Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
thanks for the reply John, but surely if the pin is grounded it will read 0v, and if the circuit is open it will also read 0v?
Ben
Goeytex Regular Member Joined: 12/05/2014 Location: United StatesPosts: 74
Posted: 02:34am 18 Jun 2014
Copy link to clipboard
Print this post
Not necessarily. Ground may be defined a physical point used as reference for voltage levels.
A pin being grounded means it is physically connected to the ground reference point and not necessarily that it is taken "low" by an external device. So if a pin is grounded and the meter is referenced to ground, it will read 0 volts.
An open circuit, meaning absolutely nothing is connected to the Pin, will not necessarily read OV.
If the pin is an input and pull ups are NOT enabled, it will be floating and in an indeterminate high impedance state. There may or may not be voltage present. But the impedance of the meter might be enough to drive the pin down to near 0 volts when taking a reading. A high impedance meter or scope may read a voltage anywhere from 0V to near Vdd.
If the pin is an input and pullups ARE enabled, then with nothing connected to the pin, it will read the supply voltage minus a few hundred millivolts.
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3998
Posted: 02:53am 18 Jun 2014
Copy link to clipboard
Print this post
Don't have floating (*) pins! They sometimes read as 0 and sometimes as 1, and may flip between those or latch up in some nasty way.
(*) implies input pins
JohnEdited by JohnS 2014-06-19
robert.rozee Guru Joined: 31/12/2012 Location: New ZealandPosts: 2400
Posted: 05:41am 18 Jun 2014
Copy link to clipboard
Print this post
the simple answer to your question:
yes. connect a 10k resistor from your pin to 3v3. this will ensure that reading the pin normally returns a '1'. if you now connect the pin to ground (0v) the pin will return '0'.
for example, the below code assumes you are using pin 2. 10k resistor from pin 2 to 3v3, and a switch from pin 2 to ground.