user42925: I'm working with a very simple circuit to understand push buttons. The code in the tutorial uses the INPUT_PULLUP pinmode. I understand the idea of the pinmode, but I have two questions:
There must be a difference between a LOW reading and no connection, correct? How does the arduino differentiate between the two?
I tried to experiment with this idea. So my thought was that you could create a circuit where the LED only stays lit when you hold the button down. In this setup, I used just normal INPUT for pinmode. So the logic was: if LOW then turn light on, else light off. The turnout was the light was almost always on and just really finicky when i moved the board. Why? 
Thanks!

user10794: 
There must be a difference between a LOW reading and no connection, correct? 

No, the input circuitry measures a voltage. The exact details are in the datasheet, but how could it know there is nothing connected? There is not some sort of sensor that detects the insertion of a wire into the input. Therefore it is trying to read a voltage all the time.
With nothing connected then stray voltages from nearby circuitry will influence the reading.


... and just really finicky when i moved the board ...

Yep, you are influencing the voltage by capacitance from your hand.
You need to have a definite voltage for "no switch pressed" which can be a resistor to ground (eg. 10k) or a resistor to +5V.
I have a tutorial on this.

It sounds like you have wired your switch like this:

Because you don't have a definite voltage there, the input could "randomly" switch between LOW and HIGH.

You could add a pull-down resistor:


Or a pull-up resistor:


Or use the INPUT_PULLUP mode to create a pull-up resistor in the processor hardware. (There is no INPUT_PULLDOWN mode).
Then you will get consistent results.

42925: <p>I'm working with a very simple circuit to understand push buttons. The code in the tutorial uses the INPUT_PULLUP pinmode. I understand the idea of the pinmode, but I have two questions:</p>

<p>There must be a difference between a LOW reading and no connection, correct? How does the arduino differentiate between the two?</p>

<p>I tried to experiment with this idea. So my thought was that you could create a circuit where the LED only stays lit when you hold the button down. In this setup, I used just normal INPUT for pinmode. So the logic was: if LOW then turn light on, else light off. The turnout was the light was almost always on and just really finicky when i moved the board. Why? </p>

<p>Thanks!</p>
 10794: <blockquote>
  <p>There must be a difference between a LOW reading and no connection, correct? </p>
</blockquote>

<p>No, the input circuitry measures a voltage. The exact details are in the datasheet, but how could it know there is nothing connected? There is not some sort of sensor that detects the insertion of a wire into the input. Therefore it is trying to read a voltage all the time.</p>

<p>With nothing connected then stray voltages from nearby circuitry will influence the reading.</p>

<hr>

<blockquote>
  <p>... and just really finicky when i moved the board ...</p>
</blockquote>

<p>Yep, you are influencing the voltage by capacitance from your hand.</p>

<p>You need to have a definite voltage for "no switch pressed" which can be a resistor to ground (eg. 10k) or a resistor to +5V.</p>

<p>I have a <a href="http://www.gammon.com.au/switches" rel="noreferrer">tutorial on this</a>.</p>

<hr>

<p>It sounds like you have wired your switch like this:</p>

<p><a href="https://i.stack.imgur.com/7Mxzd.png" rel="noreferrer"><img src="https://i.stack.imgur.com/7Mxzd.png" alt="Floating input"></a></p>

<p>Because you don't have a definite voltage there, the input could "randomly" switch between LOW and HIGH.</p>

<hr>

<p>You could add a pull-down resistor:</p>

<p><a href="https://i.stack.imgur.com/iv3SB.png" rel="noreferrer"><img src="https://i.stack.imgur.com/iv3SB.png" alt="Pull-down resistor"></a></p>

<hr>

<p>Or a pull-up resistor:</p>

<p><a href="https://i.stack.imgur.com/8k6s8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8k6s8.png" alt="Pull-up resistor"></a></p>

<hr>

<p>Or use the INPUT_PULLUP mode to create a pull-up resistor in the processor hardware. (There is no INPUT_PULLDOWN mode).</p>

<p>Then you will get consistent results.</p>
