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.
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.
Figure2.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.
Figure2.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.