ESP32 - Blink multiple LED
This tutorial instructs you how to how to program ESP32 to blink multiple LED at the same time without using delay function.
Hardware Used In This Tutorial
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Introduction to 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, ESP32 code... Learn more about them at the following link:
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: How to Power ESP32.
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.
Quick Instructions
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE.
- Do the wiring as above image.
- Connect the ESP32 board to your PC via a micro USB cable
- Open Arduino IDE on your PC.
- Select the right ESP32 board (e.g. ESP32 Dev Module) and 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 ESP32 board by clicking Upload button on Arduino IDE
- Check out the status of LED
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
Video Tutorial
Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.