This is a very good tutorial for debouncing a reed switch. As the reed wears, it's bounce may get worse and the software can check for abnormal readings to warn that a reed is wearing out. Reed switches typically bounce less than 1 msec when they are new. For a 5V supply, almost any silicon diode could be used. For a 3.3V supply, you may want to use a schottky diode for it's lower voltage drop. Someone mentioned putting a small resistor in series with the capacitor to limit the surge current when the switch closes, that's a good idea. A few hundred ohms will help. You don't want the rise time of the input to be too long because some logic circuits go crazy if the input slope is too slow. As the input voltage passes through the threshold, the input circuit may act like an amplifier and respond to noise on the input signal, thus causing extraneous transitions, just like switch bounce inside the micro chip. The resistor to ground, 1K in this case, can be larger if you want to use a smaller cap. It's limited by the current that flows from the digital input pin. Check the data sheet for this current value and make sure the voltage equal to the (leakage current*R_to_ground) is well below the threshold for a logic zero at the input.
Great explantion, I like your videos! One note, the peak current can be fairly high with a big capacitor. It would be be a good idea to include a resistor in series with the switch.
Thank you - this design eliminated the bounce for me, although I had to replace the 1uF capacitor with a 100nF ceramic capacitor to make it work well. To test, I used an ESP32 with a small OLED display to show a press counter. Every time the button was pressed, it incremented the counter. Without this circuit, it would increment the count multiple times for each button press. Now it correctly increments one time for each button press. I figure now that I have the button debounce working, it should work the same with the Inspeed Wind Speed sensor I have on order. Maybe it's overkill, but I'm also using software debounce logic to ignore extra triggers within a 10ms time span.
Very useful, I bought also a anemometer, a rain gauge and a wind vane (I think this is the right name for that device pointing to wind direction). All of them are using reed relays, I"ll try the hardware method you just presented to connect to digital inputs. Thank :)
I would add an Schmitt-trigger inverter which outputs a nice signal. But some Schmitt-triggers inverts the output. In some cases this inverting feature is interresting. For instance, when you use an I/O Expander.
I'm here because of debounce in computer programming, now I feel I must study electrical switches before I fully understand debounce in computer programming.
That is the simplest denounce circuit I've found so far. Previously the ones I found used either a 555 timer or a Schmitt trigger. Both of which seemed like overkill to me.
I have a video controller for my computer that,externally,looks like an XBox controller. During the game,(Halo CE for PC), when I press the button to start the elevator,the switch often times bounces and I have to hit the button a couple times until it settles and the elevator moves. Im thinking about using a ceramic 0.1 microF cap in line of the feed to increase the time on duration of the connection.Sound good?
That sounds like it might solve your issue. But I don't know how those buttons are implemented and the circuits they control so I can't say definitively if that will solve your problem
i have 2 problem how i can make debounc pcb to, cnc limit switch, C and R size NO limit switch. 12V, and second problem how make promixity sensor, sense metal, need calculate spindle speed, prox 12V, data out and arduino nano need read this but need 5V max input to nano, speed 0-30K 2x/rev=60K trick to secod ? not need debounc and need convert 12V sensor data to 5V to arduino. i not understand what need do.
Yes, the capacitor just worked well on the logic analyzer, without the capacitor, there's a lot of bouncing! Now pretty much the bounce problem is minimized to a good level, but the successive reads of the input which of course throttle the input count, I just want to count only 1 tick at a time.
@@ForceTronics Yes, exactly. The microcontroller is so fast that it count a moving object in front of the IR module 10 times in one go. I want it to count only one each time.
Most microcontrollers allow you to setup an interrupt off the rising or falling edge of a pulse that way no matter how long the pulse is you only count it once. If you are using a polling method to count a pulse then you wait until you measure first a low to high transition and then a high to low transition before you count it as a pulse. If you just try to measure "highs" then you will count the same pulse multiple times
Problem here: using a 10mfd cap and a 1n914 diode, the rapid current flow that occurs when the switch is closed causes a Reset of the arduino nano. The 5v regulator is not good enough to cope with the negative spike caused by unrestricted charging of the capacitor. I also do not understand why you are using the two resistor voltage divider joined at the anode to discharge the capacitor.
When you keep the swith pressed, no current will flow trough the diode. If you used a LED instead of the diode the LED would turn off. Which circuit would you build if you had to use a LED that goes ON when button is cept pressed?
If you are just trying to turn an LED on or off then switch bounce is not an issue because the human eye wouldn't even notice it. So for an LED I would just use a switch and a current limiting resistor
No, I wouldn't reply such if I only wished to turn on or off a LED. I wanne debounce but also wanne see a LED ON when button is pressed and OFF when the button released
Ok, I see. You should be able to use the LED in place of the diode. I guess you may need to ensure that the LED doesn't have a high voltage drop that takes you below the voltage threshold level of the digital input. Its a good idea!
It ensures that the capacitor only discharges through the resistor network. While the switch is bouncing, if the diode was not there the cap could start discharging when the switch bounce is in the open position
I don't understand why you need the 1k resistance in the first place. Also, why have you not placed the capacitor closer to the power supply? It seems to me that the way you have done it, the current will be flowing in the opposite direction while bouncing. Isn't that a problem?
Hi Yad - I believe the 1K resistor is in the circuit to hold the interrupt pin at ground level when the switch is open, and to provide a path for the capacitor to discharge following a switch closure/opening cycle. Also, the input impedance of the pin is likely high enough that charge cannot bleed off via that path.
I believe I explain it in the video. It is a phenomenon with mechanical switches that when they close fast they will go back and forth from closing and opening due to the force of closing this is called "switch bounce" and it happens in milli or micro seconds so a human does not notice but a MCU will.
Excellent visual no-nonsense explanation. No silly trailers, animations, music, etc. Just the content, as it should be.
This is a very good tutorial for debouncing a reed switch.
As the reed wears, it's bounce may get worse and the software can check for abnormal readings to warn that a reed is wearing out. Reed switches typically bounce less than 1 msec when they are new.
For a 5V supply, almost any silicon diode could be used. For a 3.3V supply, you may want to use a schottky diode for it's lower voltage drop. Someone mentioned putting a small resistor in series with the capacitor to limit the surge current when the switch closes, that's a good idea. A few hundred ohms will help. You don't want the rise time of the input to be too long because some logic circuits go crazy if the input slope is too slow. As the input voltage passes through the threshold, the input circuit may act like an amplifier and respond to noise on the input signal, thus causing extraneous transitions, just like switch bounce inside the micro chip.
The resistor to ground, 1K in this case, can be larger if you want to use a smaller cap. It's limited by the current that flows from the digital input pin. Check the data sheet for this current value and make sure the voltage equal to the (leakage current*R_to_ground) is well below the threshold for a logic zero at the input.
Great explantion, I like your videos!
One note, the peak current can be fairly high with a big capacitor. It would be be a good idea to include a resistor in series with the switch.
What a great lesson, thank you, peace and love.
Thank you - this design eliminated the bounce for me, although I had to replace the 1uF capacitor with a 100nF ceramic capacitor to make it work well. To test, I used an ESP32 with a small OLED display to show a press counter. Every time the button was pressed, it incremented the counter. Without this circuit, it would increment the count multiple times for each button press. Now it correctly increments one time for each button press. I figure now that I have the button debounce working, it should work the same with the Inspeed Wind Speed sensor I have on order. Maybe it's overkill, but I'm also using software debounce logic to ignore extra triggers within a 10ms time span.
Best explanation ever!
Very useful, I bought also a anemometer, a rain gauge and a wind vane (I think this is the right name for that device pointing to wind direction). All of them are using reed relays, I"ll try the hardware method you just presented to connect to digital inputs. Thank :)
Ilmu yg bermanfaat bagi kita semua . mantap kawan 👍
Very helpful video. Thank you!
Subscribed! Great lesson!
I would add an Schmitt-trigger inverter which outputs a nice signal. But some Schmitt-triggers inverts the output. In some cases this inverting feature is interresting. For instance, when you use an I/O Expander.
I'm here because of debounce in computer programming, now I feel I must study electrical switches before I fully understand debounce in computer programming.
Why are there no switch(es) debouncer(s)/switch(es)+debouncer(s) modules available ANYWHERE ???
That is the simplest denounce circuit I've found so far. Previously the ones I found used either a 555 timer or a Schmitt trigger. Both of which seemed like overkill to me.
I have a video controller for my computer that,externally,looks like an XBox controller.
During the game,(Halo CE for PC), when I press the button to start the elevator,the switch often times bounces and I have to hit the button a couple times until it settles and the elevator moves.
Im thinking about using a ceramic 0.1 microF cap in line of the feed to increase the time on duration of the connection.Sound good?
That sounds like it might solve your issue. But I don't know how those buttons are implemented and the circuits they control so I can't say definitively if that will solve your problem
@@ForceTronics Thanks for your reply. If we both think it may (but neither are sure right now,) I think Ill take the shot ..give it a chance.😁👍
@@STEVE_C_1369 Let me know how it goes!
@@ForceTronics Will do.
i have 2 problem how i can make debounc pcb to, cnc limit switch, C and R size NO limit switch. 12V, and second problem how make promixity sensor, sense metal, need calculate spindle speed, prox 12V, data out and arduino nano need read this but need 5V max input to nano, speed 0-30K 2x/rev=60K trick to secod ? not need debounc and need convert 12V sensor data to 5V to arduino. i not understand what need do.
Yes, the capacitor just worked well on the logic analyzer, without the capacitor, there's a lot of bouncing! Now pretty much the bounce problem is minimized to a good level, but the successive reads of the input which of course throttle the input count, I just want to count only 1 tick at a time.
I am not exactly sure what your question or comment is here. You want to trigger off of the rising or falling edge so each pulse is only counted once
@@ForceTronics Yes, exactly. The microcontroller is so fast that it count a moving object in front of the IR module 10 times in one go. I want it to count only one each time.
Most microcontrollers allow you to setup an interrupt off the rising or falling edge of a pulse that way no matter how long the pulse is you only count it once. If you are using a polling method to count a pulse then you wait until you measure first a low to high transition and then a high to low transition before you count it as a pulse. If you just try to measure "highs" then you will count the same pulse multiple times
this has built in pull-down too??
have to have a think about how to make it in pull-up ...
I'm new to arduino so sorry if I get this confused
Problem here: using a 10mfd cap and a 1n914 diode, the rapid current flow that occurs when the switch is closed causes a Reset of the arduino nano. The 5v regulator is not good enough to cope with the negative spike caused by unrestricted charging of the capacitor. I also do not understand why you are using the two resistor voltage divider joined at the anode to discharge the capacitor.
hi, i have bounce on my xbox controller uttons. is there any debounce software code i can use to eliminate it?
When you keep the swith pressed, no current will flow trough the diode. If you used a LED instead of the diode the LED would turn off. Which circuit would you build if you had to use a LED that goes ON when button is cept pressed?
If you are just trying to turn an LED on or off then switch bounce is not an issue because the human eye wouldn't even notice it. So for an LED I would just use a switch and a current limiting resistor
No, I wouldn't reply such if I only wished to turn on or off a LED.
I wanne debounce but also wanne see a LED ON when button is pressed and OFF when the button released
Ok, I see. You should be able to use the LED in place of the diode. I guess you may need to ensure that the LED doesn't have a high voltage drop that takes you below the voltage threshold level of the digital input. Its a good idea!
Great explanation but I'm still confused about why the diode is necessary?
It ensures that the capacitor only discharges through the resistor network. While the switch is bouncing, if the diode was not there the cap could start discharging when the switch bounce is in the open position
Ok, Thanks for the reply!
@@ForceTronics could you make it more clear, thank you
I don't understand why you need the 1k resistance in the first place.
Also, why have you not placed the capacitor closer to the power supply? It seems to me that the way you have done it, the current will be flowing in the opposite direction while bouncing. Isn't that a problem?
Hi Yad - I believe the 1K resistor is in the circuit to hold the interrupt pin at ground level when the switch is open, and to provide a path for the capacitor to discharge following a switch closure/opening cycle. Also, the input impedance of the pin is likely high enough that charge cannot bleed off via that path.
What's meant by switch bouncing??
I believe I explain it in the video. It is a phenomenon with mechanical switches that when they close fast they will go back and forth from closing and opening due to the force of closing this is called "switch bounce" and it happens in milli or micro seconds so a human does not notice but a MCU will.
@@ForceTronics What is a MCU? :D
Why debounce in hardware when you can debounce in software with like 6 lines of code? (or just use ready made library if you are using arduino)
interrupts on button presses can't do this