Hi everyone,
Thank you for taking the time to read my post. I'm an Arduino and general electronics newbie. I've been doing software development for a few years and wanted to take a stab at getting closer to the metal. Bought an Arduino and the Getting Started with Arduino book a few days ago and have been enjoying it and learning a lot.
The programming side has proven very easy considering my experience but there is a lot I don't know about the hardware which is the point of my post. I was just curious if this behavior is natural:
I have a sketch that reads the state of a push button on pin 7 and then turns an LED in pin 13 on or off depending on the state of the button (Exercise 4 in the Arduino book). The sketch and hardware works as expected however, if I disconnect the entire button circuit and leave a jumper cable plugged into pin 7 with the other end just hanging loose in the air (not connected to ground or anything else) the LED stays on as if it was reading a signal on pin 7. When I remove the jumper cable, the LED remains on for about a second and then turns off instead of turning off immediately.
Why is that? Is just having anything plugged into a digital input pin enough to send a signal even if it does not form a complete circuit and is not connected to a voltage source? Doesn't make a lot of sense to me. Below is the sketch im using. It is extremely simple but maybe I'm not seeing something that a fresh pair of eyes can make out.
Any explanation for this behavior would be appreciated.
Thanks!
#define LED 13
#define BUTTON 7
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop()
{
int buttonState = digitalRead(BUTTON);
digitalWrite(LED, buttonState);
}