
I have a simple Arduino Project, 2 buttons and face a strange case that in the beginning status of buttons are 0, but after click on the button and release the status becomes 1 for long a time then back to 0, please what is the wrong??
Code:
int const BTN1_PIN=2;
int const BTN2_PIN=4;
void setup(){
pinMode(BTN1_PIN, INPUT);
pinMode(BTN2_PIN, INPUT);
Serial.begin(9600);
}
void loop(){
int status1=digitalRead(BTN1_PIN);
Serial.print("BTN1 Status :");
Serial.println(status1);
int status2=digitalRead(BTN2_PIN);
Serial.print("BTN2 Status :");
Serial.println(status2);
delay(250);
}
in the begining, the values is :
BTN1 Status :0
BTN2 Status :0
.
.
But after click on the button1 and release the status of button1 take long time to back to 0, the output like:
BTN1 Status :1
BTN2 Status :0
BTN1 Status :1
BTN2 Status :0
BTN1 Status :1
BTN2 Status :0
BTN1 Status :1
BTN2 Status :0
BTN1 Status :1
BTN2 Status :0
BTN1 Status :1
BTN2 Status :0
BTN1 Status :1
BTN2 Status :0
BTN1 Status :1
BTN2 Status :0
BTN1 Status :0
BTN2 Status :0
BTN1 Status :0
BTN2 Status :0
BTN1 Status :0
BTN2 Status :0
BTN1 Status :0
BTN2 Status :0
BTN1 Status :0
BTN2 Status :0

readDigit()look like ? Is that simpledigitalRead()? Your ground doesn't seem to be connected to anything. Also, have you tried using INPUT_PULLUP (e.g.pinMode(BTN1_PIN, INPUT_PULLUP);) ?