/* Button_LED Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 7. The circuit: LED attached from pin 13 to ground pushbutton attached to pin 4 from ground */ int buttonPin = 4; // the number of the pushbutton pin int ledPin = 13; // the number of the LED pin int buttonState; // variable for reading the pushbutton status void setup() { pinMode(ledPin, OUTPUT); // initialize the LED pin as an output: pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input: digitalWrite (buttonPin, HIGH); // eliminates the need for a pull down resistor by giving a default state. } void loop(){ buttonState = digitalRead(buttonPin); // read the state of the pushbutton value: // check if the pushbutton is pressed. if (buttonState == HIGH) { // if it is, the buttonState is HIGH: digitalWrite(ledPin, HIGH); // turn LED on: } else { digitalWrite(ledPin, LOW); // turn LED off: } }