ESP32 - Button - Debounce
⇒ No, it is not. That is because in the physical world. when you do a single press on a button, the state of the button is quickly toggled between LOW and HIGH several times rather than once. This is the mechanical and physical characteristic. This phenomenon is known with a name: chattering. The chattering phenomenon makes MCU (e.g. ESP32) read multiple button presses in response to a single actual press. This results in a malfunction. The process to eliminate this phenomenon is called debounce. This tutorial shows how to do it.
This tutorial provides:
- How to debounce for a button on ESP32 code
- How to debounce for a button on ESP32 code using library
- How to debounce for multiple buttons on ESP32 code using library
Hardware Used In This Tutorial
|1||×||ESP-WROOM-32 Dev Module|
|1||×||Micro USB Cable|
|1||×||(Optional) 5V Power Adapter|
|1||×||(Optional) DC Power Jack|
|1||×||(Optional) ESP32 Screw Terminal Adapter|
This image is created using Fritzing. Click to enlarge image
To make it clear, let's run ESP32 code WITHOUT and WITH debounce, and compare their results
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.
- DEBOUNCE_TIME value depends on the hardware. Different hardware may use different values.
- The debounce should also apply for on/off switch, limit switch, reed switch, touch sensor ...