Arduino Tutorial 59: How To Build a Portable Distance Detector With the Ultrasonic Sensor

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is polemic order from top tech boy calm with lesson number 59 in our legendary our new our improved series of Arduino tutorials what we are going to do today is we are going to give you the solution to the homework assignment that we gave you in Lesson 58 where we're going to go in and build a portable distant sensor based on the the HC SRO for ultrasonic sensor this really builds on the work that we did in Lesson number 55 remember in lesson 55 we got the thing working where if it's plugged in you can measure distance and they could get the result back to the serial monitor well what we're going to do today is we're going to take that where we left off in less than 55 and we're going to turn it into a portable unit that we can walk around with now in order to do that like if you look at where we ended up here in lesson if you look at where we ended up in lesson 55 let me see if I can find that that graphic it is right here this is where we ended up we had the ultrasonic sensor and then we had it hooked to the arduino nano i use the nano you guys might have used an no but in this build what we are going to need to do is we're going to need to go beyond that and we need to have a way to power the arduino without being connected to the without being connected to the computer and then we need a display so we're gonna have to add things to it so i'm going to need you to pour yourself an extra-large cup of iced cold coffee and i'm gonna need you to get your equipment put together now everything that we have been doing in this series of lessons has been based on our eleggua kit the super starter kit if you don't have one the link is down below it's got a lot of the wires bread boards in components that you need 35 bucks for a boatload of components and an Arduino alright but as I have been talking to you as we're going to these more complicated builds there's a few more that I'm gonna suggest that you get I think that you need to get one of these larger breadboards linked down in the description to Amazon and then to get a neat build you need to use these straight jumper wires that are pre-cut that just slide right in so you don't end up with this rat's nest you guys know that I'm not trying to just sell you a bunch of junk but if you're going to continue with this you need to have a nice set of equipment on your workbench and so besides the Lego kit I am recommending this breadboard I'm representing these jumper wires and then I am recommending that to make cleaner builds you really need to have a good Arduino Nano and I've got a link to one of the official ones down below and if you made it this far in this series of lesson you deserve it you really need to get you Nano now if you just can't do it at all you can do the project with the uno but you are gonna have to run jumpers from the uno to the breadboard and that's going to make it a little harder to to walk around with also on this project you are going to need some way to power all this portably and I think the easiest way to do it at this point is to get a USB power bank one of the things that's used is you know like to charge a cell phone and then you can connect that directly to the usb on the on the Arduino and then the Arduino can power everything so that is what I am suggesting so the first thing that I like to do in a project like this is first thing I like to do is unplug the Arduino because when I'm doing a build like this I don't want to do it while the Arduino is plugged in because if I hook something up longer I make a mistake you know there's a chance you can short something out and either damage a component or you can you know cause it caused a problem with the Arduino and so for this build I think like you could possibly make this fit you know I like to just start by just kind of laying things out impossible fashion so if I move the Arduino all the way over and then I put the display here and then I put the sensor here the ultrasonic sensor you know it just might fit it just might fit now I'm trying to think through this I kind of really wanting to go through this because I feel like that go to this larger board because I feel like there's some things that might surprise me I would still need to put this but I think I could get that like that alright now what I am thinking is I really really really need these pins on the LCD I really need those on the side where the digital pins are and you know darn it it looks like that that could really happen in this configuration so that's lined up right and then I could come on across to the sensor that everything would be lined up here but man that's going to be I would want to move the Arduino as far down here as I could straddling let's see if I maybe this other view would work a little better I know I've got this for you here somewhere there it is okay you see I would want to straddle that Center trench so that I'm not shorting the Arduino pins together but you see I would want it as far possible down so I would leave myself as much build space up here as possible and then down here probably all I would be doing I think would be needing to maybe do a ground down here but not even sure I would need to do that so that you know guys I think I'm gonna try to build it on this single on the single board so I'm gonna go ahead and plug the Nano in okay and now I'm gonna take these other wires out and keep them handy let's see what you do you guys like better that's actually showing up pretty good for right now so we'll go back and forth between the overhead and this webcam view the webcam gives you a really good view but the problem is it's got kind of a wonky autofocus sometimes so now I would also want to give myself as much room as possible with the LCD display and I wouldn't want to put it down here because I don't want to go around a corner with all those digital wires and so I would probably put it like this okay now I've got a nice straight run from the digital pins on the Arduino to all these pins that need to be hooked up let's see here I'm gonna go ahead and leave that jumper in that connects the road to power rail to the bottom row power rail all right and now the sensor I really want to put as far forward as possible because as I put it down lower like if I put it here I really don't want any of those build wires to have the possibility of getting in front of the sensor and so I could put the sensor like here something like that I usually if I can avoid it I don't like things hanging over the edge of the board even though the pins fit I don't like to do that because it's too easy to bump something and knock it off and so I could put it even like right here okay and that would be pretty good but in fact I think what I'm going to do is I'm going to put it forward and you know what I could do I could actually do something like that alright now I'm having to think of what the problem would be if I had it that far forward the problem is that I have to connect to the on the ultrasonic sensor to VCC and ground and if I go all the way up it's gonna I'm not leavin space to jump directly over so what if I did this moving it back okay now I have got room to do the VCC and ground connections but it is going to be tricky no I think you know what I think and then I would still have room to run over the trigger and echo pins the trigger and echo pins I would still have a place to run this is getting a little bit scary my friends this is getting a little bit scary alright now what else do I need to do I've got to get this potentiometer and what if I put the potentiometer like this okay if I put the potentiometer like this I've got to leave room to connect to VCC and ground on the two outside legs and so I don't want to go all the way up into the top but if I'm in the top you see if I go second row from the top the problem is I don't have it doesn't fit you know it's wanting to then plug into the trench you see it doesn't fit like that so unfortunately what I'm going to have to do with this is I'm going to have to straddle the trench I'm going to have to straddle the trench and then that's going to leave me one kind of annoying connection and that connection is going to be from the center tap and that is in there very poorly okay that is now in there square okay I kind of had it in there not in a good way now the only problem that I really have is this centre tap of the potentiometer is going to have to kind of go around a corner to get to where it needs to go on the LCD I guess I could look and see am I really in that last row yeah I'm really in the last row so I'm gonna kind of have a little bit of a challenge and not a really a very neat run to go from here over to here I'll tell you my instincts are telling me that I should go to the bigger breadboard at this point but with a little luck this just might work and I might have like one connection that's kind of a little bit of a challenge running from here over to the over to the LCD okay so let's start hooking this thing up and what I'm going to go to I'm going to go to a crazy view which is probably going to make you mad but I think that you can follow me if we go to this view all right and I do hear Paul you need to get even further out of your way so what you can see is you can see the overhead view way over here in the corner okay and then the view from the webcam right above me and then you can see the two bond outs that we're going to be working to now if you cannot see these vaughn doubts clearly go to the website ww-why are on lesson number 59 and I've got these schematics there and so rather if you're having trouble reading them off of your screen here go to the website get them print them out and then you can have them big in front of you but I will try to use this view so you can sort of see it all at the same at the same time I also will be trying and I know it's annoying but I will be trying to keep this camera focused this webcam does a really good job but sometimes it loses its focus and I'll try to use that little piece of paper to keep it in focus okay did you guys follow I think this might be something that we can do so the first thing that I need to do is I need to look at this and I think that I think that just about everything that I'm going to be doing is on this top side and so I need to go in and just kind of kind of start believe it or not I think I'm going to start with the potentiometer and if I look at the diagram with the LCD you know with a potentiometer that you need the two outside legs one connected to ground and the other connected to the five volts and it doesn't really matter which one is which it's just that Center tap is the important one and so let's start here by oh look at that I just broke I just broke that little wire are the little wire broke I didn't break it but it broke so I want to get VCC to the outside leg of the the outside leg of the potentiometer now I need I'm sorry that's the ground the ground of the the right side of the potentiometer went to ground the left side of the potentiometer is going to go to this is not good you know what happened the way I have it here this leg of the potentiometer is not lined up with a hole and so I just really like to be super neat and super careful with these things and so I'm going to move it over a little bit so that everything will align and work on those pins a little bit and then right like that okay now I will put the right leg of the potentiometer I'm going to take to ground right leg of the potentiometer is going to go to ground and I told you guys this before sometimes these things just do not want to plug in but you don't want to force them what you want to do is you want to kind of jiggle them until they just slide in because if you try to force them it will break the pin okay right leg of the potentiometer is into the ground so what that would leave is now the left leg needs to go to five volts okay the left leg is going to go to five volts and again what I'm trying to do here is get it to slide in smoothly which I just did there okay so you see no that is so nice and neat now I'm gonna have to go ahead and deal with this Center leg of the potentiometer and if I look at that and then I'm going to turn it this way so I'm oriented kind of the same way where the pins are on the bottom as you see over on the corner of the screen I want to get the pins on the LCD pointing down so I'm oriented the same as the schematic and oriented that way what I can see is that the center leg of the potentiometer goes to the third pin from the right so the center leg of the potentiometer needs to go all the way over here to the third pin from the right and this my friend is going to be ugly so it's going to go one two three okay I think that's labeled B zero one two three third from the right and I'm checking this so carefully third from the right is going to go to the center leg of the potentiometer so I'm going to come in and then I'm going to try to kind of tuck this under there because I rarely really really want this wire out the way the good news is this is going to be kind of the the most problematic connection so I'm going to try to just see if I can angle it and then come over here to the center leg of the potentiometer because you see what I'm doing is I'm thinking ahead and I don't want that connection to then get in the way of everything else that I'm gonna have to build see see we go from the one two third leg from the right when the pins are on the bottom and then come over here to the center leg of the potentiometer and that actually came out better than what I had hoped I've been anticipating this to be a problem but you see it actually kind of is out of the way and looks pretty neat alright so let me go back over here to this view the potentiometer gets hooked up now I want to just kind of go in and and take care of some of my bcc's my voltages and my rails my ground rails and so on the Arduino remember when you're building you want all your grounds hooked together and so you wouldn't want to just come in and plug into the Arduino and not have it actually grounded to all the other grounds so I'm going to establish this bottom ground rail which is the bottom row here and I'm going to do that by coming to the ground pin on the Arduino and tying it to that ground rail and it's in effect I'm kind of establishing that as the ground rail now like I say I don't think that I'm gonna have to create a ground rail on the top because that should take care of that I don't think there's anything else in particular here that is going to need to be done and so now I want to probably go ahead and hook up the ultrasonic sensor because it's pretty easy and I'm going to need some warps small wires so I will need a DCC a voltage a five volt and I'm going to need a ground on the ultrasonic sensor so I'm going to come into if you look oriented like this the VCC is on my left so I will come in and it's going to be kind of tricky and you know what I might just pull this out a little bit so that I can get my finger in there and that's going to be to the second row from the bottom so I'm going to just kind of have to toll this out I think because I will not be able to put that in with it in so I'll put that like that so then that takes care of the VCC alright now I need the ground and so I will come in and go from that VCC pin down to the ground and again I do not want to bend this wire by the moth by one so now I know where it is so I'm going to take that out I'm going to just kind of not force it it's not wanting to go down in there and so I just want to kind of jiggle it and guys it's just so tempting to just try to you know try to force it but you don't want to do that because once you get these wires where they're not straight then you fight with them from now on so I'm gonna try to straighten that you want them to come straight down let's skip to this should be that should be it and okay there slipped right in okay now if we come back with the sensor okay that looks pretty good I do need to go back further if I can like that okay I think that war now we've got to get the trigger and we've got to get to echo and if I look at that let's see the ultrasonic sensor wants the trigger to go to 12 in the echo go to 11 and if I look over here it looks like 12 and 11 and 13 now 12 and 11 are already taken so I could take this to pin 13 which is not being used and where it is plan 13 on the nano am I going crazy am I going insane or does the nano not have a pin 13 think the problem is pin 13 maybe if I'm reading this right mine is a little blurry and I'm afraid that pen 13 might be down here on that corner which would not be good so let me go back over to this view and so I don't want to bring it down here so then order my options well it looks like pens two through six are not used and so two through six I could use pen too and I could use pen three so let's see if we have a wire that would be able to help me make that happen and you can see that real quick here a challenge that we're going to have is when you're going to have a lot of stuff running through here so we have to be as neat as careful and neat and careful as possible so I'm going to start with the echo pen and I want to bring the echo pen and it does not quite long enough with this wire to get to and - which is a problem okay so I'm gonna see if there's any way that I can get that because it would sure be nice to have that connection and that is d2 and there is no way it is going to work so I'm going to have to go to something a little bit longer and guys if you're just bored with me we'll just go do go do it on your own but the reason I am stepping through this with you is so you can hear me talk out loud because it can be a challenge it can be a challenge to get these things to work now at this point another possibility would be for me to move this this way or this way to get it to fit and I think I am going to do that because I don't want to I don't want to bend the wires the other thing is I could come this way and use that orange wire okay let's see what the implications would be in guys if you see somebody that just hooks things up perfectly the first time it's because they've already done it you've got to think through this so let's say I said that I was going to use D tube I'm going to kind of try to work up here hi I'm gonna go D - over to here all right and then similarly I'm gonna go D 3 because I needed two digital pins I'm gonna go D 3 now let's see I'm gonna start over I want to start with D 2 with a nice straight wire and take it as far as I can so D 2 will come here and see if we can get that in there otherwise it's gonna have to go like that okay that is going to be the best that we can do okay so then the next one will be D 3 so in case you're wondering what I am trying to do I'm trying to get it where the sensor can be hooked up with relatively straight wires and then still leave myself build room down here then what we also know is if we look at the sensor that when I have it like this I need a ground on the left and so the left pin would need to be a ground which I took out that little wire and I lost it sort of a bit in the one I need to stop losing these little wires because they are precious so the left one on here needs to be ground the left one on the sensor needs to be ground so if I come down like this now you kind of see why it's good to put your ground wires in first and as much as I don't like to do this okay I'm going to do it like that so now the left one is ground and I need to make the right one five volts like that alright so now let's look at this the left the left is ground which it's supposed to be then I have echo and then I have trig and then I have VCC so that looks right so if I plug this back in now I think with a little luck that will be hooked up okay what I don't like is that wire is kind of keeping me I need to go one more back I think like that okay so now I have this as far back as possible and I think I've got this thing hooked up and the only thing I don't like is this orange wire is running on top of this ground wire I can't really move the ground wire so I just got to make sure that that stays securely plugged in all right this is kind of interesting and I think I might have this hooked up now so I'm going to go ahead and plug in and you see this is such a complicated bill before I do anything else I want to see if we have that ultrasonic sensor working so I'm going to plug the Arduino and good news is I kind of got the happy little sound so I don't think that I shorted anything out and so then let's go over here to a code view like this okay and now this I believe was I believe this was where we left off in lesson number 55 so you can go to fit lesson 55 and you can get this code okay you can go to lesson 55 and you can get this code let's see you want to make sure that I have a good view give me just a second to sort through all these views this is probably a pretty reasonable code view okay now what changed though my echo and my trigger pin change so here the trigger pin is now pin 2 so I've got to come to my code and my trigger pin is pin 2 now my echo pin my echo pin is I think these wires crossed I've got to be very very careful the trigger pin is that one you know what we didn't do we should have written it down as we put it in this one is the trigger pin and the trigger pin is in fact d2 and then the echo pen is pen three all right man this is so tedious but if you try to do this just by using a bunch of Luthi a bunch of loopy jumper wires you're gonna have some problems okay and then we come in again this is pretty straightforward we set up the ping we send it we've done all the math already and so I think we are ready to download this and what we want to see is if our basic distance sensor works I need you to hold your breath Oh denied what is it not like it might it might not like having a serial monitor already open so let's see try it again [Music] hey looks like it downloaded but now what we need to do is we need to look and see if we can see that serial monitor and okay and I seem to be getting a very spurious result here can I make it where you can see the serial monitor okay give me just a second to edit this shot so that you can see it this is one of the very annoying things it sometimes doesn't like to have to arduino windows so it gets loses track of which is which okay I believe that you can see that now and so what you see is is that I'm measuring zero so something is not working so let's look and let's come back over here and let's look and see what it is VCC is definitely to five volts but nothing is creating VCC so you see the problem is there is nothing that is turning the sensor on because I don't have this power rail ro - I didn't establish it and so I've got to find the five volts on the Arduino and as luck would have it the five volts is on the opposite side so I can't drop a rail right up there but the good news is I've jumpered the bottom plus to the positive plus so if i hook this one up here i should be good to go so let's see what happens here I'm going to come and I will make sure it's got to go to the bottom row so I will come in here and I will go there to five volts and then I will come in and it slips right in okay boom all the sudden I am getting measurements okay so the problem was that I was thinking maybe we confused that echo and trigger right because we were getting a little confused there but in trying to see what was connected to what but now boom look at this okay so this is looking pretty good okay so the sensor is working and that's a huge huge step so now and the reason that's giving you strange numbers is because there's not a target if we put a target there it works alright now what do we have to do we have to hook up the LCD and this is something that we have to be super super duper uber careful with because the LCD has a lot of connections and it's easy to get confused so I'm gonna go to a view that will show you like this we've got the ultrasonic sensor hooked up and now we've got to look over in the corner on how to get the LCD hooked up and I think what you need to do is you need to get some view you need to get where you can see that schematic if you can call it up from the website that would be great but you need to get somewhere where you can see that big I'm looking for like here you see you can see it big but the problem is if I use this view if I use this shot then you're not going to be able to see my hands and you're not going to be able to see the build and so therefore you need to go to the website and either print it out but you got to have it some way that it is in front of you big this would be another possibility but I think I would rather you see the two the two angles on the on the build okay so let's look and we're looking and now what I need to do is if you look at that schematic the pins are on the bottom and so I need to move it like this so that I am oriented pins on the bottom just like if you look in the corner on the schematic the pins on the LCD or on the bottom in that I think we really really really need to do and so now we need to begin to hook things up we've got the one connection I'm going to unplug this from power as well as we're doing this we've got the one connection already from the potentiometer to the third pin from the right now the rightmost pin is ground and then the second to the right is power and so we ought to go ahead and take care of that I would think so I'm gonna get a couple of these small little bitty jumpers and get that taken care of how are the thing up to begin with okay on the right is ground okay on the right is ground so I need to kind of move these out of the way and then unfortunately I'm not lined up perfectly I've got one of these that's has a blank spot right there but I can go over one and get it in there and that goes right in okay now the second pin from the right on the LCD wants to go to five volts okay so I've got one two three I've got the first three pins hooked up the fourth pin let's see and then the fifth pin the fifth pin also the fifth pin also is going to be a ground so one two three four fifth pin on the LCD the fifth pin from the right also wants to be a ground and I can kind of okay so I'm going to check that and man this is where you have to check over and over I look at the schematic one two three four five is a ground and then I come here one two three four one two three four five goes to ground I believe that's right now we need to go back and look at four one two three four from the right or from the right goes to pin seven so here is where things get dicey I go one two three four from the right wants to go to ten seven and I am just way way way too long for that so our faint hope is that one of these shorter wires would work so I go one two three four five is going to go to still too long you can see why it really really really helps to have a nice set of these and I said of these wires that come in a nice different array of sizes let's try this one so we're going to come the other thing you can do which really we're probably at the point is to buy a roll of this wire and get some diagonal cutters so that you can make them exactly the size you need so let's go again one two three four the fourth one from the right goes to ten seven so I'm going to go one two three fourth one from the right doesn't quite go to pin 7 and pretty soon we are getting to the point that we will need to just bend the wire around to make it work one two three four wants to go to ten seven and then it's going to go let me start at the other end maybe and so if I go all the way to the other end we're going to have some fun and so the leftmost pin the leftmost pin is going to want to be a ground and so if I'm going to make that leftmost pin a ground what am I going to need to do is take this sensor out for a minute so that I have some room to work so leftmost pin on the LCC LCD is going to go to ground so leftmost pin on the LCD will go to ground okay and now second pin from the left wants to go to power wants to go to five volts so second pin goes to five volts and I'm resisting the temptation of jamming this thing down there okay so I have the left pin hooked up I've got the second pin from the left hooked up and now the third pin from the left wants to go to 12 the third pin from the left wants to go to pin 12 needs to be longer third pin from the left needs to be longer trying to kind of get different sizes out here to work with so I'm probably going to have to like use a yellow one so third pin from the left one one two three third pin from the left wants to go all the way to ten twelve which I'm going to have to accomplish by looping back okay and then okay do you see how I went back there lets you give you a focus here okay you see I had to kind of limp back but then I'm also trying to keep this wire nice and out of the way so now I've got on the left one the second one from the left and the third one from the left hooked up one two three the fourth one from the left is going to want to go to 11 and so I think I'm just going to have to continue to make these little looped back wires like this and it is going to get kind of ugly but I'm going to try to get it in there like that and then again I will need to make a loop back but I want to do the loops where I'm keeping this wire as straight as possible so that is going to go to 11 okay and now I want to take that slack out like that you see how that's still staying relatively neat and so that was the 1 2 3 4 from the left 1 2 3 4 from the left went to 10 11 okay and so we're going to have the same type of thing the nice thing is they kind of begin to go in order and so if you can try to keep things in order like that there's a lot of different ways this LCD can be hooked up but when you them across in the same order that the pins are it kind of helps a little bit so now I'm going to try to come back up to that right by the LCD and see if I can get that in okay and now that one which is the one two three four fifth from the left one two three four fifth from the left wants to go to pin ten now so I will need to I'm going to see if one of these other ones would fit in at this point because the things are coming towards each other and yes they will and in fact I think this is pin ten now I'm going to go maybe I won't have to use this okay now that is going to want to come back to ten okay so that's pin ten and now I have one two three now the next one is going to go to pin 9 so one two three four five six from the left wants to go to pin nine and so one two three four five and I am off I won on that I need to put that one back in I'm just going to have to come down here like that and then that wanted to go to the pen so you see you've got to keep checking your work because it's a lot easier to correct something right after you put it in then when you have more wires on top of it because as this thing continues to build it becomes harder and harder to debug so that was pin ten now what I know is one two three four five six from the left needs to go to pin nine so six from the left needs to go to pen nine and then let's see where six from the left is one two three four five six from the left check and screw right in there and that will come back and check this and I'm just going to look and see if by some chance a shorter wire would work not even close so this one two is going to have to loop back and this will be married so ten nine and then draw it in there tight and kind of loop it back like that this is really getting to be a mess here and I don't like that but since I don't have diagonal cutters I really don't have a good solution so now we need to skip the next four and then we no need to go to pen eight so I need to skip I probably I'm going to start working from the right again okay I'm gonna start working from the right again so the next thing I need to do is from the right one two three four okay one two three four from the right needs to go to pen seven so pin 7 pin seven is going to go to one two three four from the right needs to go to and seven I just really am always hoping I'll find a wire that will do this one two three four it's that kind of naked denied okay so one two three four it's going to go to pin seven so I will have to make one of my famous little loops there and then bring it up here like this okay so that looks pretty good this is turning out to be a little bit of a nightmare and so I've gone seven and now I have the ground and now I need to I have another ground here okay so there's one more ground that we need to put in okay so let's look at this we have one two three four fifth over from the right should be a ground one two three one two three four fifth over is a ground and then we go to maybe I am NOT missing their ground okay - we have picked we have hooked up pin 7 and pin 7 goes one two three four from the right one two three four from the right is pin 7 4 from the right is pin 7 and then the next one is the ground and then the next one needs to go to pin 8 so the next one okay I am just going to check this man because I got to be so careful first one on the right goes to ground next one on the right goes to five volts third one goes to the potentiometer fourth one one two three four goes to pin 7 v 1 v 1 is a ground and that's right and now the next one is going to pin 8 next one goes to pin 8 needs a little longer wire so the next one goes to pin 8 I will need to bend it ok now I skip let me just see I just want to check so after pin 8 I should skip 1 2 3 4 and then I should be making connections again so I skip 1 2 3 4 and then I have a connection which goes to pin 9 ok that looks like it's hooked up right name that was TD straight tedious but I think I've got it all hooked up now I'm gonna go ahead and be brave and I'm gonna plug it in and let's see what happens what I want to hear is the happy little noise and maybe some sign of life got the happy little noise and I've got some signs of life on the LCD the screen came on so that's pretty good guys before we go in and program before we go in and program up the printing the distance what I really want to do is I want to just do a hello world on the LCD what do we know at this point what we know is that we are getting good distance measurements right we know that we are getting good distance measurements I think so is this working okay ah what did I forget to do why am I not getting good distance measurements because I didn't plug this back in now we know this is all in the right place but we had to kind of take it off in order to we had to take it off in order to give our little fingers room to put these wires in and so we need to plug this back in most carefully and I think I need to go further back like that okay now what do I not like about this those wires have kind of got this thing now so I want to plug it in where the wires are not keeping this from plugging in all the way okay and that is going to be like that okay that is pretty good and now are we getting any type of measurement let's see hit the reset button this thing still was not coming to life okay so this was working earlier but now is not the good news is I did not see any smoke coming out of any of this okay let's see if we download this program again if we can get something to come to life that doesn't like that when the serial monitor is on I'm trying to download the program again and see if I can give you a few here all right I got it downloaded now let's come up here see if the sensor okay at least I'm getting some readings off the sensor and they are starting to look good okay so we got the sensor plugged back in and now if I come over here to this view again I'm sorry but when I kill the serial monitor it's like the Arduino is kind of fighting with my broadcast software so I've got to fix this where you can see it again so give me just a second here to configure this so that you are actually seeing serial monitor okay this will fix it okay so do you see now that I am getting measurements that are looking good all right so that is good news that is good news so now what we need to do is we need to see if we can get a hello world up here so I need to take you back to a good code view and let's see I wonder if all that one is not live could we see let me just check one thing here sorry sorry sorry okay it was a good view here I believe I should be able to get the view here with a little luck I have it and then not make that smaller I want you to be able to see what my hands are doing I want you to see the serial monitor and the code view all at the same time which I think maybe we've accomplished with this view alright so that is looking good and so now let's come back over here and let's see if we can get a code view going alright so what do we want to do we want to make our LCD say hello world so we're going to have to set up the LCD now in software and let me remind you of where we did this kind of thing in our lessons so if you haven't done this before you can go back to our LCD which was connecting and using the LCD Arduino Arduino tutorial 48 you can see it on this channel on this playlist or you can go to top tech boy calm and find Arduino tutorial 48 and I show you the coding on this but let's go ahead you can follow along with me here we are going to first have to set up our library so I think liquid crystal is one of the libraries that is already on there if there's any confusion go back and look at that lesson and it shows you include alright we want liquid crystal dot H what are we doing we are loading the liquid crystal library remember on library loads you don't put a semicolon now how did we hook this up we hooked our s to pin 7 RS on the LCD went to pin 7 int e in went to pin 8 int D for what depend on I'll tell you guys this LCD project is the project that makes it separates the men from the boys or the women from the little girls because it's the project that if a student isn't careful they just can't do it and this is kind of the make-or-break things for students in the engineering program but the good thing is it teaches you to be careful and methodical and even if you don't become an engineer you become a nurse well you've learned to think clearly and be careful and precise good characteristics for people in the medical profession so no matter what you're planning on doing I think it's good to learn to work carefully as I forget to put equals 10 on that all right so d5 is equal to 10 in d6 we hit hooked up to pin 11 okay int d7 we hooked to pin 12 all right that looks good now we have to set up we have to create the liquid crystal objects so we're going to use the library liquid crystal turns the happy little orange color we're going to call it our LCD that's our object and then the order is our s e in d4 d5 d6 d7 okay now you could have just come in here and put 7 8 9 10 11 12 and that would have worked but it's better to use variables because if we have a problem we can go in and check things then okay so we created the object then down in our void setup we need to begin our LCD so we're going to do an LCD dot B again LCD dot begin and then this is sixteen columns by two rows the LCD that we're using and so that starts that that looks good now in the void loop okay we make our measurement and do our calculations and we can still print it to the serial monitor that's okay but what we need to do is we need to LCD dot set cursor happy little orange color and we're going to set the color that's cursor to column zero row zero and then we're going to do a LCD dot print and we're going to say hello world and then we are going to do a delay so that you can see it and then we are going to do a LCD dot clear you always want to clear it so if you get something you don't end up with garbage from the last print and now we just got to make sure delay time should be longer here like maybe a hundred let's say okay let's download this and see what happens oh LCD clear I think needs to have the open close parenthesis hold your breath downloaded okay downloaded and are we getting anything here we uh we are getting a hello world we will turn it around boom look at that hello world aha did you see that we hooked it up right the Jews work I hope yours worked as well if you were as careful as I was it probably would because man this is a booger bear to try to find an error when you've got all these wires so so let's look here let me go back to let me go back to this view and if you look at those wires there man if we had had a problem at this point trying to troubleshoot that is very hard and I told you my intuition was telling me that I really needed to go to a bigger board but we did put it on microphone crash okay we did get it fit on there so that's pretty good now that blanking business it's a little blinking let's work on our delay here a little bit maybe we need to have a little bit longer delay let's put it at like 500 because it's a little bit blinky there I'm sorry you guys are not seeing that you need you need this view here okay so let's come over here let's make this 500 that's half a second and maybe I would get a little less jitter in that okay that looks a lot better so I think now I can bring you back to this view okay now why is it reading 18 inches because I don't have a target in front of it okay and I want to make sure all my connections are super good okay look at that so what is the super cool thing here a super cool thing here is I want to get that just right and I'm checking all of my connections and that one you know you know okay so that looks good I want to see what happened if I take that LCD clear out I've got several delays in here so I just want to see if I take the LCD clear out need to give you back your view I took the LCD clear out and now I'm going to download it okay that looks pretty good there for some reason I was getting it kind of blinky while ago and I didn't like how it was blinking and it made me think maybe I had a bad connection but okay now we don't want to print hello world let's see if I can get a better view will this one work here okay yeah I think that one will work so now let's see if we can really print something and so let's see if I could print here instead of hello world what if I said target distance do you think that will fit I bet it doesn't but we can correct it if it doesn't target distance now I'm going to do an LCD dot print and then in that earlier lesson what was the variable this distance to target as such okay but where do I want to put that I can't put that on that same row I better do an LCD dot set cursor cursor and I still want to be where I want to be row I want to be column zero again it starts with column which is kind of backwards for a math teacher and then I want it to be Row one like that and then I want to print distance to target all right and then what I will do up here is I will actually give you a target and then let's see if we can download this and see what it was downloading hey hey look at this hard do you see this do you see this distance to target target distance 1.7 inches 2 inches look at that boom Shakalaka uh-huh yeah boom did you see that look at that let's give you the more dramatic view is this the more dramatic view oh look at that I'll put a target there so I can see it oh look at that ah come on focus you're you're messing me up here mr. webcam this webcam gives you a pretty nice view but then it's got a real wonky autofocus which there okay now look at that so let's put a target here and then oh my beautiful look at how neat this build is now we just ran into some difficulty here the solution is is to but get a roll of wire we need to probably do that and get some diagonal cutters and start making the things exactly the right size all right what's the one thing that we should probably do if we come back over here to where you can see the code will this work that is not very nice let's come back over here to our good Old Faithful here we probably want to put units and so then let's do LCD dot print and then let's do space inches space inches okay and do that and then let's see what happens now here we might have a problem if we don't do an LCD clear so let's go ahead and download this that is going to download we might have to go back and put an LCD clear in it so let's look at this and see what happens okay that looks good but let's say if I go to something really big and then come back do you see how that messed it up because now the inches scoots over and you have that trailing S on it as I feared so let's see if we go back and after the delay if we put an LCD dot clear this was giving it a little bit of a blinky business before so okay I'm sorry you didn't see that what I did was right here after the delay I put in the I put in the LCD clear so let's come back over here to this view and what I'm hoping now is I'm hoping that we don't get it okay that okay I am not getting a lot of problems there okay now if you just let it go that blink is because it's looking for a pulse that it never got back and so there's a delay after the clear and so that all right man look at that okay are we done oh we are not done what have we not done we have not gone portable and so what you need is you need like this USB power supply this USB power bank and so what I'm going to do I'm going to unplug from the computer okay I'm going to unplug from the computer and so do you see now that we are completely untethered that this thing isn't connected to anything so I think I can come back up here and what I can do is I can get the power bank and then I can plug it in like this and then look at that we are completely mobile we are completely mobile so then let's look I yes I do need to put it back over here alright and that little bit of blink is because it's looking for a ping that it's not getting and it's after the clear and so that is pretty straightforward right so we hopefully you believe we we are completely mobile at this point and then if I put a target here we're getting nice glitch free operation if it goes to a long distance and then it comes back you're still getting a good reading oh man and look at this is this not a nice-looking portable portable system now if this was in the real world I would find a much shorter cord to power this thing with and so still the power is something that you got to think about a little bit but man that is really slick okay did anybody do this along with me did anybody play along at home you guys give me a comment down below and let me know did anybody actually do this first of all was anybody able to do it on their own was anybody able to do it on their own and if you were did you do it the way I did it did you end up with something like this can you see man if you try to do this with the uno and you were running all of these wires with these loopy wires you probably would have really really run into something that if you got it to work it's probably very glitchy and so if you guys haven't done it already get yourself a nano and get you some of these straight jumper wires I've bent up so many of these jumper wires I'm gonna have to like buy me another kit because I've really messed up a lot of those a lot of those wires and so I am just SuperDuper happy with this thing I'm super duper happy with the way it came out would love to hear your comments down below did you get it working on your own did you get it working after you did it with me what were your problems did you do it the way I did did you do it something some other way did you just fold up like a cheap lawn chair and go back to playing silly video games or did you run from crying like a little child or did you actually get this done you see when you start getting to this level of a project it's not that it's just that hard but you just have to be so careful and so precise and you have to focus particularly as we were running those wires on the LCD so I would love to hear your comments down below all right we are going to let's see what else do we have coming up here we have a port we did the homework we made a portable distance sensor I need to give you your homework for next week all right your homework for next week is keep this thing put together but do you see this thing is like making measurements when I don't want it to and then it gives erroneous measurements and so what I want is I want this thing to sit here and I wanted to have a push button and I want you to only make a measurement when you push the button okay I only want you to make a measurement when you push the button so you push the button it runs off and makes a measurement and that way it's not just sitting there and kind of getting wonky things going on so the assignment for the next lesson and I'll go over it in less than 60 the assignment is to go away and add a push button switch where you push the button and it makes a measurement okay palma quarter from top tech boy comm enjoying coffee after a successful build I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 23,398
Rating: undefined out of 5
Keywords: HC-SR04, Ultrasonic Sensor, Measure Distance, Arduino
Id: cEuzEPJnb5s
Channel Id: undefined
Length: 79min 44sec (4784 seconds)
Published: Tue Apr 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.