Arduino Tutorials – Lesson 7 – Three LEDs Connect With A Single Switch Blink Using Arduino UNO

Creating three LEDs blink program using push button

Required Components

  1. Led -3 no
  2. Resistor(220 ohm) -3 no
  3. Resistor(10K) -1 no
  4. Pushbutton -1 no
  5. Bread Board -1 no
  6. Arduino UNO -1 no
  7. Connecting Wires -1 set

Circuit

Steps

  1. Make sure the components are working properly.
  2. Connect Arduino board 5V and GND pin to the bread board by using wires.
  3. Connect 220 Ω Resistors to each LED Anode (+) pin and all cathode (-) pin to Gnd.
  4. Connect Arduino pin 9, 10, 11 to the 220 Ω Resistors another pin.
  5. Connect 10 k Ω Resistor to the switch.
  6. Connect switch button another pin to the Arduino pin 8.
  7. When we press the push button 1st time LED1 blinks.
  8. When we press the push button 2nd time LED1 off and LED2 blinks.
  9. When we press the push button 3rd time LED2 off and LED3 blinks.
  10. Repeated last 3steps as per the program.
  11. Check the Arduino program.
  12. Check the circuit connections.
  13. 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

  1. Advertising application.
  2. Decoration purposes.

Leave a Reply

Your email address will not be published. Required fields are marked *