PAGE 111 OF 150 · MICROCONTROLLERS & LEDS
Debouncing Explained
Switch contacts bounce for a few milliseconds.
LED SYMBOLTriangle points from anode to cathode; the arrows show light leaving the part.
What bounce is
When a mechanical switch closes, its contacts spring against each other for a few milliseconds, creating several rapid on-off pulses. A microcontroller is fast enough to count each one as a separate press.
Fixes
- Software: after a change, ignore the input for 20 to 50 milliseconds.
- Hardware: a 10 kilohm resistor with a 100 nanofarad capacitor smooths the signal, and a Schmitt trigger cleans the edges.
- A set-reset latch made from two gates gives perfect debouncing for a changeover switch.
Always test with a counter. If one press adds more than one, bounce is the cause.
REMEMBER
One press can look like many until it is debounced.Try it yourself
Sketch the circuit on paper first, calculate the values, then build it on a solderless breadboard using a low-voltage supply. Measure with a multimeter before you make anything permanent.
Explore LED clocks, stopwatches and electronics at cosycom.com.