I'm trying to use a switch to to provide input to software running on the Raspberry Pi. I have software running right now that continually reads the input pin and prints the result. Problem is, even when nothing is connected to it, the voltage reading from the input pin to circuit ground reads about 0.9V. The software rapidly flickers between TRUE and FALSE.
Is this a software issue? If not, how can I avoid this?
Thanks for any advice, - Chase
1 Answer 1
The input in question is "floating" until the button is pressed, due to its inputs being of very high impedance.
You need to add a pull-down resistor to the pushbutton, 10k is commonly used, thus:
Pull-down resistor for switch
That way, the Raspberry Pi input sees a false
(0 Volts) until the button is pressed, then a true
until released.
-
-
\$\begingroup\$ @icarus74 I'm sorry, I don't get your point: 3.3V or 5V, the rationale, and the answer, remain valid. \$\endgroup\$Anindo Ghosh– Anindo Ghosh2013年01月06日 15:42:53 +00:00Commented Jan 6, 2013 at 15:42
-
\$\begingroup\$ Answer, from rationale point of view, is perfect, it is the schematic which is misleading. For someone, who is new to electronics (and RaspberryPi) might take a highly rated answer as-is, and try to implement it, potentially leading to magic smoke being let out. The pitfall is 5V, since the pins are not 5V tolerant. \$\endgroup\$bdutta74– bdutta742013年01月06日 17:21:19 +00:00Commented Jan 6, 2013 at 17:21
-
\$\begingroup\$ @icarus74 Hmm... If that deserves a downvote, I'll take care of it. \$\endgroup\$Anindo Ghosh– Anindo Ghosh2013年01月06日 17:22:36 +00:00Commented Jan 6, 2013 at 17:22
-
\$\begingroup\$ @icarus74 ... and done. \$\endgroup\$Anindo Ghosh– Anindo Ghosh2013年01月06日 17:28:08 +00:00Commented Jan 6, 2013 at 17:28