// found here: https://arduino.stackexchange.com/questions/3479/how-to-toggle-led-on-button-press int ledPin = 7; int buttonPin = 3; int lastButtonState = HIGH; void setup() { pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); } void loop() { // Get the current state of the button int currentButtonState = digitalRead(buttonPin); // Has the button gone high since we last read it? if (currentButtonState == HIGH && lastButtonState == LOW) { // Switch the state of the output //digitalWrite(ledPin, !digitalRead(ledPin)); if(digitalRead(ledPin)) digitalWrite(ledPin, 0); else digitalWrite(ledPin, 1); } // Store the button's state so we can tell if it's changed next time round lastButtonState = currentButtonState; }