Arduino - Button - Debounce
When a button is pressed/released or when a switch is toggled, newbies usually think simply that its state is changed from LOW to HIGH or HIGH to LOW. In practice, it is not exactly like that. Because of the mechanical and physical characteristics, the state of the button (or switch) might be toggled between LOW and HIGH several times. This phenomenon is called chattering. The chattering phenomenon makes a single press that may be read as multiple presses, resulting in a malfunction in some kinds of applications. This tutorial shows how to eliminate this phenomenon (called debounce the input).
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
Image is developed using Fritzing. Click to enlarge image
Let's see and compare Arduino code between WITHOUT and WITH debounce and their behaviors.
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.
- DEBOUNCE_DELAY value depends on the applications. Different applications may use different values.
The debounce method can apply for switch, touch sensor ...