ESP32 C3 Super Mini - LED - Blink Without Delay

The simplest way to blink an LED is the delay() function, but it stops the ESP32 C3 Super Mini from doing anything else. That is fine for a single LED, but not when you want to blink more LEDs or do other work at the same time. This tutorial shows how to blink an LED without delay on the ESP32 C3 Super Mini while it also checks a button.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - LED - Blink Without Delay

We will run through these examples and compare them:

This method lets the ESP32 C3 Super Mini do several tasks at the same time. Blinking an LED is just an example.

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×LED Kit
1×LED (red)
1×LED Module
1×Alternatively, Button and LED Kit
1×220Ω Resistor
1×Breadboard-mount Button with Cap
1×Breadboard-mount Button Kit
1×Panel-mount Push Button
1×Push Button Module
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.

Overview of LED and Button

We have separate tutorials with the pinout, how each part works, wiring and code.

Wiring Diagram

Connect the LED and the button to your ESP32 C3 Super Mini as shown below.

  • Note: Always use the 220 ohm resistor with the LED to protect it from damage.
  • Note: The button needs no external resistor, because the code turns on the internal pull-up resistor on GPIO5.
The wiring diagram between ESP32 C3 Super Mini LED button

This image is created using Fritzing. Click to enlarge image

If you do not use a breadboard, wire it like this:

The wiring diagram between ESP32 C3 Super Mini LED button  (No Breadboard)

This image is created using Fritzing. Click to enlarge image

Component Pin ESP32 C3 Super Mini Pin
LED anode (long leg), through the 220 ohm resistor GPIO7
LED cathode (short leg) GND
Button pin 1 GPIO5
Button pin 2 GND

Let's compare the ESP32 C3 Super Mini code that blinks an LED with and without the delay() function

ESP32 C3 Super Mini Code - With Delay

This first code blinks the LED with delay(), so you can see the problem for yourself.

What This Code Does:

  • Blinks the LED: Toggles the LED on GPIO7 every 1000 milliseconds
  • Waits: Stops on delay() for the whole second
  • Reads the Button: Checks GPIO5 only once per second, after each delay
  • Prints Changes: Sends the button state to the Serial Monitor when it changes
/* * 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-led-blink-without-delay */ #define LED_PIN 7 // The ESP32 C3 SuperMini pin GPIO7 connected to LED #define BUTTON_PIN 5 // The ESP32 C3 SuperMini pin GPIO5 connected to button #define BLINK_INTERVAL 1000 // interval at which to blink LED (milliseconds) int led_state = LOW; // led_state used to set the LED int prev_button_state = LOW; // will store last time button was updated void setup() { Serial.begin(115200); // set the digital pin as output: pinMode(LED_PIN, OUTPUT); // set the digital pin as an input: pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { // if the LED is off turn it on and vice-versa: led_state = (led_state == LOW) ? HIGH : LOW; // set the LED with the led_state of the variable: digitalWrite(LED_PIN, led_state); delay(BLINK_INTERVAL); // If button is pressed during this time, ESP32 C3 SuperMini CANNOT detect int button_state = digitalRead(BUTTON_PIN); if (button_state != prev_button_state) { // print out the state of the button: Serial.println(button_state); // save the last state of button prev_button_state = button_state; } // DO OTHER WORKS HERE }

Detailed Instructions

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Wire the Circuit: Connect the components as shown in the diagram above.
  • Connect the Board: Plug the ESP32 C3 Super Mini into your computer with a USB Type-C cable.
  • Open Arduino IDE: Launch the Arduino IDE on your computer.
  • Select Board: Make sure ESP32 C3 Super Mini is selected in Tools > Board, then choose its COM port.
  • Copy Code: Copy the code above and paste it into the Arduino IDE.
  • Upload Code: Click the Upload button to compile and upload the code.
How to upload ESP32 C3 Super Mini code on Arduino IDE
  • Open Serial Monitor: Open the Serial Monitor and set the baud rate to 115200.
How to open serial monitor on Arduino IDE
  • Press the Button: Press the button quickly 4 times.
  • Watch the LED: The LED toggles between ON and OFF every second.
  • Check the Output: See the result in the Serial Monitor.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
1 0
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • What It Means: 1 means released and 0 means pressed. You will not see 0 four times, because the ESP32 C3 Super Mini CANNOT detect a press during the delay time.
  • Pro Tip: Try longer delays. The longer the delay, the more button presses are missed.

ESP32 C3 Super Mini Code - Without Delay

This code blinks the LED at the same speed, but it never stops to wait.

What This Code Does:

  • Checks the Time: Reads millis() on every loop instead of waiting
  • Blinks on Time: Toggles the LED on GPIO7 only when 1000 milliseconds have passed
  • Reads the Button: Checks GPIO5 on every loop, thousands of times per second
  • Stays Free: Leaves room for other work in loop()
/* * 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-led-blink-without-delay */ #define LED_PIN 7 // The ESP32 C3 SuperMini pin GPIO7 connected to LED #define BUTTON_PIN 5 // The ESP32 C3 SuperMini pin GPIO5 connected to button #define BLINK_INTERVAL 1000 // interval at which to blink LED (milliseconds) int led_state = LOW; // led_state used to set the LED int prev_button_state = LOW; // will store last time button was updated unsigned long prev_millis = 0; // will store last time LED was updated void setup() { Serial.begin(115200); // set the digital pin as output: pinMode(LED_PIN, OUTPUT); // set the digital pin as an input: pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { // check to see if it's time to blink the LED; that is, if the difference // between the current time and last time you blinked the LED is bigger than // The interval at which you want to blink the LED. unsigned long current_millis = millis(); if (current_millis - prev_millis >= BLINK_INTERVAL) { // if the LED is off turn it on and vice-versa: led_state = (led_state == LOW) ? HIGH : LOW; // set the LED with the led_state of the variable: digitalWrite(LED_PIN, led_state); // save the last time you blinked the LED prev_millis = current_millis; } // check button state's change int button_state = digitalRead(BUTTON_PIN); if (button_state != prev_button_state) { // print out the state of the button: Serial.println(button_state); // save the last state of button prev_button_state = button_state; } // DO OTHER WORKS HERE }

Detailed Instructions

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Select Board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Upload Code: Run the code above on your board.
  • Open Serial Monitor: Keep the baud rate at 115200.
  • Press the Button: Press the button 4 times.
  • Watch the LED: The LED still toggles between ON and OFF every second.
  • Check the Output: See the result in the Serial Monitor.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
1 0 1 0 1 0 1 0 1
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • What It Means: All 4 presses were detected. The first 1 is the released state when the code starts.
  • Pro Tip: If the Serial Monitor stays blank, set USB CDC On Boot to Enabled in the Tools menu and upload again.

Line-by-line Code Explanation

The ESP32 C3 Super Mini code above has a line-by-line explanation in its comments. Please read them!

Adding More Tasks

This code blinks two LEDs at different speeds and also checks the state of the button.

What This Code Does:

  • LED 1: Blinks on GPIO6, toggling every 1000 milliseconds
  • LED 2: Blinks on GPIO7, toggling every 500 milliseconds
  • Separate Timers: Keeps one millis() time for each LED
  • Button: Still reads GPIO5 on every loop and prints each change

Add the second LED to the same circuit. It needs one more LED and one more 220 ohm resistor.

Component Pin ESP32 C3 Super Mini Pin
LED 1 anode (long leg), through a 220 ohm resistor GPIO6
LED 1 cathode (short leg) GND
LED 2 anode (long leg), through a 220 ohm resistor GPIO7
LED 2 cathode (short leg) GND
Button pin 1 GPIO5
Button pin 2 GND
/* * 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-led-blink-without-delay */ #define LED_PIN_1 6 // The ESP32 C3 SuperMini pin GPIO6 connected to LED 1 #define LED_PIN_2 7 // The ESP32 C3 SuperMini pin GPIO7 connected to LED 2 #define BUTTON_PIN 5 // The ESP32 C3 SuperMini pin GPIO5 connected to button #define BLINK_INTERVAL_1 1000 // interval at which to blink LED 1 (milliseconds) #define BLINK_INTERVAL_2 500 // interval at which to blink LED 2 (milliseconds) int led_state_1 = LOW; // led_state used to set the LED 1 int led_state_2 = LOW; // led_state used to set the LED 2 int prev_button_state = LOW; // will store last time button was updated unsigned long prev_millis_1 = 0; // will store last time LED 1 was updated unsigned long prev_millis_2 = 0; // will store last time LED 2 was updated void setup() { Serial.begin(115200); // set the digital pin as output: pinMode(LED_PIN_1, OUTPUT); pinMode(LED_PIN_2, OUTPUT); // set the digital pin as an input: pinMode(BUTTON_PIN, INPUT_PULLUP); } void loop() { unsigned long current_millis = millis(); // check to see if it's time to blink the LED 1 if (current_millis - prev_millis_1 >= BLINK_INTERVAL_1) { // if the LED is off turn it on and vice-versa: led_state_1 = (led_state_1 == LOW) ? HIGH : LOW; // set the LED with the led_state of the variable: digitalWrite(LED_PIN_1, led_state_1); // save the last time you blinked the LED prev_millis_1 = current_millis; } // check to see if it's time to blink the LED 2 if (current_millis - prev_millis_2 >= BLINK_INTERVAL_2) { // if the LED is off turn it on and vice-versa: led_state_2 = (led_state_2 == LOW) ? HIGH : LOW; // set the LED with the led_state of the variable: digitalWrite(LED_PIN_2, led_state_2); // save the last time you blinked the LED prev_millis_2 = current_millis; } // check button state's change int button_state = digitalRead(BUTTON_PIN); if (button_state != prev_button_state) { // print out the state of the button: Serial.println(button_state); // save the last state of button prev_button_state = button_state; } // DO OTHER WORKS HERE }

Detailed Instructions

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Select Board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Upload Code: Run the code above on your board.
  • Open Serial Monitor: Keep the baud rate at 115200.
  • Watch the LEDs: LED 2 blinks twice as fast as LED 1.
  • Press the Button: Each press and release appears in the Serial Monitor, while both LEDs keep their speed.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
1 0 1 0 1
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
  • Pro Tip: Change BLINK_INTERVAL_1 and BLINK_INTERVAL_2 to set a different speed for each LED.

Application and Project Ideas

Blinking without delay on the ESP32 C3 Super Mini helps any project that must do many things at once.

  • Status Light: Blink a "working" LED while the board reads sensors
  • Alarm Panel: Flash a warning LED and still react to a stop button at once
  • Traffic Light: Run timed light changes while watching a crossing button
  • Plant Monitor: Blink an LED when the soil is dry, and keep taking readings
  • Smart Device: Show the connection state with an LED while WiFi code keeps running

Challenge Yourself

Try these challenges to practice non-blocking code on your ESP32 C3 Super Mini.

  • Easy: Change BLINK_INTERVAL to make the LED blink faster or slower
  • Easy: Print a message to the Serial Monitor each time the LED changes state
  • Medium: Make the button change the blink speed between slow and fast
  • Medium: Add a third LED with its own interval and its own timer
  • Advanced: Make the LED stay ON for 200 milliseconds and OFF for 800 milliseconds
  • Advanced: Rewrite the two-LED code with the ezLED library and compare the code

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!