when I connect the wires I should see 1 on the serial monitor and when I disconnect them 0 .
but it’s always 1 !
when I connect the wires i it goes to 0 and 1 for a couple of times and then it becomes 1. when I disconnect it it stays at 1 for a a few seconds and it goes to 0 sometimes and sometimes doesn't.
this the simple program that I wrote to light a led when the switch is pushed is like this:
//
void loop()
{
int val = digitalRead(enc);
if (val ==HIGH)
{
digitalWrite(led,HIGH);
Serial.println(val);
}
else{
digitalWrite(led,LOW);
}
}
I thought maybe it’s because of bouncing. because it was like this since the first day that I got the Arduino.
but today I had problem in counting pulses from encode and I was told it's because of my pins has problem.
there any other way to check the pins ? it’s UNO btw.
int button = 12;
void setup()
{
pinMode(button,INPUT);
Serial.begin(9600);
}
void loop()
{
int val = digitalRead(button);
Serial.println(val);
}
when I upload the program, I get the bunch of zeros which is normal
when i connect the wire I get 1, which is normal.
but when disconnect the wire, I get 1 for almost 5 seconds and then the value starts to bounce between 0 and 1 for 3 4 more seconds and then it goes to zero.
one other thing which seems weird is when I place a wire which is connected to nowhere to the pin 12. I get the uploaded picture number 1 !!! and when I take it out, for couple of seconds I get picture number 2. and then it goes to all zero.
it’s so weird. the wire is connected to nowhere !!!