Learn how to eliminate button chattering on your ESP32 C3 Super Mini with proper debounce techniques. This tutorial shows you simple methods to handle button presses accurately.
In this tutorial, you'll learn:
What button debounce is and why it matters
How to debounce a button on ESP32 C3 Super Mini using code
How to use the ezButton library for easier debouncing
How to debounce multiple buttons at once
When you press a button, does its state change from LOW to HIGH (or HIGH to LOW) just once? Not quite! In the real world, a single button press causes the state to toggle between LOW and HIGH multiple times very quickly. This is a physical characteristic of mechanical buttons called chattering. The chattering phenomenon makes your ESP32 C3 Super Mini read multiple button presses when you only pressed it once, causing errors in your projects. The solution to eliminate this issue is called button debounce.
This tutorial covers:
Debouncing a single button with built-in ESP32 code
Using the ezButton library for simple debounce implementation
Handling multiple buttons with debounce on ESP32 C3 Super Mini
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 .
Overview of Button
Buttons are input devices that detect when they are pressed or released.
We have a dedicated tutorial covering everything about buttons with ESP32 C3 Super Mini:
Wire the components: Follow the wiring diagram shown above to connect the button to pin GPIO7.
Connect the board: Plug your ESP32 C3 Super Mini into your computer using a USB Type-C cable.
Open Arduino IDE: Launch the Arduino IDE on your computer.
Select your board: Choose "ESP32 C3 Super Mini" and the correct COM port from the Tools menu.
Upload the code: Copy the code below and upload it to your ESP32 C3 Super Mini board.
Open Serial Monitor: Click the Serial Monitor icon to view the output.
Test the button: Press the button once and hold it for several seconds, then release it.
Observe the results: Watch the Serial Monitor output showing multiple press/release events.
Pro Tip: If you don't see chattering immediately, try pressing the button several times - it's a random phenomenon that appears intermittently.
/* * 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-button-debounce */#define BUTTON_PIN D7 // The ESP32 C3 SuperMini pin GPIO7 pin connected to buttonint prev_state = LOW; // The previous state from the input pinint button_state; // The current reading from the input pinvoidsetup() {// Initialize the Serial to communicate with the Serial Monitor.Serial.begin(9600);// initialize the button pin as an pull-up input (HIGH when the switch is open and LOW when the switch is closed)pinMode(BUTTON_PIN, INPUT_PULLUP);}voidloop() {// read the state of the switch/button: button_state = digitalRead(BUTTON_PIN);if (prev_state == HIGH && button_state == LOW)Serial.println("The button is pressed");elseif (prev_state == LOW && button_state == HIGH)Serial.println("The button is released");// save the the last state prev_state = button_state;}
Serial Monitor Output:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
The button is pressed
The button is pressed
The button is pressed
The button is pressed
The button is released
The button is released
The button is released
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
⇒ As you can see, you pressed the button only once and released it once, but the ESP32 C3 Super Mini detected multiple presses and releases due to chattering.
※ NOTE THAT:
The chattering phenomenon does not happen all the time. If it does not happen, please try the above test several times to observe it.
Reading Button with Debounce
This code eliminates chattering by implementing button debounce on your ESP32 C3 Super Mini.
What this debounce code does:
Records the time when the button state changes
Waits for a short delay (debounce time) before confirming the change
Ignores rapid state changes during the debounce period
Copy the code: Copy the debounce code below into Arduino IDE.
Upload the code: Click the Upload button to program your ESP32 C3 Super Mini.
Open Serial Monitor: Click the Serial Monitor icon to view the output.
Test the button: Press the button and hold it for several seconds, then release it.
Observe the results: Notice that you now see only one press and one release event.
Pro Tip: If you still see chattering, try increasing the DEBOUNCE_TIME value from 50 to 100 milliseconds.
/* * 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-button-debounce */#define BUTTON_PIN D7 // The ESP32 C3 SuperMini pin GPIO7 pin connected to button#define DEBOUNCE_TIME 50 // The debounce time in millisecond, increase this time if it still chattersint prev_state_steady = LOW; // The previous steady state from the input pinint prev_state_flick = LOW; // The previous flickerable state from the input pinint button_state; // The current reading from the input pinunsignedlong last_debounce_time = 0; // The last time the output pin was toggledvoidsetup() {// Initialize the Serial to communicate with the Serial Monitor.Serial.begin(9600);// initialize the button pin as an pull-up input (HIGH when the switch is open and LOW when the switch is closed)pinMode(BUTTON_PIN, INPUT_PULLUP);}voidloop() {// read the state of the switch/button: button_state = digitalRead(BUTTON_PIN);// check to see if you just pressed the button// (i.e. the input went from LOW to HIGH), and you've waited long enough// since the last press to ignore any noise:// If the switch/button changed, due to noise or pressing:if (button_state != prev_state_flick) {// reset the debouncing timer last_debounce_time = millis();// save the the last flickerable state prev_state_flick = button_state; }if ((millis() - last_debounce_time) > DEBOUNCE_TIME) {// whatever the reading is at, it's been there for longer than the debounce// delay, so take it as the actual current state:// if the button state has changed:if(prev_state_steady == HIGH && button_state == LOW)Serial.println("The button is pressed");elseif(prev_state_steady == LOW && button_state == HIGH)Serial.println("The button is released");// save the the last steady state prev_state_steady = button_state; }}
Serial Monitor Output:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
The button is pressed
The button is released
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
⇒ Perfect! You pressed once and released once, and the ESP32 C3 Super Mini correctly read one press and one release. The chattering has been eliminated with proper button debounce.
We Made It Simple - ESP32 C3 Super Mini Button Debounce Code with Library
We created the ezButton library to make button debouncing much easier, especially when working with multiple buttons on your ESP32 C3 Super Mini.
Benefits of using ezButton library:
Simple one-line setup for button debounce
Clean, readable code
Easy to manage multiple buttons
Built-in functions for press and release detection
ESP32 C3 Super Mini Button Debounce Code for A Single Button
This example shows how to debounce a single button using the ezButton library on ESP32 C3 Super Mini.
/* * 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-button-debounce */#include <ezButton.h>#define DEBOUNCE_TIME 50 // the debounce time in millisecond, increase this time if it still chattersezButtonbutton(D7); // create ezButton object for pin GPIO7voidsetup() {Serial.begin(9600);button.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 milliseconds}voidloop() {button.loop(); // MUST call the loop() function firstif (button.isPressed())Serial.println("The button is pressed");if (button.isReleased())Serial.println("The button is released");}
ESP32 C3 Super Mini Button Debounce Code for Multiple Buttons
This example demonstrates how to debounce three buttons simultaneously on your ESP32 C3 Super Mini using the ezButton library.
The wiring diagram
Connect three buttons to your ESP32 C3 Super Mini as shown below.
This image is created using Fritzing. Click to enlarge image
Button
ESP32 C3 Super Mini Pin
Button 1
D5 and GND
Button 2
D6 and GND
Button 3
D7 and 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-button-debounce */#include <ezButton.h>#define DEBOUNCE_TIME 50 // the debounce time in millisecond, increase this time if it still chattersezButtonbutton1(D5); // create ezButton object for pin D5ezButtonbutton2(D6); // create ezButton object for pin D6ezButtonbutton3(D7); // create ezButton object for pin D7voidsetup() {Serial.begin(9600);button1.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 millisecondsbutton2.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 millisecondsbutton3.setDebounceTime(DEBOUNCE_TIME); // set debounce time to 50 milliseconds}voidloop() {button1.loop(); // MUST call the loop() function firstbutton2.loop(); // MUST call the loop() function firstbutton3.loop(); // MUST call the loop() function firstif (button1.isPressed())Serial.println("The button 1 is pressed");if (button1.isReleased())Serial.println("The button 1 is released");if (button2.isPressed())Serial.println("The button 2 is pressed");if (button2.isReleased())Serial.println("The button 2 is released");if (button3.isPressed())Serial.println("The button 3 is pressed");if (button3.isReleased())Serial.println("The button 3 is released");}
Serial Monitor Output:
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32C3 Dev Module
Newbiely.ino
···
8Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32C3 Dev Module' on 'COM15')
New Line
9600 baud
The button 1 is pressed
The button 2 is pressed
The button 1 is released
The button 3 is pressed
The button 2 is released
The button 3 is released
Ln 11, Col 1
ESP32C3 Dev Module on COM15
2
Application Ideas
Here are some practical projects where button debounce is essential for your ESP32 C3 Super Mini:
Door lock systems with keypad entry
Game controllers with responsive button input
Remote control devices for home automation
Menu navigation systems with multiple buttons
Counter circuits that need accurate press detection
Security alarm keypads with reliable input
Challenge Yourself
Try these challenges to improve your ESP32 C3 Super Mini button debounce skills:
Easy: Change the debounce time to different values and observe how it affects button response
Medium: Add an LED that toggles on/off with each button press using debounced input
Medium: Create a counter that increments only once per button press, displaying the count on Serial Monitor
Advanced: Build a 4-button menu system with debounce where each button performs a different action
Advanced: Implement long-press detection that triggers different actions for short vs. long button presses
Additional Knowledge
Important debounce tips for ESP32 C3 Super Mini:
The DEBOUNCE_TIME value depends on your specific button hardware
Different buttons may require different debounce times (typically 20-100ms)
Start with 50ms and adjust if you still see chattering
Debounce techniques also work for switches, limit switches, reed switches, and touch sensors
Hardware debounce (using capacitors) can complement software debounce for critical applications
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!