Skip to main content

Subsection 2.5.1 Hardware Debouncing: RC Filter

The classic hardware fix is to add a small capacitor (0.1 µF or 0.15 µF) across the switch terminals. Together with the internal pull-up it forms an RC low-pass filter, and what it changes is how fast the voltage on the pin is allowed to move. Follow it through the four situations.
While the switch is open, the pull-up has charged the capacitor to 3.3 V through its 40 kΩ resistance, so the pin reads HIGH. When the switch is pressed, the closed contacts have almost no resistance, so the capacitor discharges through them at once and the pin goes LOW. While the contacts are bouncing, each time they break the capacitor can only recharge through the 40 kΩ pull-up, which is slow: if C is large enough the voltage stays below \(V_{\mathrm{IL}}\) until the contacts close again, so the pin keeps reading 0. Once the switch is fully closed, the capacitor stays discharged and the pin sits at 0.
Note that it is the switch contacts that bounce, never the capacitor. The capacitor’s only job is to be slow, and the RC time constant is what makes the pin too slow to follow the chatter. Breadboard placement is shown in Figure 2.4.5.
Figure 2.5.1. RC debounce circuit: the internal pull-up resistance \(R_{\mathrm{pu}}\text{,}\) about 40 kΩ, and the external capacitor form an RC low-pass filter. When the switch bounces open, the capacitor recharges slowly through \(R_{\mathrm{pu}}\text{;}\) if C is large enough, the voltage stays below \(V_{\mathrm{IL}}\) during the bounce window.
Figure 2.5.2. Effect of capacitor size on bounce suppression. Top: C = 0.01 µF, where the voltage recovers quickly between bounces and can reach \(V_{\mathrm{IH}}\text{,}\) causing spurious edges. Bottom: C = 0.1 µF, where it recovers so slowly that it stays below \(V_{\mathrm{IL}}\text{,}\) eliminating spurious transitions.
Figure 2.5.3. Side-by-side oscilloscope view: without capacitor (left) vs. with 0.1 µF (right). Orange (CH1) = button signal; blue (CH2) = LED. Without debouncing, the LED toggles multiple times per press. With the capacitor, each press produces exactly one toggle.