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?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.Sign up to join this community
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.