Coding a Simple 2-LED Flasher Using Arduino

Today, we will make a simple 2-LED flasher circuit using Arduino (UNO). It is a very simple circuit where two LEDs take turns blinking.

Usually, we would make an LED flasher circuit with a transistor circuit. However, building a simple circuit like this one with Arduino is an excellent way to learn the C programming language.

Simple 2-LED Flasher Using Arduino

Without further ado, let’s get started!

Creating Code Structure

We begin by creating a structure or order for our code using a vertical diagram. First, we assign each function to their block.

Define pictograms of LED blinking  working
Assigning a Function to a Block

If it is a bit confusing, on the left is the block icon; on the right is the function each block represents. Next, we arrange these blocks in the way we want our circuit to function.

diagram programing Arduino
Creating a Diagram that Represents the Function of Our 2-LED Flasher

The function of each block is played (executed) from top to bottom. Something like “LED1 is ON → LED2 is OFF → Delay for 1S → …,” etc.

The next step is to convert each block into code, which will be put into our Arduino controller board.

Put code in programing
Convert the Diagram into C Language Code

Read also: DIY Flashing Bicycle LED Taillight Circuit

Applying the Code and Testing Its Function

Now, we put the resulting code into the Arduino IDE software. The code is shown below.

void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}
void loop() {
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);
  delay(1000);
  digitalWrite(13, LOW);
  digitalWrite(12, HIGH);
  delay(1000);
}
Programing on Arduino-IDE
Programming Code onto Arduino IDE

And then, when we are done, press Ctrl + R to compile the code and check for potential errors.

In the meantime, let’s assemble the LED circuit onto the test breadboard. But before that, we first need to prepare the following parts.

Parts List

  • Arduino Board
  • 2x LEDs
  • 2x 470Ω Resistors
  • Jumper Wires

After gathering all the required parts, we assemble the LED as shown in the illustration below.

2 LED flasher Arduino circuit connection
Assembling the Circuit on the Breadboard

Testing the 2-LED Flasher Circuit

Finally, connect the Arduino board to the computer via the USB cable. Then, in the Arduino IDE program, go to Sketch > Upload code to the Arduino board.

After that we will see the two red and green LEDs blinking alternatively, as shown in the picture and video below.

Blink 2 LED flasher circuit using Arduino

What happens in the video:

  • First, we set time delay to 1s
  • Second, we set time delay to 0.1s (LEDs blink faster)
  • Third, we set time delay to 3s (LEDs blink slowly)

This simple 2-LED flasher circuit works very well. Plus, coding a circuit opens the door to integration with other more complicated circuits in the future.

However, if you are interested in a more analog approach, check out this 1.5V LED flasher circuit using transistor, it can outputs 1 to 5 LEDs using only a single AAA battery.

📘 Get Ebook: Simple Electronics VOL.5