If you've ever written async code to avoid blocking a UI thread, you'll feel right at home here: this tutorial blinks three LEDs on an ESP32 C3 Super Mini at three different speeds at once, without ever calling delay(). Instead it leans on millis() timestamps wrapped up in a small library, so your main loop stays free to do other work.
The full tutorial, with every detail and the line-by-line code explanation, is on our site: ESP32 C3 Super Mini - Blink multiple LED
What you need
- ESP32 C3 Super Mini
- USB Cable Type-A to Type-C (for USB-A PC)
- USB Cable Type-C to Type-C (for USB-C PC)
- LED Kit
- LED (red)
- LED Module
- Button and LED Kit
- 220Ω Resistor
- Breadboard
- Jumper Wires
- DC Power Jack
- DIYables Sensor Kit (18 sensors/displays)
Wiring
Each LED needs its own GPIO pin plus a 220 ohm resistor in series, connected to the anode (the long leg). The cathode (short leg) goes to GND. This build uses three LEDs on GPIO7, GPIO6 and GPIO5, so you need three LEDs and three resistors total. Never skip the resistor: without it, the LED draws too much current and can damage itself or the pin. If you'd rather skip discrete resistors, an LED module with one built in makes wiring simpler.
How it works
An LED only lights up when current flows through it in the correct direction, and each one is controlled independently by whichever GPIO pin it's wired to. Every pin on the ESP32 C3 Super Mini runs at 3.3V logic. Because each LED has its own pin, each can blink on its own schedule, one fast, one slow, without affecting the others, as long as your code checks timing for each one separately instead of pausing the whole program with delay().
Code
Blinking several LEDs at independent rates with raw millis() means tracking a separate timestamp and state for each one, which gets messy fast. The ezLED library handles that bookkeeping for you: you call blink() once per LED with an ON time and OFF time, then call .loop() on each LED object every pass through loop(). In the example, LED 1 on GPIO7 blinks 500ms on/500ms off, LED 2 on GPIO6 does 200ms on/800ms off, and LED 3 on GPIO5 does 200ms on/200ms off, all running simultaneously. A follow-up version of the sketch stores the LED objects in an array and loops over them, so adding a fourth or fifth LED is just one more array entry instead of more copy-pasted lines.
esp32-c3-super-mini-blink-multiple-led.ino
/*
* This ESP32 C3 Super Mini code was developed by newbiely.com
*
* This ESP32 C3 Super Mini code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-blink-multiple-led
*/
#include <ezLED.h> // ezLED library
#define PIN_LED_1 7 // The ESP32 C3 SuperMini pin connected to LED 1
#define PIN_LED_2 6 // The ESP32 C3 SuperMini pin connected to LED 2
#define PIN_LED_3 5 // The ESP32 C3 SuperMini pin connected to LED 3
ezLED led1(PIN_LED_1); // create ezLED object that attach to pin PIN_LED_1
ezLED led2(PIN_LED_2); // create ezLED object that attach to pin PIN_LED_2
ezLED led3(PIN_LED_3); // create ezLED object that attach to pin PIN_LED_3
void setup() {
Serial.begin(115200);
led1.blink(500, 500); // 500ms ON, 500ms OFF, blink immediately
led2.blink(200, 800); // 200ms ON, 800ms OFF, blink immediately
led3.blink(200, 200); // 200ms ON, 200ms OFF, blink immediately
}
void loop() {
led1.loop(); // MUST call the led1.loop() function in loop()
led2.loop(); // MUST call the led2.loop() function in loop()
led3.loop(); // MUST call the led3.loop() function in loop()
// DO SOMETHING HERE
}
Things that go wrong
If an LED stays dark, check that it's wired the right way round, the long leg (anode) through the resistor to the GPIO pin, the short leg (cathode) to GND. If it's wired backwards it simply won't light. Also make sure you actually call .loop() for every LED object inside loop(); forgetting it means that LED's blink logic never advances and it just stays stuck in whatever state it was in.
Full tutorial
The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-blink-multiple-led

Top comments (0)