Arduino Tutorial 34: Simplest Way to Use a Pushbutton Switch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Palma quarter from top tech boy comm and we are here today with lesson number 34 in our legendary new and improved Arduino tutorial series and what we're going to learn today is we're gonna learn a quick hack that will allow you to put a button a push button into an Arduino project the simplest possible way in videos 27 28 and 29 in this series I talked to you about using a push button and showed you the old-school theory about you know having to put in an external pull-up resistor connected to five volts or a pulldown resistor connected to ground and how to do it did some projects got it all working but I'm gonna show you a quick and dirty way to do that same thing without having to use any external resistors and let's move me out of the way and so for this project you will need your push button from your handy a Lego super starter kit okay if you don't have one yet click the link down in the description 35 bucks you get all the parts that we use in this series also of course you will need some coffee that's coffee towards the end of the day it is gone so my video making will come to an end today because I'm out of coffee coffee is the elixir that fuels this creative genius that you know as top tech boy calm alright so to do this switch let me zoom in some and then of course we are going to have to wait for this thing to focus which it takes a little while but I got a new document camera and the problem is it takes a little while to focus but it does give a much better image than my old one alright hooking this thing up we're going to show you how to do this without having to use any external pull-up or pulldown resistors the main thing on this switch is do you see these leads that are pointing towards each other it's like they're curved towards each other those leads that are curved towards each other are already hooked together so they need to go in a common column because the columns are hooked together so if you put those that are curved together in a common column then these other pins and these these oligo switches fit into a breadboard better than most but they still require a little bit of fussing with them to get them to go alright so I now have the switch in there and the push button and I will come from one pin all right and I will go to pin 2 I cannot I am going to zoom out a little bit so you can see both things that I'm doing we will allow it to focus and I lied I've got a zoom out a little bit more okay if I had a producer you know this would be so much easier but it is just me working here okay so you can see that I go from one leg of the switch to pin 2 and then of course the other leg of the button we will go to ground alright no magic no pull up no pulldown resistor ok this is the way that you make it work in the code so let me come over here to the code view which I think let's see no that's not very that's that's kind of a lame shot there let me come to this one okay yeah I really don't like that one either let me come to this one alright this is a great view and if I had been more professional I would have taken out this nonsense before its start with an empty one okay but you can kind of figure out I practice this before I do the video so I've already written the program 1 so how do we use this button as a push button on our project well what we start with is I need that thing to go down in there I think I am sorry I've got to get these pins where it goes down in there really good or I'm going to drive myself crazy fearing that it is not going to work so let me get that plugged in where it really stays all the way down there aha that is in there good now okay so what do we need for a push button well we need a we need a int and let's just call it but pin the pin no let's call it button button in and that is in where that's in pin 2 as we said and let's go int and then I'm gonna need a button value button value and I'm not going to put anything in there because that is going to be what I'm going to read now this is where the magic is going to happen I am going to do a pen mode pin mode of button in and I'm going to do as you could imagine input no surprises there right no surprises there because I'm going to be reading from it here is where the magic happens digital right ok I am writing to an input pin what kind of insanity is that ok so I'm going to digital write to a button pin and what am I going to make it high so think about what this is doing doing the pin motive as an input on bringing internally on that chip I'm bringing internally into the circuit a pull-up resistor and so the pull-up resistor is there because I declare it as an input and then if I write that input pin high that connects it to 5 volts and so now I have like a pull-up situation where it should in its nominal state be sitting there reading a 1 and then when I press the button that'll connect it directly to ground and I'll read a zero so I will have a very very stable operation but taking advantage of the internal pull-up resistor and not having to furnish one myself if all goes according to plan so I do a digital right button pin hi now what do I do I do a into button value I will do digital read of what I'm going to read from button pin as such and then I'm going to do a serial dot println and what I like to put a little formatting so I'm going to say in quotes makes it a string your butt is like that and now I will do a serial dot in in and then I will print but a value which I just read okay and then let's put a little bit of a delay in their delay DT for delay time I will have to come back up here and declare that int delay time equals 100 milliseconds I like that alright let's download this and then let's see what happens hold your breath oh my goodness used a colon instead of a semicolon hopefully you were yelling at me all right hold rip limit downloaded okay downloaded but we don't know if it worked so we need to go to a slightly different view here is this a good view I need to open the serial monitor so you can see it okay ah what is wrong what did we forget we got to do our serial dot B again 9600 all right so here we are going to download this time with the serial monitor turned on okay it looks like it downloaded look at that button is one why because the button is not pressed I will get out of your way a little bit more here the button is not pressed now I'm going to put my little finger down there and press the button boom look at that look at that do you see anything indicating non stable operation we have just made a push button without having to plug a resistor into the circuit and it's working very very simply alright guys I like using buttons but they're a small part of a much bigger project and the thing that just kind of annoys me is having to get slowed down by adding that resistor and messing everything up and so this to me is a really big deal to be able to come in and get a button in without having to put a resistor in just doing this this wacky little thing of writing to an input pin alright guys this has been a quick lesson I would love to hear from you guys down below in the comments think about giving us a thumbs up think about subscribing to the channel and I'm not going to give you a secret word this time because I figured people could actually make it through this video because it was just a couple of minutes long okay Palmer quarter from top tech boy comm I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 43,595
Rating: undefined out of 5
Keywords: Pushbutton, Switch, Arduino
Id: ChHNI8yt69g
Channel Id: undefined
Length: 10min 25sec (625 seconds)
Published: Tue Oct 29 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.