Arduino Nano - Blink multiple LED
This tutorial instructs you through programming the Arduino Nano to blink multiple LEDs simultaneously, each at its own frequency, without utilizing the delay function. While we'll use three LEDs as an example, you can effortlessly extend the setup to include more LEDs.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of LED
We have specific a tutorial about LED. The tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to Arduino Nano, Arduino Nano code... Learn more about them at the following link:
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Nano Code - Blink Multiple LEDs
To blink multiple LEDs, we cannot use the delay() function. Instead, we need to use the millis() function and manage the timestamps .
Managing timestamps while blinking multiple LEDs can be challenging for beginners. Thankfully, the ezLED library simplifies the process of blinking multiple LEDs by internally managing timestamps. This eliminates the need for users to handle timestamp management when utilizing this library. Additionally, you can enhance code clarity and brevity by employing an array of LEDs.
Detailed Instructions
- Wire the components according to the provided diagram.
- Connect the Arduino Nano board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano) board and its corresponding COM port.
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search “ezLED”, then find the led library by ArduinoGetStarted
- Click Install button to install ezLED library.
- Copy the above code and paste it to Arduino IDE.
- Compile and upload code to Arduino Nano board by clicking Upload button on Arduino IDE
- Check out the status of LED
Arduino Nano Code - Blink Multiple LEDs by using array
We can optimize the above code by using an array of LEDs. The below code uses the array to manage LED objects.
For the flexible blink, please refer to other functions of the ezLED library