Arduino Tut. #7 - Button De-bouncing - Software & Hardware

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
how's it going guys welcome to the seventh argument tutorial in which we're going to discuss what are the basic concepts that I wanted to discuss a long time ago but never got around to it so that would be button debouncing so as you can see I have a small setup where I have two LEDs on the bread board along with a button which is used to toggle the LEDs and currently there is no button debouncing present and my software or hardware as you can see if I if I keep just pressing the button you would see the LEDs blinking sometimes so I'm going to discuss the concept of the whole button debouncing and what's happening exactly in a separate video but I actually wanted to show you what is actually happening in the hardware so as you can see sometimes I press and the LEDs quickly blink and they don't just saw as you would expect them to so let's take a look at the code what which I have right now and see how we can first of all debounce and software and then I'm also going to explain how you can debounce in hardware so stay tuned alright so they can look at the sketch that I have currently uploaded in on the Arduino as you can see I have a button and two LEDs declared I also have a boolean for to keep the state of the button and I have a toggle which is also a boolean I'm going to explain that in a second what it does in the setup function I have two LEDs as output one button as an input and arbitrarily I have declared two LEDs one high one low just for starting purposes and the loop as you can see I write a digital read of the button high and if that is the case I'm going to say that the button is pressed that is set to true otherwise it is false and the toggle is false so what this creates is a situation where I can actually check if the button has been pressed once or it has been just held down and what that basically means is that if I just hold my finger on the button I'm not going to just keep on toggling the LEDs during that process I'm only going to toggle at once so once again because of that issue I have to check for if the button is pressed is true and the toggle is currently false so that means that the toggle has not been executed yet so it if it has not been executed I execute it once so I set it to true and I execute the function toggle which is basically setting LED LEDs to the opposite of the of what they currently are so in order to make this fukin debounce able I'm going to actually go ahead and add a condition so I'm going to add an int bounce which is which I'm going to set to zero for now I'm going to change this button is pressed true because I'm going to add a condition so if it is high I'm going to simply increment the bounce so we're going to increment the bounce we're also going to say that the bounce is going to be reset back to zero in case of the button not being pressed anymore or the button going back to low and we are also going to add an if statement so if debounce bigger equal to and I have tested several values for this case so in my case 5000 worked pretty well you can experiment on your own this value is basically going to indicate how long you wait to be certain that the button is actually not bouncing any more so you may set this to something lower it depends on your on many factors notably your button so in this case I am going to say button pressed equals to true and this should be about all we need for button D bouncing so let's check the sketch and upload it and once again this is the value which indicates how long you need to wait before accepting that the button was pressed so just to explain this a little bit you may set this to a lower lower value so for example 500 or even 50 but the lower you set it the less time you give yourself to pick the D bones so preferably you would like to set it as long as you can without having a delay in your button so let's take a look at what our same setup does right now alright so we have our D bouncing implemented so as you can see no matter how hard I try the LEDs are responding perfectly to my button presses you no longer see them flickering here and there so obviously if I if I try and sort of press extremely fast that's only the contact not making um sort of the closure and it's not actually the button bouncing effect so let's take a look at the hardware solution that we can also implement alright so if you have noticed this is my current setup for the button so as you can see the pen is normally pulled down low and once you press the button it goes too high so that's what I'm detecting in my software so what happens is when this contact makes basically when I create this contact with the button it goes high low high low which is the bouncing of the button but if you were to insert a capacitor right here basically you would have a low on this capacitor right so zero volts and when you press the button instead of going up instantly this voltage would actually take time to go to five volts depending on the capacitor value so that is one way that you can debounce the button through hardware so thank you guys for watching these are the two methods which you can use to do bounce your buttons right now so the hardware method as well as the software that I explained in the extended version I would like to touch up on button D bounce and a little bit more and actually explain the concept so take a look at that I'm going to post a link in the description thank you very much if you've enjoyed the video make sure to leave me a comment if you have a question post it down there as well if you feel like you enjoyed the video make sure to subscribe thank you bye
Info
Channel: EEEnthusiast
Views: 34,673
Rating: 4.8541665 out of 5
Keywords: Computer Hardware (Industry), Arduino (Computing Platform), Software (Industry), Button (Invention), Raspberry Pi (Computer), Microcontroller (Computer Processor), De-bouncing, Tutorial (Industry), Teacher (Occupation), Technology (Professional Field), Electrical Engineering (Industry), Electrical Resistivity And Conductivity (Dimension), Electrical Resistance And Conductance (Dimension), Electronics (Field Of Study), Electronic Engineering (Field Of Study)
Id: 4NcfEwm9WBI
Channel Id: undefined
Length: 7min 16sec (436 seconds)
Published: Wed Mar 12 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.