How to control a series of LED using PUSH BUTTON - Arduino Tutorial

How to control a series of LED using PUSH BUTTON – Arduino Tutorial

How to control a series of LED using PUSH BUTTON – Arduino Tutorial

This tutorial I am going to share with you the method and codes for controlling LED using a PUSH BUTTON via arduino. Please feel free to download and have look into my circuit at Tinkercad. You can SIMULATE its function and download the code.

Click HERE to the File/ Play with the simulation below:

The code available at the bottom of this layout.

Arduino Schematic Diagram:

How to control a series of LED using PUSH BUTTON – Arduino Tutorial

Arduino Code Here:

//Start

#define button 3
#define redLED 5
#define blueLED 6
#define yellowLED 7

int state = 0;
int old =0;
int buttonPoll=0;

void setup(){
pinMode (button,INPUT);
pinMode(redLED,OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(yellowLED,OUTPUT);

digitalWrite(redLED, LOW);
digitalWrite(blueLED,LOW);
digitalWrite(yellowLED,LOW);
}

void loop(){
buttonPoll = digitalRead(button);
if(buttonPoll==1){
delay(50);
buttonPoll =digitalRead(button);
if(buttonPoll==0){
state=old+1;
}}
else{
delay(100);
}
switch (state){
case 1:
digitalWrite(redLED,HIGH);
digitalWrite(blueLED,LOW);
digitalWrite(yellowLED,LOW);
old=state;
break;
case 2:
digitalWrite(redLED,LOW);
digitalWrite(blueLED,HIGH);
digitalWrite(yellowLED,LOW);
old=state;
break;
case 3:
digitalWrite(redLED,LOW);
digitalWrite(blueLED,LOW);
digitalWrite(yellowLED,HIGH);
old=state;
break;
default:
digitalWrite(redLED,LOW);
digitalWrite(blueLED,LOW);
digitalWrite(yellowLED,LOW);
old=0;
break;
}
}

//End

====