Feb 132011

This activity is a variation of the single led blink activity. It allows you flash 2 LEDs alternately, like you might see on an emergency vehicle.

You will need:

  • Arduino
  • 2 LEDs
  • 470 ohm resistor
  • jumper wires

Place 3 jumper wires in pin 12, pin13 and Gnd on the digital side of the arduino, shown below.

Set up your breadboard so that the cathode sides of the LEDs are connected to a resistor, and then to a common ground. Doing it this way means we only need a single resistor and ground pin. The other legs (anode) of the LEDs should be in pin 13 for the first LED, and pin 12 for the second LED.

Next connect your arduino to your  computer with a USB cable and open the Arduino IDE. Type in the following code:

void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);

void loop(){
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);

The code above is similar to the single LED blinker except that

  • in the setup section pin 12 is added as a second output
  • in the loop section lines are added so that when pin 12 is on (high),  pin 13 is low (off) and vice-versa.


How could you change the code so that both LEDs blink at that same time?

Try it for yourself!

 Posted by at 3:30 am

  2 Responses to “Arduino: Blink 2 LEDs (emergency flasher style!)”

  1. With this code you make all the lights blink at the same time.

    void setup()
    pinMode(1, OUTPUT);
    pinMode(2, OUTPUT);
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);
    pinMode(10, OUTPUT);
    pinMode(11, OUTPUT);
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(0, OUTPUT);
    void loop()
    digitalWrite(0, HIGH);
    digitalWrite(1, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    digitalWrite(11, HIGH);
    digitalWrite(12, HIGH);
    digitalWrite(13, HIGH);
    digitalWrite(0, LOW);
    digitalWrite(1, LOW);
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
    digitalWrite(6, LOW);
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);
    digitalWrite(9, LOW);
    digitalWrite(10, LOW);
    digitalWrite(11, LOW);
    digitalWrite(12, LOW);
    digitalWrite(13, LOW);

  2. Thank you for the simplest explanation to date of a simple flip flop. I have only just started on arduino circuits and this is exactly what I needed, not only to explain in simple terms the use of the pins but also the source code.
    I see that the rate is set at half a second which is nice and easy to change.
    Thanks again.

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>