IT lexicon › Hardware › Switch debouncing

Switch debouncing

Hardware På svenska → Updated: 2026-11-02

Filtering out the rapid on-off pulses a mechanical switch produces in the milliseconds after it is pressed.

Metal contacts bounce. To a microcontroller polling a GPIO pin millions of times a second, a single button press looks like ten or fifty transitions over a few milliseconds, and an edge-triggered interrupt fires just as many times. Anyone who has built their first push-button counter has watched it leap from 3 to 11.

The hardware fix is an RC filter feeding a Schmitt trigger, which slows the signal down and adds hysteresis. In firmware the usual approach is to sample the pin at a fixed rate, from a SysTick interrupt for instance, and only accept a new state once it has held steady for several samples in a row. Simply waiting 20 ms after the first edge also works, but steals time from everything else. Jack Ganssle's write-up of how real switches actually behave remains the standard reference.

← Back to the lexicon