# How does the capacitor in a debouncing circuit work?

On the following circuit (a debounced push button that turns on a LED):

simulate this circuit – Schematic created using CircuitLab

I'm trying to understand why the LED will not light up as the capacitor looks like it's bypassing the switch. When the capacitor is full, it doesn't transmit/conduct electricity?

You'll notice that I'm very beginner, but after 20 hours of reading various tutorials, I still can't really figure out something very simple; how does the full capacitor act differently than a simple wire? If I replaced the capacitor with a wire placed a wire instead of the capacitor, the light would always be on.

Edit: Some people pointed out that the debouncing circuit made no sense (bad voltage, etc.) Here's my 2nd attempt to make more sense. R5 and R6 could be the same, but I thought keeping them separate would help to keep 1 job to each component.

This is not a good debounce circuit.

One problem is that (at least ideally) the switch and its connecting wires have a resistance of zero. This means that the capacitor will instantaneously discharge when the switch is closed. (In practical terms, also, this rapid discharge could even be bad for the switch contacts or the wiring, if there is a high enough voltage on the capacitor and it has a high enough capacity.)

A capacitive switch debounce should slowly charge the capacitor when the switch is in one state, and slowly discharge it when it is in another state. The RC constant doesn't have to be the same, but it should be something nonzero. The circuit has resistors that control the charging of the capacitor; it just needs a resistor in the switch loop to discharge it gracefully.

Another problem with this circuit is that the LED is only off if the circuit has been on for some time, such as if the circuit has existed since the beginning of time with that same voltage source. But what if, at time $t = 0$, the voltage source has been 0V and suddenly jumps to its voltage? At that time, the capacitor, which must have been empty, begins charging. While it is charging, current flows and the LED will light up briefly and then go dark. (Well, maybe not, because your source has only 1V, but that's another story).

In CircuitLab, you can distinguish these two situations in the "Time Domain" simulation. You can either "Skip Initial" or not. The solver can either pretend that the circuit has existed in the given state for all eternity until the time $t = 0$, and start solving it from there. Or it can solve it from the point of view that the circuit just came into existence at $t = 0$ and the voltage sources spring into life, the capacitors are empty, and so on.

One final consideration here is that the circuit only lights a LED, so switch bounce is basically moot, unless the LED is shining on some optical detector where the switch bounce turns into a glitch in the signal. If the LED's job is to just provide a pretty light, then your eye won't even be fast enough to see the switch bounce.

Here is a time domain simulation of the circuit (after changing V1 to 3V). What is plotted is the LED current. Important: the Skip Initial parameter is set to Yes, so we can see what happens when the capacitor is initially empty and the voltage source energizes to 3V. This is all with the switch in an open state.

As you can see, current surges through the LED and then dies down. If your intent was that the LED is strictly controlled by the operator via the push button, then your design does not implement your intent one hundred percent.

With regard to the comment below, suppose that the aim is to actually drive a microcontroller pin (everything running at 5V). Firstly, we can do that without any capacitance and handle the debouncing in software by sampling the pin at a reasonably low rate.

simulate this circuit – Schematic created using CircuitLab

When the switch is open the output is pulled to 0V by the pull-down resistor. When we close the switch, the voltage at the top of the resistor rises to 5V. This output can be regarded as a signal. We are interested in the low frequency component of the signal: relatively slow switch presses. We want to reject high frequencies, like switch bounce. To that aim, we can add a passive, one-pole RC low-pass filter:

simulate this circuit

Now when the switch closes, the voltage rises gradually as the capacitor is charged. You can see this in the time domain simulation:

When the switch is opened, the capacitor will discharge through R1 and R1, gradually dropping the voltage back to zero. The capacitor basically follows the voltage of R1, but with lag due to having to charge through R1, and discharge through R1 and R2. (Note that the discharge is twice as slow as the charge!)

The microprocessor input senses the voltage with high impedance, so we can ignore its loading effect and not even show it on the diagram. We cannot do this in the case of the LED because it requires current which our circuit must supply. That current flows through our resistors and develops voltages that we must account for: in other words, it has "loading effects".

This type of circuit works even better if we feed the output to a Schmidt trigger. A Schmidt trigger is a kind of buffer for digital signals which shows hysteresis similar to a thermometer. Its output goes high when some high input threshold is exceeded, and falls low when a different low threshold is exceeded. For instance, it might go high when the input goes above 3.5 volts, and only go low when the input falls below 1.5.

So even if the capacitor allows through some noise that could still cause some small flipping back-and-forth near the crossing of an input's threshold, the Schmidt trigger will reject that.

Suppose we want to debounce the LED with a capacitor? The problem is that the resistances end up being too low due to the need to supply current to the LED. If we just use the same circuit and make the resistors smaller (and the capacitor larger by the same factor), we end up with something which wastes power. The way to do this is to use a small signal loop to handle the switch, and debounce it, and then use the voltage to control a transistor which dumps current into the LED.

Though debouncing a LED might be useless, if we make the resistors and/or capacitor large enough, we can obtain a nice behavior: that of the LED slowly fading on when the button is pressed and held, and fading out when it is released.

simulate this circuit

This is the same circuit as before: the "out to microcontroller" node now connects to the base of an n-channel MOSFET which drives current to the LED. The MOSFET "buffers" the debounce logic from the LED driving. The debounce circuit isn't disturbed by the low impedance of the LED, and the LED is not starved of current by the high impedances in the debounce circuit.

• Hum, so what the solution would be ? The LED could be an arduino input or something else. My question was more about the capacitor... I just tried to copy an existing debouncing circuit to illustrate my question about the capacitor. Voltage would be 5V, not 1. Apr 24, 2013 at 15:10
– Kaz
Apr 24, 2013 at 15:55
• So what you're saying is that I should add a 100olm resistance between V1 and SW1 ? I guess I'm just confused because I've yet to see a push button debounce circuit that involved more than 1 resistance in all the tutorial I've seen. But most do not draw the complete circuit ( to OUT, to Arduino, etc.. ) so it's hard to understand for me. So this would be bad ? : digital.ni.com/public.nsf/8e0a9cd1e264dced86256a100082b910/… Apr 24, 2013 at 17:12
• Weird, so you explained me that I can't do a push button that light up a LED, with a debouncing circuit. Anyway, this answered the initial question, I'll do more research for the rest :p I just don't like to say ' the arduino will do it ': I know, I could just add a 20ms delay and NOT do a debouncing at all, but I'm trying to understand what's the magic behind it... that's why I want a complete circuit. Apr 24, 2013 at 17:32
• You can debounce a push button that drives a LED, but it's pointless because switch bounce doesn't cause a LED to malfunction. For a complete circuit, imagine you have the Arduino there powered up by +5V and ground. Then the "out" node connects to the input pin you want to drive.
– Kaz
Apr 24, 2013 at 19:29

This effect occurs because at steady state a capacitor effectively blocks any current from DC voltages. This can be seen by understanding the equation

i=C*(dV/dt)

At DC the differential term is 0 so the current is 0. Therefore the current through the capacitor will be zero at steady state.

If you take that for granted it should be fairly obvious why this circuit works. If you want even more detail than that, then this video will probably do a better job of demonstrating how the physics of a capacitor play out to yield the result above than my description could.

• This video is great, except for the headhake it gave me :p Thanks :) Apr 24, 2013 at 15:34

A capacitor can, for many purposes, be considered as a very small rechargeable battery. It will only pass current while charging or discharging.

Most LEDs require at least 2 volts to light - for your circuit to work at all, the voltage source should be at least 3 volts. Then you might see the LED continue to glow for a fraction of a second after you open the switch, as the capacitor charges.

• I did not really configure the voltage and all that, except for the resistance. It's my first use of circuit lab, so I was just "placing the component with default values", If I would be doing it for real, it would be 5V. Apr 24, 2013 at 15:06
"When the capacitor is full, it doesn't transmit/conduct electricity"


Yes. It's not a wire, it is (like the symbol) two parallel plates close together.