const int LED=3; //LED pin const int BUTTON=7; //imput pin where the button is connected int val=0; //val is used to store the state of the input pin int state=0; //0=LED is off and 1=LED is on void setup() { pinMode(LED, OUTPUT); //informs arduino that the LED is an output pinMode(BUTTON, INPUT); //and button is imput // put your setup code here, to run once: } void loop() { val=digitalRead(BUTTON); //reads the input value and stores //verifies that the input has high value (button pressed) and changes the state value if (val==LOW) { state=1-state; } if(state==1){ digitalWrite(LED, HIGH); //turn on the LED }else { digitalWrite(LED,LOW); } // put your main code here, to run repeatedly: }