What is Contact bounce?

The rapid on-off flickering of a mechanical switch's contacts when pressed or released, removed by debouncing.

Field: Embedded Systems & Firmware

Japanese name: チャタリング

Why it matters

When switch contacts close, the metal bounces and makes and breaks contact several times. How long this lasts depends on the switch, but it usually settles within a few milliseconds. To a person it is one press, but a microcontroller can read a pin every microsecond, so counting edges directly turns one press into several. In designs that trigger an interrupt on each edge, every bounce fires another interrupt and can upset counters or toggling logic.

Hardware and software fixes

In hardware, the basic approach is an RC low-pass filter to smooth the rapid changes, followed by a Schmitt trigger to produce a clean 0 or 1. For a changeover switch with two contacts, an SR latch can hold the state from the first contact. In software, a timer interrupt reads the pin every few milliseconds and accepts a new state only after the same value has been seen several times in a row. Long waits inside an interrupt handler should be avoided, since they block other work.

Related flickering in other circuits

Contact bounce is one case of a broader problem: an output that flickers briefly, which Japanese engineers call chattering in general. A comparator receiving a slow or noisy signal, for example, can switch many times near its threshold. That is not mechanical bounce, and the fix is to add hysteresis. Relay contacts bounce just as switch contacts do. Telling the cases apart matters because the remedies differ: filtering and debouncing for contacts, hysteresis for comparators.

Try it: questions about Contact bounce

Which is the most suitable way to remove switch bounce in software?

  1. ARead the pin more often and treat any single 1 as a press
  2. BRead the pin every few milliseconds and accept a change only after the same value repeats several times
  3. CReboot the microcontroller whenever the switch is pressed
Show answer and explanation

Answer: B. Read the pin every few milliseconds and accept a change only after the same value repeats several times

Bounce settles within a few milliseconds, so reading the pin, say, every 5 ms and declaring a change only after three identical readings ignores the transitions during bouncing. Reading periodically from a timer interrupt avoids blocking other work. Making the delay too long makes the response feel sluggish, so it is tuned to the switch's characteristics.

Books on Embedded Systems & Firmware Ad

Learn hands-on: parts and kits

Building real circuits is a good way to check what you learned in the questions.

As an Amazon Associate I earn from qualifying purchases.

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary