/* LightSwitchPullup Turn an LED on and off. Internal pullup version. */ int pushButtonPin = 2; // connect the push button to digital pin 2 int ledPin = 13; // connect the LED to pin 13 int buttonState; // stores current button state void setup() { pinMode(pushButtonPin, INPUT); // make the pushbutton's pin an input digitalWrite(pushButtonPin, HIGH); // turn on internal pullup resistors pinMode(ledPin, OUTPUT); // make LED's pin an output } void loop() { buttonState = digitalRead(pushButtonPin); // read the input pin // set LED state accordingly // becasue we are using pullup resistors, the logic is inverted; // in other words, pressed produces LOW, un-pressed produces HIGH. if (buttonState == LOW) // if the button is pushed digitalWrite(ledPin, HIGH); // turn the LED on else // otherwise digitalWrite(ledPin, LOW); // turn the LED off }