Using a Pushbutton to Control the LED

I just got the board and I'm setting up this example on a breadboard. However, if I just stick a wire in the pin 7 and place my hand in close proximity to the wire, the LED lights! No other board connections. I'm trying to figure out what's going on:

#define LED 13
#define BUTTON 7
int val = 0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop()
{
val = digitalRead(BUTTON);
if(val == HIGH)
digitalWrite(LED, HIGH);
else
digitalWrite(LED, LOW);
}

Wow. You’ve blown through all the example tutorial projects and created your own proximity sensor.

Why go back to push buttons? :slight_smile:

Thanks - works perfectly once hooked up!

The Button tutorial explains that floating input pins will lead to exactly the behavior you're describing.