ESP32 C3 Super Mini - Button LED
This tutorial shows you how to use the ESP32 C3 Super Mini with a button to control an LED. Whether you're syncing the LED to button presses or toggling states, you'll learn both methods with simple code examples.
In this tutorial, you'll learn:
How ESP32 C3 Super Mini buttons control LED states
How to wire a button and LED to ESP32 C3 Super Mini
How to write code for synchronized and toggle control
Why button debouncing is essential for reliable LED toggling
How to use the ezButton library for clean, reliable button control
We'll cover two distinct use cases for ESP32 C3 Super Mini button LED control:
Use-Case 1 - Synchronized LED and button states:
ESP32 C3 Super Mini turns the LED ON when the button is pressed
ESP32 C3 Super Mini turns the LED OFF when the button is released
LED state directly mirrors button state in real-time
Use-Case 2 - Toggle LED state with button presses:
ESP32 C3 Super Mini detects button press (HIGH to LOW transition)
LED toggles ON if currently OFF, or OFF if currently ON
Releasing the button doesn't change the LED state
Requires debouncing for reliable operation
In Use-Case 2, button debouncing is critical. We'll demonstrate the difference between ESP32 C3 Super Mini code with and without debouncing so you can see why it matters.
Or you can buy the following kits:
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.
LEDs and buttons are fundamental components for ESP32 C3 Super Mini projects.
For complete beginner guides, check these tutorials:
Key points about this setup:
LEDs require current-limiting resistors (220 ohm recommended)
Buttons can be wired with internal or external pull-up/pull-down resistors
ESP32 C3 Super Mini supports both digital input (button) and output (LED) simultaneously
Combining buttons and LEDs creates interactive projects perfect for beginners
Connect the button and LED to your ESP32 C3 Super Mini following the diagram below.

This image is created using Fritzing. Click to enlarge image
Wiring connections:
| Component | Pin | ESP32 C3 Super Mini Pin |
| Button | One terminal | D5 |
| Button | Other terminal | GND |
| LED | Anode (long leg) | D7 |
| LED | Cathode (short leg) | 220Ω resistor to GND |
Important notes:
This ESP32 C3 Super Mini application demonstrates direct LED control with a button.
What this code does:
Reads the button state continuously on ESP32 C3 Super Mini
Turns the LED ON immediately when button is pressed
Turns the LED OFF immediately when button is released
Creates a simple, real-time synchronized response
#define BUTTON_PIN D5
#define LED_PIN D7
int button_state = 0;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
button_state = digitalRead(BUTTON_PIN);
if(button_state == LOW)
digitalWrite(LED_PIN, HIGH);
else
digitalWrite(LED_PIN, LOW);
}
Wire the components: Follow the wiring diagram shown above.
Connect ESP32 C3 Super Mini: Use a USB Type-C cable to connect to your computer.
Select your board: Choose the ESP32 C3 Super Mini board and its COM port in Arduino IDE.
Upload the code: Copy the code above and upload it to your ESP32 C3 Super Mini.
Test the button: Press and hold the button for a few seconds.
Observe the LED: Watch the LED turn ON and OFF with button presses.
Pro Tip: If the LED behavior seems reversed, check that you've correctly identified the button pressed state.
You will see that the LED state is in sync with the button state on your ESP32 C3 Super Mini.
Check out the line-by-line explanation contained in the comments of the source code!
This ESP32 C3 Super Mini application shows how to toggle an LED with button presses instead of direct synchronization.
Toggle behavior on ESP32 C3 Super Mini:
First button press turns LED ON
Second button press turns LED OFF
Each press switches to the opposite state
Requires debouncing for reliable operation
This first example demonstrates the problem with button toggling on ESP32 C3 Super Mini without debouncing.
#define BUTTON_PIN D5
#define LED_PIN D7
int led_state = LOW;
int prev_button_state;
int button_state;
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
button_state = digitalRead(BUTTON_PIN);
}
void loop() {
prev_button_state = button_state;
button_state = digitalRead(BUTTON_PIN);
if(prev_button_state == HIGH && button_state == LOW) {
Serial.println("The button is pressed");
led_state = !led_state;
digitalWrite(LED_PIN, led_state);
}
}
You can locate the explanation in the comment lines of the ESP32 C3 Super Mini code above.
Understanding the toggle logic:
In the code, the expression led_state = !led_state is equal to the following code:
if(led_state == LOW)
led_state = HIGH;
else
led_state = LOW;
Why this shorthand works:
The ! operator inverts the boolean value
More compact and easier to read
Common pattern in ESP32 C3 Super Mini toggle applications
Upload the code: Copy the code above and upload it to your ESP32 C3 Super Mini.
Test multiple presses: Press and release the button several times.
Observe erratic behavior: Notice the LED may toggle inconsistently.
Understand the problem: Single presses might toggle the LED multiple times or not at all.
Pro Tip: This inconsistency happens because buttons "bounce" electrically when pressed, creating multiple signals.
You may observe that the LED state is toggled every time the button is pressed. However, this behavior may not always be consistent. At times, the LED state may be rapidly toggled multiple times within a single button press, or it may not toggle at all (toggling twice in quick succession which can be difficult to see with the naked eye).
⇒ To solve this problem, we need to debounce for the button.
Now we'll use proper debouncing to make the ESP32 C3 Super Mini button LED toggle reliable.
Why use the ezButton library:
Handles all debouncing automatically for ESP32 C3 Super Mini
Simple, beginner-friendly commands
Eliminates button bounce problems completely
Makes ESP32 C3 Super Mini projects more professional
Debouncing a button can be challenging for beginners. Fortunately, the ezButton library makes it easy.
Why is debouncing necessary? See the ESP32 C3 Super Mini - Button Debounce tutorial for more information.
#include <ezButton.h>
#define BUTTON_PIN D5
#define LED_PIN D7
ezButton button(BUTTON_PIN);
int led_state = LOW;
void setup() {
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
button.setDebounceTime(50);
}
void loop() {
button.loop();
if(button.isPressed()) {
Serial.println("The button is pressed");
led_state = !led_state;
digitalWrite(LED_PIN, led_state);
}
}
Install ezButton library: Install the ezButton library. Refer to
How To for instructions.
Upload debounced code: Copy the code above and upload it to your ESP32 C3 Super Mini.
Test button presses: Press and release the button multiple times.
Observe reliable toggling: Notice the LED toggles exactly once per press.
Compare behaviors: Notice how much more reliable this is compared to the non-debounced version.
Pro Tip: The ezButton library works with all ESP32 C3 Super Mini projects requiring button input.
You will see that the LED state is toggled exactly once each time the button is pressed on your ESP32 C3 Super Mini.
Here are some creative ways to use ESP32 C3 Super Mini button LED control in your projects:
Build a simple ESP32 C3 Super Mini desk lamp with manual ON/OFF toggle control
Create a doorbell indicator that lights up when the button is pressed
Design a game buzzer system with visual LED feedback using ESP32 C3 Super Mini
Make a status indicator for equipment (ON/OFF state) with ESP32 C3 Super Mini
Build a simple lock indicator showing locked/unlocked status with button control
Create a reaction time game measuring how fast you can toggle the LED
Watch the video below for a visual walkthrough of this ESP32 C3 Super Mini button LED project.
Try these challenges to improve your ESP32 C3 Super Mini button LED skills:
Easy: Modify the code to control two LEDs with a single button (one ON when pressed, one OFF)
Easy: Change the LED to blink three times when the button is pressed instead of staying solid
Medium: Add a second button to your ESP32 C3 Super Mini to control LED brightness (dim/bright toggle)
Medium: Create a traffic light sequence that advances to the next state with each button press
Advanced: Implement a long-press detection that behaves differently than a short press on ESP32 C3 Super Mini
Advanced: Build a combination lock using multiple buttons where the LED only turns ON with the correct sequence