Arduino Tut. #7 - Extended - Button De-bouncing explained

preview_player
Показать описание

In the seventh extended tutorial I explain what really happens when the button is bouncing and how it is countered in software and hardware.

The bottom line is that you want to make sure that the transition between low and high voltages has occurred only once during this instance. You can do so by setting a long enough software check which would reset if the pin goes low again or you can use a capacitor which would not completely charge until the button is pressed for a long enough period time.

Keywords & Search Terms:
Button Tutorial
Arduino Button
External Interrupt
Button Pull-up
Button Resistor
Resistance
Capacitor
Button Capacitor
De bouncing
Tutorial for button de bouncing
Рекомендации по теме
Комментарии
Автор

Excellent explanation! n just 10 minutes I understood what I have been trying to figure out for 2 days! Thank you.

armandoscalise
Автор

Being a software engineer where "our world" is always 0 or 1.... and not "maybe".... I need to thank you for making this video explaining something totally new for me (newbie in electronics)  :) keep making this videos.

Dryadwoods
Автор

This is a great Arduino tutorial series, thank you very much!

DrScientistSounds
Автор

Thank you dear, it is easy, clear, and very benificial. I do appreciate your effort.

AbdurrahmanAllahem
Автор

Great tutorial. I have just a suggestion, try to put a resistor in series and a capacitor in parallel to the switch (RC-circuit) so you can control the decaying time of the capacitor discharge by TAU=1/RC. And let see the de-bounce time is 1us, then insert it in the formula(instead of TAU) and chose an arbitrary resistor value lets say 1Kohm and calculated the corresponding capacitor value you need to remove/filter the bouncing time.  in other words the RC circuit will let your signal through until the transient (de-bounce) period is over. Keep up your great work

chakirelyattafti
Автор

I'm working with IR sensors modules which come with a transmitter and a receiver at the same breakout board. So, I'm working with different configurations. First one is counting people who are entering and exiting a building and this one need an accurate triggering, I solved the bouncing problem with 1uF electrolytic capacitor. But the problem is that the microcontroller reads the person more than one time in one go which of course is a problem for the counting process. Another configuration is to catch a moving car whether is exceeding the speed limit or not.

PerchEagle
Автор

You are partly correct then you are talking about the threshold values of 0.8V and 4.2V.

First: It has nothing to do with Arduino. It depends on the chip you are using on the Arduino board. For example an Arduino UNO uses ATMEGA328P as microcontroller.

Second: The threshold values you are giving is NOT threshold values. Between those two values you do not know if the chip will interpret the signal as HIGH or LOW. That is CMOS fundamental and depends on the process during manufacturing. So why do they write those numbers in the datasheet? That is _guaranteed_ values! The next batch of microcontroller will have a different voltage they will have as threshold. It might not differ much, but it will differ.

How can one know what the threshold is? That is quite easy. Make a voltage divider by one fix resistor (10k is a reasonable value) connected to ground or power supply and variable resistor (100k is a reasonable value) connected to the other (power supply or ground). Then turn the varistor (variable resistor) to the point there the chip says, "hey now the input has toggled" and measure the voltage at the pin (in the middle of the voltage divider). Repeat for the same chip and you will get the same result.

How to test then the chip has recognised a toggle on the pin? Something like this
void loop() {
if(digitalRead(<pin name to read>) digitalWrite(<pin name to write>, HIGH);
else digitalWrite(<pin name>, LOW);
}

If you connect <pin name to write>, to a LED and series resistance (maybe use one of those already inbuilt on the board you are using).

embeddedhenrik
Автор

Great explanation! Which solution is more common? Via software or hardware?

rogernevez
Автор

Thanks for nice video. So what's optimum value for capacitor to prevent de-bouncing for a button ?

onurolce