Arduino Nano ESP32 - Blink multiple LED
This tutorial instructs you through programming the Arduino Nano ESP32 to blink multiple LEDs simultaneously without relying on the delay function. Each LED can blink at a different frequency from the others. We'll use three LEDs as an example, but you can easily adapt the code to blink 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 ESP32, Arduino Nano ESP32 code... Learn more about them at the following link:
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Nano ESP32 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
To get started with Arduino Nano ESP32, follow these steps:
- If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano ESP32 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 ESP32 board by clicking Upload button on Arduino IDE
- Check out the status of LED
Arduino Nano ESP32 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