Creating three LEDs blink program using push button
Required Components
- Led -3 no
- Resistor(220 ohm) -3 no
- Resistor(10K) -1 no
- Pushbutton -1 no
- Bread Board -1 no
- Arduino UNO -1 no
- Connecting Wires -1 set
Circuit
Steps
- Make sure the components are working properly.
- Connect Arduino board 5V and GND pin to the bread board by using wires.
- Connect 220 Ω Resistors to each LED Anode (+) pin and all cathode (-) pin to Gnd.
- Connect Arduino pin 9, 10, 11 to the 220 Ω Resistors another pin.
- Connect 10 k Ω Resistor to the switch.
- Connect switch button another pin to the Arduino pin 8.
- When we press the push button 1st time LED1 blinks.
- When we press the push button 2nd time LED1 off and LED2 blinks.
- When we press the push button 3rd time LED2 off and LED3 blinks.
- Repeated last 3steps as per the program.
- Check the Arduino program.
- Check the circuit connections.
- Run the Arduino program.
Arduino Program
int led1=9;
int led2=10;
int led3=11;
int btn=0;
const int buttonpin=8;
void setup ( )
{
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
pinMode (led3, OUTPUT);
pinMode (buttonpin, INPUT);
Serial.begin(9600);
}
void loop ( )
{
if (digitalRead(buttonpin)== HIGH)
{
btn ++;
Serial.println(btn);
Lighton(btn);
delay (500);
}
if (btn >=3)
{
btn=0;
}
}
void Lighton(int n)
{
digitalWrite (led1, LOW);
digitalWrite (led2, LOW);
digitalWrite (led3, LOW);
if (n==1){
digitalWrite (led1, HIGH);
}
else if (n==2)
{
digitalWrite (led2, HIGH);
}
else if (n==3)
{
digitalWrite (led3, HIGH);
}
}
Usage
- Advertising application.
- Decoration purposes.