//This program is very simple ...... if you are having trouble to understand ......just dry run the loop() for four different states of the "currentButtonState" and "lastButtonState" #define switchPin 8 // Just the switch definations #define ledPin 13 boolean lastButtonState = LOW; boolean currentButtonState = LOW; // Used in the debounce function boolean ledOn = false; void setup() { pinMode(switchPin,OUTPUT); pinMode(ledPin,OUTPUT); } boolean debounce(boolean last) // This function works the magic... { boolean current = digitalRead(switchPin); if (last != current) { current = digitalRead(switchPin); } return current; } void loop() // Just dry run this function with four combination values of currentButtonState and lastButtonState { currentButtonState = debounce(lastButtonState); if(currentButtonState == HIGH && lastButtonState == LOW) // this means someone has just pressed the switch { ledOn = !ledOn; } lastButtonState = currentButtonState; digitalWrite(ledPin, ledOn); }