Debouncing a switch before GPIO pin

I'm using the following switch circuit to trigger a code inside arduino.
While working fine, I might think I should make the switch debounce. How shall I do so? Adding a capacitor in parallel with the 10k pulldown resistor will work? if so what value shall I use?

Why are you using external pulldown resistors when the internal pullups are free?

Hello
Do you have to work with external R/C components?
If NOT, take a view here to gain the knowledge.

and

Have a nice day and enjoy coding in C++.
Дайте миру шанс!

Yes, for that project I must work with the schematics I have uploaded. I can't change it for that specific project

what? if you can't change the circuit, then what exactly are you asking for? groundFungus provided you with a better version of what you described in your original post. why did you ask if you should add it, if you can't add it? Im super confused.

What I mean is that I can add a capacitor but can't change the circuit as a pulldown (pressing 5V not pressing 0V)

Why not just try it and see if it makes a difference. I can't tell you if it works or not. I have not wired a switch active high in many years.

Is this for a class?

Yes (in any case, it will not be a problem).

100nF ... 2.2µF

Since you have a very powerful microcontroller (presumably, an Arduino since you did not mention), why would you not just code it to perform the debouncing? :astonished:

Saves on components, works better and responds faster. :face_with_raised_eyebrow:

Can you explain the purpose of the 1k resistors?

Code doesn't always need it. Post it if you're not sure.

The default circuit is (should be) the switch between pin and ground. Nothing else.
With internal pull up enabled in pinMode, and software debounce when needed.

External parts are sometimes used in noisy/RF environments or with long wiring.
Stronger pull up and/or 100n ceramic to ground.
Leo..

Your circuit looks fine to me. The 1K would protect the GPIO pin if it gets inadvertently set as an output.

You could easily debounce in software, but if for some reason you need to use interrupts (timing critical application) then a 1μF capacitor in parallel with the 10K resistor would work well. It would:

  • maintain near instant response to button presses
  • provide a slower fall time on button release (10ms time constant) good for debouncing
  • prevent flooding the interrupt with multiple triggers upon press and release
  • provide adequate wetting current which would improve reliability

I think, with the 1K resistor in place, it would be best to connect the capacitor from GPIO pin to GND. Since the delay time is proportional to R times C in seconds, the resistor will add to the delay time and a smaller capacitor can be used.

But for a timing critical application, you are not going to use a capacitor to delay the response!
:astonished:

how "timing critical" can a button press really be? we are talking about millisecond delays & if that results in the trigger coming in at a more consistent time, albeit delayed, that is likely a more accurate timing method.

  • No delay on button press, only on release (just like generic software debounce).
  • Just set interrupt mode to RISING

The short circuit to 5V on button press (IMHO) almost instantly charges the capacitor (100 μs?). This wins out over having no capacitor and an interrupt input with 1-15 ms of multiple triggering due to contact bounce.

You can avoid the use of capacitor by including Debounce.h Library and the associated methods in your sketch. There are examples with the Library that you can practice to understand the working principle of the debouncing mechanism.
Debounce-master.zip (7.5 KB)

Except that with the capacitor initially discharged a (theoretically infinite) surge current will flow when the switch closes.

And through the internal pin protection diodes, when you accidentality short the 5volt supply or power down the Arduino.
Leo..

No. It is for a friend who specific ask for Active High switch (aka pull down resistor)

What do you consider a critical application? with the 1uF capacitor in parallel with the pull down 10k resistor at the GPIO pin 10ms should be fine for most application isn't it?