/* Switch and LED Sends HIGH or LOW to serial monitor, when pressing a pushbutton attached to pin 2. The circuit: * led attached to pin 3 with a 100 ohm resistor to ground * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground */ // set pin numbers: int buttonPin = 2; // the number of the pushbutton pin int ledPin = 3; // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); // initialize the led pin as an output: pinMode(ledPin, OUTPUT); // initialize the Serial communication Serial.begin(9600); } void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. if (buttonState == HIGH) { // turn on LED by turning ledPin HIGH digitalWrite(ledPin, HIGH); // send HIGH to the serial monitor Serial.println("HIGH"); } else { // turn on LED by turning ledPin LOW digitalWrite(ledPin, LOW); // send LOW to the serial monitor Serial.println("LOW"); } }