About this calculator
Mechanical switch contacts do not close cleanly. They bounce apart and back together for anything from a few hundred microseconds to tens of milliseconds, and a microcontroller polling fast enough will read that as a burst of presses.
An RC network smooths the transition so the input crosses its logic threshold only once, after the contacts have settled. This calculator sizes the resistor and capacitor for your bounce time, or checks a pair you already have.
How it works
The standard circuit is a pull-up resistor to Vdd, the switch to ground, and a capacitor across the switch. Pressing shorts the capacitor out; releasing lets it charge back up through the resistor along an RC curve.
What matters is how long that curve takes to cross the input's logic threshold. For a CMOS input that is about 0.7 Vdd, which is −ln(1 − 0.7) ≈ 1.2 time constants. Make that crossing take longer than the bounce window and the contacts have finished chattering before the logic sees any change.
The press direction behaves quite differently. Closing the switch discharges the capacitor directly through the contacts — nearly instantly, and with a current spike limited only by contact resistance. A series resistor of a few hundred ohms tames that, protects the pin, and gives the press its own (shorter) time constant.
A slow RC edge into an ordinary logic input is not ideal: while the input dwells near its threshold it can oscillate and draw shoot-through current. Feeding it into a Schmitt trigger — a 74HC14, or a pin configured for hysteresis — converts the slow ramp into a clean fast edge.
Worked example
Debouncing a tactile pushbutton with about 5 ms of bounce, on a 5 V supply, feeding a 74HC14 Schmitt trigger.
- Choose C = 100 nF, a convenient ceramic
- Schmitt threshold ≈ 0.6 Vdd → −ln(1 − 0.6) = 0.916 time constants
- R = 5e-3 / (0.916 × 100e-9) = 54.6 kΩ
- Nearest E24: 56 kΩ
- Release time: 0.916 × 56000 × 100e-9 = 5.1 ms — just past the bounce window
- Add Rs = 220 Ω: press spike = 5 / 220 = 23 mA
56 kΩ pull-up, 100 nF capacitor, 220 Ω in series with the switch. The release edge takes 5.1 ms to cross threshold, comfortably outlasting the bounce, and the contacts only ever see 23 mA.
Practical notes
- Typical bounce times: 1–5 ms for small tactile switches, 5–20 ms for larger mechanical switches and relays. Measure yours on a scope if it matters.
- The series resistor Rs is not optional in practice. Without it, the capacitor dumps its charge straight through the contacts every press, which pits them and shortens switch life.
- Too much RC makes the button feel laggy. Beyond about 50 ms users notice the delay.
- Feed the output into a Schmitt-trigger input wherever you can. A slow ramp into a plain CMOS input can produce multiple transitions all by itself — exactly what you were trying to avoid.
- Software debouncing is free. Sample the pin every few milliseconds and accept a change only after several consecutive agreeing reads. Hardware earns its place when the signal drives an interrupt, a counter, or logic with no CPU behind it.
- For rotary encoders, RC debouncing is usually the wrong approach — it destroys the timing relationship between the two channels. Use a state-machine decoder instead.
Frequently asked questions
How do I debounce a switch with an RC circuit?
Pull-up resistor to Vdd, switch to ground, capacitor across the switch. Size RC so the release edge takes longer to cross the logic threshold than the contacts take to stop bouncing — typically a 5–10 ms time constant.
How long do switch contacts bounce?
Small tactile switches bounce for 1–5 ms; larger mechanical switches and relays for 5–20 ms. It varies with the switch, how hard it is pressed, and how worn it is.
Should I debounce in hardware or software?
Software when a CPU is already polling the pin — it costs nothing and is easy to tune. Hardware when the signal drives an interrupt, feeds a counter, or goes into logic with no processor, and when you need a genuinely clean edge.
Why do I need the series resistor?
It limits the current the capacitor dumps through the switch contacts on each press. Without it that surge is limited only by contact resistance, which pits the contacts and shortens the switch's life.
Why use a Schmitt trigger?
An RC produces a slow ramp, and an ordinary logic input hovering near its threshold can oscillate and draw excessive current. A Schmitt trigger has separate rising and falling thresholds, so it snaps cleanly once and stays there.