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.
Thanks for your answers, but I think I'm not explaining very well..
Imagine my board without anything... in this case, digitalRead() always return me "0", but when I connect one piece of cable (only the cable) to PIN 7 (remember, is INPUT) my Arduino returns me alternatively "0" and "1" (even without closing the circuit)
In this way...
if PIN 7 still do not receive voltage.. Why do I need the "resistance"?
if PIN 7 will be returns 1 or 0 (representing HIGH or LOW), Why do I need float variable?
Why do you think that having nothing connected to a pin should give a consistent result?
The resistor gives a consistent high or low, depending on which rail it is connected to.
Thanks for your answers, but I think I'm not explaining very well..
Yes you are perfectly clear, as are the answers you got.
The connection of a cable makes it more likely to pick up noise. If you have a UNO then that works off 5V and so trying to switch with 3V5 is marginal at best.
Don't wire it up like that.
LarryD:
Add a resistor (about 10K) from pin 7 to Arduino +5 volts.
edit: as AWOL said
Since the button is connected to +3.5V that won't work - use a pull-down to ground. 3.5V will consistently
read as HIGH when the button is pressed. You need the resistor to pull the pin back down to 0V when the
button is released.
Unconnected inputs on CMOS chips are like radio antennas, they pick up any nearby signal very easily
since they are almost perfect voltage sensors with infinite resistance (well thousands of megohms or more).