/* LightSwitchMonitored Turn an LED on and off and send switch state to serial monitor */ int pushButtonPin = 2; // connect the push button to digital pin 2 int ledPin = 13; // connect the LED to pin 13 void setup() { Serial.begin(9600); // initialize serial communication at 9600 bits/second pinMode(pushButtonPin, INPUT); // make the pushbutton's pin an input digitalWrite(pushButtonPin, HIGH); // turn on pullup resistors pinMode(ledPin, OUTPUT); // make LED's pin an output } void loop() { int buttonState = digitalRead(pushButtonPin); // read the input pin // set LED state accordingly if (buttonState == LOW) // if the button is pushed digitalWrite(ledPin, HIGH); // turn the LED on else // otherwise digitalWrite(ledPin, LOW); // turn the LED off Serial.println(buttonState); // print out state of button delay(500); // delay between reads }