/* Button Turns ON and OFF a LED connected to digital pin 8, when pressing a pushbutton attached to pin 7. The circuit: LED attached from pin 8 to ground, pushbutton attached to pin 7 from +5V, 10K resistor attached to pin 4 from ground created 2005 by DojoDave modified 30 Aug 2011 by Tom Igoe modified 20 March 2018 by Kati Pitkänen This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Button */ // Setting pin numbers: const int pinButton = 7; // The number of the pushbutton pin const int pinLED = 8; // The number of the LED pin // Variables will change: const int stateButton = 0; // Variable for reading the pushbutton status void setup() { pinMode(pinButton, INPUT); // Set the pushbutton pin as an INPUT pinMode(pinLED, OUTPUT); // Set the LED pin as an OUTPUT } void loop() { int stateButton = digitalRead(pinButton); // Read the state of the button // check if the button is pressed // if it is, the buttonState is 0: [because the button has a PULL-UP resistor] if (stateButton == LOW) { // turn LED on: digitalWrite(pinLED, HIGH); // Write 1 or HIGH to LED pin } else { // turn LED off: digitalWrite(pinLED, LOW); // Write 0 or low to LED pin } }