user13886: Using the Arduino tutorial "Button", I have noticed that if I totally disconnect Pin2 from the circuit, the LED comes on dimly.
I am trying to understand HOW this happens.  Is it simply due to being a floating ground?


user10214: The pinMode(buttonPin, INPUT); line tells the board to set the buttonPin in high impedance mode.
When you disconnect the wire the state of that pin becomes unknown; usually it oscillates.
Since it is oscillating, the LED turns on and off randomly: you see it "dimly light".
The usual solution is to use a pull-up or pull-down. I suggest you to wire your buttons towards the ground, declare the pins as pinMode(buttonPin, INPUT_PULLUP); and invert the logic (i.e. buttonState = !digitalRead(buttonPin);). This way it will never oscillate again.

13886: <p>Using the Arduino tutorial "<a href="https://www.arduino.cc/en/Tutorial/Button" rel="nofollow noreferrer">Button</a>", I have noticed that if I totally disconnect Pin2 from the circuit, the LED comes on dimly.</p>

<p>I am trying to understand HOW this happens.  Is it simply due to being a floating ground?</p>

<p><a href="https://i.stack.imgur.com/St0Tc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/St0Tc.png" alt="enter image description here"></a></p>
 10214: <p>The <code>pinMode(buttonPin, INPUT);</code> line tells the board to set the <code>buttonPin</code> in high impedance mode.</p>

<p>When you disconnect the wire the state of that pin becomes unknown; usually it oscillates.
Since it is oscillating, the LED turns on and off randomly: you see it "dimly light".</p>

<p>The usual solution is to use a pull-up or pull-down. I suggest you to wire your buttons towards the ground, declare the pins as <code>pinMode(buttonPin, INPUT_PULLUP);</code> and invert the logic (i.e. <code>buttonState = !digitalRead(buttonPin);</code>). This way it will never oscillate again.</p>
