What is Debouncing?

Processing that removes switch bounce, by software that accepts a change only after repeated identical readings or by hardware filtering.

Field: Embedded Systems & Firmware

Japanese name: デバウンス

The basic software method

A timer interrupt reads the pin every 5 to 10 ms, and the state is accepted as changed only after several identical readings in a row. Reading every 5 ms and waiting for four matching samples gives a delay of about 20 ms, which a person does not notice. Besides counting matches, a common trick shifts the last eight readings into one byte and accepts the change when the byte is all ones or all zeros.

Hardware methods

A resistor-capacitor low-pass filter smooths the fast changes and a Schmitt-trigger input squares the result. With 10 kΩ and 0.1 µF the time constant is 1 ms. A changeover switch (common, normally open and normally closed terminals) can drive an SR latch that holds the first contact, giving one clean transition with no delay. When extra parts are unwelcome, debouncing in microcontroller software is the usual choice.

Choosing the time

How long contacts bounce depends on the switch type and its age: often a few milliseconds, sometimes more than 10 ms. Check the datasheet or capture the waveform with an oscilloscope, then make the confirmation time longer than that. Too long a time makes the button feel sluggish. Reacting to the first change and then ignoring changes for a fixed time responds faster, but it also reacts to a single noise spike.

Try it: questions about Debouncing

In the step response of an RC circuit, how long does it take for the capacitor voltage to reach about 63% of its final value?

  1. ARC2RC / 2
  2. BRC (the time constant)
  3. C5RC
Show answer and explanation

Answer: B. RC (the time constant)

The capacitor voltage in an RC circuit follows V(1−e−t/RC)V(1 − e^(−t/RC)), reaching1−1e≈63 %1 − 1/e ≈ 63%at t = RC. This RC is the time constant τ: about 86% at 2τ, 95% at 3τ and over 99% at 5τ, so charging is considered complete after 5τ. For 10 kΩ and 1 µF, τ = 10 ms. It is used to estimate reset-delay circuits, switch debouncing and flash charging times.

What is the phenomenon called in which a mechanical switch's contacts bounce, turning on and off many times in a short period when pressed?

  1. ALatch-up
  2. BCrosstalk
  3. CContact bounce (chattering)
Show answer and explanation

Answer: C. Contact bounce (chattering)

When a mechanical switch closes, the metal contacts bounce and turn on and off for a few milliseconds. A microcontroller reads its pins very fast, so counting naively would register one press as several. The bounce is removed in software by waiting and rereading, or in hardware by smoothing the waveform with a resistor and capacitor and feeding it to a Schmitt trigger to get a clean 0 or 1. This processing is called debouncing.

FAQ

Can debouncing be done with interrupts alone?

An edge interrupt fires on every bounce. It works if the first interrupt disables that pin interrupt and a timer re-reads the pin some tens of milliseconds later before enabling it again. Reading on a periodic timer is simpler and handles many switches at once.

Is a delay of a few tens of milliseconds enough?

It works, but everything else stops while the code waits, and waiting inside an interrupt handler is especially bad. Sampling on a periodic timer avoids blocking other work.

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