Arduino - Blink Multiple LED
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://arduinogetstarted.com/tutorials/arduino-blink-multiple-led
This build blinks three LEDs at the same time on an Arduino, each one on and off at its own rate, without using delay(). The same wiring and code pattern extends to two, four, or more LEDs. It uses the ezLED library so the sketch does not have to manage timestamps manually.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- Official Arduino Uno
- DIYables STEM V3, Fully Compatible with Arduino Uno R3
- USB 2.0 cable type A/B (for USB-A PC)
- USB 2.0 cable type C/B (for USB-C PC)
- LED Kit
- LED (red)
- LED Module
- Button and LED Kit
- 220Ω Resistor
- Breadboard
- Jumper Wires
- Screw Terminal Block Shield for Arduino Uno
- Sensors/Servo Expansion Shield for Arduino Uno
- Breadboard Shield for Arduino Uno
- Enclosure for Arduino Uno
- Prototyping Base Plate & Breadboard Kit for Arduino UNO
- DIYables STEM V3 Starter Kit (Arduino included)
- DIYables Sensor Kit (18 sensors/displays)
Wiring
Connect three LEDs to Arduino pins 7, 8, and 9. Using the LED Module (which has a built-in resistor) simplifies the wiring since you just connect it to the pin, 5V, and GND. If you use plain LEDs on a breadboard instead, wire each one in series with a 220Ω resistor to ground.
How It Works
Blinking several LEDs at once rules out delay(), since delay() blocks the rest of the code and would stop the other LEDs from blinking independently. The sketch instead relies on millis() to track timing for each LED separately. The ezLED library wraps this timestamp handling internally, so each LED object just needs to be told its on-time and off-time and then serviced in the loop.
Code
The sketch includes the ezLED library and creates one ezLED object per LED pin (7, 8, 9). In setup(), each object's blink() call sets its own on-time and off-time in milliseconds, for example 500/500, 200/800, and 800/200, so each LED blinks at a different rate starting immediately. In loop(), each object's loop() function must be called every pass so the library can update that LED's state; other code can run in loop() alongside it without blocking the blinking. A second version of the sketch puts the LED objects in an array to make the code shorter and easier to extend to more LEDs.
arduino-blink-multiple-led.ino - the sketch from the tutorial, unchanged.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://arduinogetstarted.com/tutorials/arduino-blink-multiple-led