Hi everybody,
I'm trying to make very simple exercise with my Arduino UNO. Basically, I'm trying to read the pulsation on button but I've run into an error I do not understand.
I'm trying to explain...
My Design is like this:
3.5 v output ------ cable ------
button ------ cable --------
PIN 7And my code is like this:
void setup()
{
pinMode(7, INPUT);
}
void loop()
{
delay(100);
int x = digitalRead(7);
Serial.print(x);
}
If I don't push the button, I will receive "0", however, if I push the button I will receive "1".... yes?
But... without touching anything... the "Monitor serial" always shows me alternatively 0 and 1... 6 or 7 times each... like this example:
x: 1
x: 1
x: 0
x: 0
x: 0
x: 0
x: 0
x: 0
x: 1
x: 1
x: 1
x: 1
x: 1
x: 1
x: 1
x: 0
x: 0
x: 0
x: 0
x: 0
x: 0
x: 0
x: 1
x: 1
...
If I touch the button, the "x" value, evidenty, force change to "1"... but the other times... What happens???
I do not understand why this problem happens.
Thanks in advance for your comments.
Moderator edit: topic subject corrected