I have been wondering: why cannot you just hook up a capacitor to a button to debounce it? I have been figuring out how to reduce the work my microprocessor has to do, but I have very limited space on a PCB I am designing, so I don't want to do a full-blown debounce circuit which would complicate the design.


simulate this circuit – Schematic created using CircuitLab

That's a example circuit; sorry for any errors (I am not good at designing circuits with capacitors). Would this even work? For the tack switch, I couldn't find one that matches what it is in real life, but it works for this situation. The button is like the one found here. D10 stands for Digital Pin 10, but it doesn't matter; it just means the Arduino input. I also don't know how big of capacitor I would need, so if this circuit works, what size do I need?

Again, I am just trying to simplify this to make it easier to build while not having to do software debouncing. From looking at how capacitors work, this seems like it would work, but also it might make the button press longer/delay it if the capacitance is too big. They are commonly used for "smoothing" out noise in power supplies, so isn't this a similar thing where it "smooths" out the bouncing? Any circuit modifications to make it work (if needed) would also be appreciated.

  • 1
    \$\begingroup\$ Here's where we have discussed it before: electronics.stackexchange.com/questions/6884/… \$\endgroup\$ – Andy aka Apr 7 '13 at 17:54
  • 5
    \$\begingroup\$ Do you realize that you can debounce an input simply by polling it with an interval of at least 50 ms? Less work to do for your aduino :) \$\endgroup\$ – Wouter van Ooijen Apr 7 '13 at 17:55
  • 1
    \$\begingroup\$ 50 milli seconds would do - good point Mr O \$\endgroup\$ – Andy aka Apr 7 '13 at 18:00
  • 1
    \$\begingroup\$ No, I mean poll with an interval of at least 50 ms, and do whatever you need to do according to the level you detect. \$\endgroup\$ – Wouter van Ooijen Apr 7 '13 at 18:14
  • 1
    \$\begingroup\$ @AnnonomusPerson - a delay() in a single-threaded environment means nothing else can happen. While that is one option, another is to do other useful work until it is time to check again. \$\endgroup\$ – Chris Stratton Apr 7 '13 at 18:41

It depends on what the default state of the switch is. A capacitor will only charge when you give it a positive voltage. Usually, in an embedded environment, we use a pull-up to give a pin a default high state, and link the switch to ground. Adding a capacitor won't help here, because it won't "store" the ground state.

However, you can also use a pull-down. This would mean the pin is by default low. Making it high by pressing the switch, will charge the capacitor. After releasing, the capacitor will keep the pin high for a little while, so yes, this would work. I'm not sure if 1uF is enough, too little or too much, I'd recommend you to look with a scope and try it out a bit.

  • \$\begingroup\$ So if I changed the + and the - it would work? \$\endgroup\$ – Anonymous Penguin Apr 7 '13 at 18:13
  • \$\begingroup\$ @AnnonomusPerson it depends. What is the default state of the switch? \$\endgroup\$ – user17592 Apr 7 '13 at 18:15
  • \$\begingroup\$ You mean when it is not pressed whether it conducts electricity? If that is what you mean, I can do it either way because of the nature of the switch I am using. Looking at the link in my question, when not pressed, the button conducts from the top left to the bottom left and the top right to the bottom right. When pressed, it conducts from the top left to the bottom right, and the top right to the bottom left. \$\endgroup\$ – Anonymous Penguin Apr 7 '13 at 18:22
  • \$\begingroup\$ Okay. This will mean you by default want the pin to be low. The switch should make contact to +, so that the capacitor gets some charge before you release the button. \$\endgroup\$ – user17592 Apr 7 '13 at 18:24
  • 3
    \$\begingroup\$ @AnnonomusPerson No, the switch should make contact to +. It's kinda jargon for what the switch will connect to when pressed. The capacitor is in the right place. The resistor would be better connected from ground to the IO pin directly. \$\endgroup\$ – user17592 Apr 7 '13 at 18:36

Not the answer you're looking for? Browse other questions tagged or ask your own question.