What is Debouncing?
Processing that removes switch bounce, by software that accepts a change only after repeated identical readings or by hardware filtering.
Japanese name: デバウンス
Processing that removes switch bounce, by software that accepts a change only after repeated identical readings or by hardware filtering.
Japanese name: デバウンス
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.
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.
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.
Answer: B. RC (the time constant)
The capacitor voltage in an RC circuit follows , reachingat 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.
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.
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.
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.
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.