//This program is very simple ...... if you are having trouble to understand ......just dry run the loop() for two different states of the switchPin #define switchPin 8 #define led 13 boolean ledOn = false; // current state of the LED (intially its false coz at first the LED stays off) void setup() { pinMode(switchPin,OUTPUT); pinMode(led,OUTPUT); } void loop() { if(digitalRead(switchPin) == HIGH)//This signifies that the switch is pressed { ledOn = !ledOn; //Inverts the state of ledOn } digitalWrite(led,ledOn); // Switch the LED High or Low depending n the state of the variable ledOn }