Arduino Tutorial 66: Controlling DC Motor, Speed and Direction with a Remote

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 66 in our epic our legendary new series of Arduino tutorials I will need you today to pour yourself a nice huge mug of iced coffee I will need you to get out your most excellent Lego kit if you don't have one there's a link down below you know the series of tutorials is using components from this kit and if we're using the identical hardware it really makes life a lot easier what we're gonna do in today's lesson is in lesson number 65 I gave you a homework assignment and that homework assignment was to create a remote-controlled fan okay and leave a comment down below and let me know if you were able to do this homework on your own it's sort of like I didn't try at all I tried but I could not do it I tried and I was successful or I was tried and I had some problems but now I understand it after kind of going through it with you but what I hope you guys will start doing is I hope that you guys will start being able to do more of these on your own because if you remember in lesson 65 which I think I can get you to right here on top tech boy comm and lesson number 65 I left you with a working remote control and that's kind of where we left things off and you can see up here a working remote and then also if you remember I believe it was in Lesson number 37 we got you going with a an Arduino controlled motor and so if you kind of think you did 65 you got the remote working you did less than 37 and you got the motor working and so really we're kind of bringing together two things that we already understand and sometimes that's a little harder than it sounds but I hope you guys were successful in doing that what will you need for today's build well I will be using the Arduino Nano now I know that the Lego kit comes with the Arduino Uno but as we start getting to these more complicated builds I really like going to the Nano link down below if you guys don't have a nano yet pick one up because that is what we are going to be doing let's see if we can get our focus back okay there we go this Arduino Nano is what I'm going to be using for a lot of the more advanced lessons just because it's so much easier to get a clean build also there's a link down below for some of these straight jumper wires which allow us to make these nice neat connections and not end up with the rat nests that we end up with when we try to use these male-to-male jumper wires and so what you're going to need is you're going to need to get out your Nano you need the remote control receiver unit from lesson number 65 you need the l293d motor controller remember this looks a lot like the serial register there's two components in your kit make sure that you get the motor controller l293d visual confirmation that you see those letters on it before you plug it in you would not want to try to run a motor with a shift register and then you need your power supply okay and you need your motor with the fan and you can get these things out of your kit okay so let's see let's come in and just make sure where we left off in Lesson number 65 we left you and let's see if I can call this up or I can see it well okay we left you with this program and again if you haven't done less than 65 yet you really need to go back and see less than 65 and so with the remote control what we did was we map the buttons to commands in the arduino so i'm gonna press 0 I get 0 also notice when I press the button when you look down here you see that it receives the signal and then of course I lose my focus because I put my finger in there I am really gonna try to I'm sorry you guys this is slowing you down but I really want you to be able to see clearly so I've got to kind of help it with the focus okay now notice when I press the button one you'll see the little red light blink okay and then it receives the command one or the power button it receives the command PWR so you can see that from lesson 65 we have you where we can map any one of the buttons on here to a string command and so that's really really good so what do we need to do now we'll we need to hook the motor up and how do we hook the motor up we go back to lesson number 37 and if you go to top tech boy comm lesson number 37 you can see this bond out alright there's a little bit of bookkeeping that I need to do here okay and a little bit of things that we need to adjust before moving on and so I am going to give you a nice big overhead view of our situation and you remember earlier on in lesson number 65 we were running the remote off of the five volts coming off of the arduino and so the way we did that is on the arduino at the 5 volt pin we came and connected that to our power rail and then our power rail on the top we jumper down through this red wire onto the power rail on the second to the bottom row all right now the thing is because we're gonna add a motor we need to add a DC 5 volt supply here so we don't want to be trying to get 5 volts off of the arduino and get 5 volts off of the power supply at the same time and so what we are going to do is we are not going to be jumping the 5 volts off of the arduino so the arduino now is no longer powering the remote and the arduino will not power the motor controller and the arduino will not power the fan what we will do is we will power all of those things from this motor controller now what we will do is we will continue to power the arduino through the USB now i should give warning at this point what I am showing you how to do is safe and effective and won't damage anything for the l293d motor controller running a little DC motor that came with the kit and then powering the remote the motor controller and the motor from this power supply now these things are made to work together but you can't go out and get a huge motor and try to run it off of this little chip or you can't get a motor that's bigger that's suitable for this chip but is more current required than what can be supplied here so I cannot teach you in today's lesson how to get every single motor working with every single motor controller working with every single power supply that is something that if you start moving away from the components I'm showing you you have to look at the wattage ratings of the motor and the motor controller and the DC power supply and you have to then also look at the current draw of the motor the current producing capability of the l293d and how much current the power supply can give so you have to really think about those things so you you can just do what I'm doing here for these components but if you change the components you've got to take all those things into account alright so let's start this build so we disconnected from we've disconnected from the Arduino and therefore we got to make sure that we are powering the remote and the remote is powered through the center pin which is labeled R on this one so I need to get power to R and so I am going to come down and I will let's see I will look at R and I will make sure that it is connected to this lower power rail okay it was and now what I will just have to do is make sure that this is connected to the motor control coming to the power supply alright now one thing that is very very good practice is if you look you can see and hopefully I can get focus you can see that the Pens coming off of this power supply are labeled plus and minus okay you see that plus and minus and this one is over here is plus and minus you want to make sure that these labels match the labels on the rails of the breadboard that you're using now you could do it backwards and as long as you did the bookkeeping you can make it work but if these labels don't match these labels before your build is over it is going to be very likely that you plug the wrong thing in so make your labels match so right now it would be much more natural for me to plug things in this direction and then my power could come from over here but the problem if I do that is then I am not wind up with my labels so I want to do it like this way and then the labels on the pins on the power supply are going to match the labels on the breadboard so I'm going to plug it in like this okay and now I'm going to check I am always going to check these things and what I see here is plus goes to plus minus goes to minus and then down here plus is in plus and minuses and - all right the one other thing that I want to I want to make sure of is that this power supply can put out 3.3 volts or 5 volts you can see that I have the jumper over on the 5 volts on that rail and on here I've got the jumper connected to five volts and if you have it hooked the other way you are going to get 3 volts out 3.3 volts and this whole thing is going to turn into a mess alright so I've got the power supply connected and so now I should be powering the remote and the remote should be powered from this power supply i have not plugged the power supply in yet and in fact even on the arduino I'm going to unplug it because I don't like doing these builds with the Arduino plugged in because if you get something hooked up wrong you can cause some damage so I want to I want to get everything hooked up and then I will come back okay so the remote is connected properly now because I've activated these rails with the power supply so I think on the remote side I think things will be good now we need to go and we need to look at that that pin out and again you can get the pin out for the motor on lesson number 37 Arduino tutorial 37 on top tech boy calm and you can get a nice big one but as I'm building here I'm going to put it up there okay and if you can't see that open up top tech boy comm go to Arduino tutorial number 37 so let's see what I need to do here first thing I want to do is I want to start hooking up the motor controller and so let me uh let me see what I need to do here alright and I am going to try very very hard to keep this in focus and where you can see it and so don't get impatient with me if I take a second to try to get things try to get things focused because I want you to see my build as carefully as possible and if you're aboard with me and you just can't stand this anymore just look at the bond diagram and then skip part of this video and come back as we start as we start coding a little bit later okay so I think what I will start with is I will start with power and ground okay and if you look at the bond diagram up there the pin out what you can see is is that ten eight goes to power and so this is the rightmost pin and so that is one two three four five six seven eight the rightmost pin at the bottom needs to go to five volts and so I'm going to get one of my small jumper wires and I'm going to be very careful and I'm going to put ten eight that's the rightmost pin on the bottom and I'm gonna give that five volts alright so now after I do it I want to check okay I look at the pin out it says that pin eight needs to go to five volts I see that this is 5 volts it goes to pen eight it looks like 10 4 goes to ground so that would be pin 1 2 3 4 1 2 3 4 24 goes to ground and I am going to go back and redo this with a smaller wire I was not paying attention there and so I'm gonna go pin 8 to 5 volts with a small wire and now I'll use the slightly larger wire to go what did we say pin 1 2 3 4 in 1 2 3 4 & 1 2 3 4 will go to the ground okay like that now I'm gonna go back and I'm going to check it it's easier to check as you go so I'm going to put pin 1 2 3 4 10 1 2 3 4 pin 4 goes to ground and that looks pretty darn good I think I can come up to this view and you'll still be able to see what I'm doing alright ok so now I've got power and I've got ground now I need to put set up that speed pin speed pin I believe is pin 1 & Co ok let's see let me check and make sure that that is correct this feed pin is pin 1 here and that pin 1 needs to go to pin 5 on the Arduino so pin 1 on the motor controller needs to go to pin 5 on the Arduino and I believe what that is is I believe that is our speed pin and so let's see I should find a wire that goes naturally okay and I think this one is going to go very very nicely so pin one on the motor controller goes to pin five on the Arduino and you see I've got a nice nice neat connection there okay and you've got some pretty good focus all right what do I have now I have pin two on the motor controller pin to on the motor controller goes to pin four on the Arduino so pin two on the motor controller goes to pin four on the Arduino and you remember that was that direction control that first Direction control that there's two Direction controls and that first one the first Direction control is pin two on the motor controller that goes to pin four on the Arduino you're following along up there okay now I think we need one more and that is pin seven on the motor controller one two three four five six seven seven from the left one from the right seven from the left one from the right that needs to go to pin 3 on the Arduino so I'm going to come here pin 7 and 7 on the motor controller is going to come to pin 3 on the Arduino okay so I believe that I have that connected up so now let's come back up here and let's think all right I've got power and I've got power and I've got this and I've got the motor speed and I've got the two Direction pins and I've got ground and everything set up so I think that is pretty darn good now what we need to do is we need to come in and make sure that we have set up we've got to actually plug the motor in and what I can see is is that the red wire from the motor goes to pin 3 of the motor controller so red wire on the motor goes to pin 3 1 2 3 all right and then the other wire of the motor it looks like is going to go to pin 6 so this is 1 2 3 4 5 6 ok like that so I think that that is hooked up now what I want to do is I want to see if I can kind of get this just to stick down so I can stand it up I've got a little piece of Pookie it's like I'm gonna make a little ring and remember that you don't want to get the motor shaft you don't want to get the motor shaft plug down in the Pookie so I make a little ring and I'm going to put that here like this ok and now hopefully I can plug this down on there without getting any gooey on the shaft because that spinning shaft is sticking out there and you wouldn't want to get anything gooey on that because if you did it would make it not want to run well and these little motors are a little hard to keep running have any of you guys knocked the red or black wire off yet if you haven't it's just a matter of time and you probably will alright so now I believe I have the whole thing set up and so let's go back to this view and now I think that I am going to go ahead and I'm going to plug this in ok and so now I plug that in and now I'm going to turn it on and I would expect nothing to happen ok well I get some happy little lights but I'm kind of worried that my happy little light is staying on let's see I've got red to positive okay I have ground G to ground I've got the Arduino grounded so everything is sharing a common ground and so I do not know where that little light is staying on but I don't like that very much and then the control line on the little module the control line is going to pen nine and that's maybe one thing I should just check and make sure yeah what's like that should be and so I do not know why we are seeing what we're seeing here but let's come back and let's look at the code that we ended up with on lesson number 65 all right so what you can do is you can go back to top tech boy calm and you can get the code so let me let me go to view that would show that so we are going to go back to lesson number 65 and you've got your remote hooked up and now you can get this code and you can put it in your Arduino and then we will come back over here to a code view okay and let's see if you can see everything there all right so let me let me see if the remote still works just with with the other things that we've done here because I'm not real happy with my that little white staying on but I have this code which is the code from lesson number 65 and now we will download that and it is not happy oh oh oh what did we forget we forgot to plug the Arduino back in maybe that would explain some of this alright okay so what do we see now you know how is worried about why the little red light was on look now when we put power back on the Arduino it went off so did you guys catch that that I had not powered the Arduino up with the USB cable okay so now everything has power and so what I want to do is I want you to be looking at the serial monitor okay and I'm going to call that up here let's call it up here okay hopefully hopefully this is going to work and you can see it but now we got a download so I'm going to download it's looking happy okay where are we now we're exactly where we left off in lesson number 65 but we've added the motor the motor controller in the power supply but before I start coding I want to just see I want to see if the remote still works so I'm going to hit the power button and then be watching the serial monitor so I hit power and you cannot see the serial monitor so I apologize let me let me fix that this beyond the scope of what I can really talk about here but it's easy for this to get lost and so I need to fix this really quick for you here okay where you can see what I'm seeing okay now you can see what I am seeing very nice alright so now let's check and make sure the remote is still working so I'm going to press 0 okay and when I press 0 you get a 0 when I press 1 you get a 1 okay so the good news is is that the little remote is still working we've mapped the buttons on the remote to functions in the Arduino and so now what we want to do is we want to start coding and seeing if we can add the motor back in well you can go back and watch them lesson number 37 if you want to know how to get that motor working or you can just kind of follow along here with me and I'm going to move all of this and try to keep you where you can see that focus also watch me code okay so what do we need to do in order to add the motor back in well we've got some more pins that we are going to control and so we need to do those things so let's come down after I'm going to come down after my variables that I did for the remote and now I'm going to put in the variables for the motor well what do we need we have an int and we need speed pin so that's that pin one which connected to pin pin 1 on the motor controller which connected to pin 5 on the Arduino and so we need to tell that that that is pin 5 on the Arduino and remember you're telling it not the pin on the motor controller you're telling it the Arduino pin speed pin on the motor controller is connected to pin 5 on the Arduino then we had those two Direction pins and those were derp one direction one on the motor controller was connected to pin four on the arduino int dirt 2 on the motor controller in dirt 2 on the motor controller was connected to pin 3 I do believe ok pin 3 I do believe alright now we also had the motor speed so we're just going to call that M speed and we're going to set that to 255 full-blast alright that seems to make very good sense now in the void setup we're going to have to do some more pin modes so we're going to leave the two things that we did from the early lesson and we're gonna add some pin modes what pin did we all add we added speed pin and that is an output we will be sending data to it we have pin mode and then we have door one which is an output then we have pen mode door two which is an output okay and I think that's pretty good now what I'm gonna do is I'm going to go ahead and I'm gonna set an initial direction for the motor just to make sure that we we're starting in a known direction so I'm going to say digital right and so I'm gonna say door one is high and digital right door to this low and how many semicolons have I forgotten already this early in the morning looks like I did pretty good up there huh okay so that should have it ready to roll now the first thing it's gonna do is just sit and wait for the IR command and so it's sitting and waiting for you to press a button on the remote and then when you press it it's gonna look at the value and map those complicating hexadecimal values that you get from the remote and change them into more intuitive things like zero one or power or things like that so all that's taken care of now when we get to this point what we're ready to do is we're ready to do something with the motor now before I try to map all these different buttons onto functions I just want to make sure that the motor runs and so what is the simplest way to for me to just turn the motor on so I'm gonna get a command from the remote but at first I'm not going to do anything I just want to make sure that our connections are good so I'm gonna do a digital right and I'm gonna do a door Lo and it doesn't matter during one or two one's got to be high and the others got to be low okay one's got to be high and the other one's got to be low and then if you make it the opposite it will go in the opposite direction since I made derp one high I'll make derp too low okay and now I'm going to say analog analog right what do I want to write to I want to write to speed pin speed pin and I'm going to just set it full on 255 okay 255 all right like that okay and then I think I'll put a delay I don't know did I put a delay up at the top if I put a delay up at the top I don't want to put another one here okay I have a delay up here so I don't think I really want to delay down at the bottom here because I've already got a delay at the top okay so what do we expect to happen when I turn this on well it shouldn't do anything initially because it's gonna be sitting here waiting for some signal from the remote then as soon as it gets any signal from the remote it doesn't matter which one it should just turned the motor on right just trying to see if we have it hooked up before we you know it's kind of like check as you go check as you go on that way you don't end up with something really complicated and if it doesn't work then you don't know you might have wired it up wrong you might have coded it wrong your motor might not be working there's so many things if I can just get the motor to turn on I will know then that my connections are right and then if my connections are right then I can go in and start trying to map different things like do different useful things as I press buttons and so let's hold our breath Oh denied denied what did I oh did you guys see that I said sygyt alright okay please everyone hold your breath this time oh it's gonna Oh [Music] it's taking soul come boom it downloaded English okay so we don't know if it works yet or not but what we are going to do is we are going to see if we can get it to work so what do we expect if I press any button the fan should turn on so just for fun I'm gonna press power and then hopefully over on the digital monitor you will see power it will recognize that I press the PWR button okay so let's try that you see we're ready to go hold your breath okay it saw PWR but de motor did not come on okay the motor did not come on so let's see speed pin that looks good alright so let's see if the motor is hooked up correctly I go one two three four five six motor does look like it's hooked up correctly okay and I'm getting absolutely nothing is this turned on yes that's turned on okay this is peculiar so what am I going to do I'm going to just see if the motor works in the way I'm going to see that is I'm just going to hook the motor into the power supply directly and see if I'm getting power and see if the motor works okay do you see if I just hook this to the not the Arduino power supply you wouldn't want to do that but I'm hooking it just to this little power supply and that does in fact look like it works and so now I'm going to go back up to the motor controller and so I'm going to go to six and ten three okay so let's see oh did you see what I did here I put both of these things low did you guys catch that that could very well be causing that problem there did you guys catch that eh okay one low and one high okay let's try downloading again and let me see if I can get it get a good focus for you well okay that looks pretty good we will download now what we expect is on the download we don't expect anything to happen we are watching and it is downloading downloading okay it has downloaded now I'm gonna press PWR and this time I expect it to come on we turned it on okay that's actually kind of lame because it's just I can't even turn it off right all I could do was just turn it on okay so let's see what would be another thing right let's say let's put an off button in there that would be the next thing to do so what I want to do is I want to start putting if statements in here all right so if it's PWR so if and then let's see the variable that we were using was my command so if my command equal equal the string PWR then what do i want to do i want to do just what i just did i want to turn it on in the forward direction okay get rid of that now let's see if we can turn it off will off would be very similar so I'm going to take all this okay now what is the command that I want when you see that little button that says let's have the off V this this button that says function stop so I need to know what button that does and so I'm going to come over here look at the serial monitor and I'm going to point that I'm going to press that button and see what the command comes out to be and then okay now one thing that I'm noticing is is I press this remote now it is no longer working okay this thing is no longer working so what I suspect has happened is what I suspect has happened is is that we're getting some noise now this is stopped so let me try it again okay I'll try to make real clear what is going on if it's just sitting there and nothing happens this works alright so I'm going to unplug the motor and I'm going to test the remote so if I press PWR I get a P well i press rewind by accident but i'm gonna press PWR okay and I get a PWR if I press function stop I get a function okay if I press zero I get a zero so that is working but look what happens when I plug the motor in it's going to work the first time let me clear the output it's gonna work the first time I'm going to press PWR okay and it gets the PWR and no it doesn't even turn on anymore so let's see what happened there okay it seems like for some reason it's got like a really low speed or it's not wanting to turn on a little concern with my motor here because that I kind of had to help it turn on trying to look and see it's like okay things look pretty good alright so that worked but now watch if I try to turn press the other button now I press the other button and it's not picking it up okay once the motor turns on the remote brakes what could be going on the motor generates a lot of electrical noise okay it generates a lot of electrical noise a lot of static it's like it's almost like a little radio station broadcasting nonsense everywhere and some of these components can be sensitive and then they can't hear what's going on because there's so much noise from the motor running there's kind of two ways that you would do this and really the best way would be to come in and start putting some small capacitors across these motor pins and try to filter out that noise but since the eleggua kid and the things that you bought so far don't have capacitors what I'm going to try to do is I'm going to try to power the remote off of the Arduino rather than powering the remote off of the power supply and I think I could probably get cleaner power for the remote off of the Arduino and not share a power supply and so what would I need to do in order to do that well I need to turn the power off to the remote okay so you see the remote here this one that goes to plus that is the center wire I'm going to take that out and then I'm going to connect that Center wire on the remote Center wire on the remote okay it's labeled R and I'm going to take that around to the positive five voltage on the Arduino okay and I'm gonna try to get that all down in there need for everything is plugged in okay not as neat as I would like but now to just be painfully clear that Center our pin on the remote I did not want to power from the power supply I bring it over to five volts on the Arduino okay and now okay so now the fan turned back on okay so now what I'm going to do is I'm just going to reset it and see if I can turn it on okay so I reset it it's sitting there like we would expect now when I press PWR I expect PWR to come on I expect the motor to come on okay happy little red blink it's all PWR the motor came on so far so good okay now the question is by powering the remote off the Arduino can I get new signals now while the motor is running so I'm going to try the stop button so I press stop and I did not get it let's make sure that is good ground is ground tied to five volts all right let me turn the motor off again turn it back on okay so let's try this again so gonna reset it to stop everything okay you guys understand what we're doing we have a noise problem here and I'm trying to get it worked out I'm trying to get it worked out where I'm powering the remote off of a different power supply the one coming off of the Arduino and then we should see it work all right it got a power signal which I must have accidentally pressed so I'm gonna reset it again okay now I will deliberately press PWR this time okay it's all the PWR and the motor came on now the question is if I hit stop will it see that signal this time and it does not see it okay so this is still moving that wire did not get rid of the noise problem because once the motor works it doesn't work one thing I notice is I have this wire from the motor very close to this power supply wire and so what I want to do is I want to unplug the motor and let me go to a clearer overhead view here okay so I've unplugged the motor I'm gonna kind of twist these leads together because that will suppress a little of the noise you see how I'm gonna try to kind of weave them that can suppress some of the noise again best way to do this is with capacitors okay but now I will plug the red wire back to pin three on the motor controller one two three make sure I get it in the right one and the black one into pin six like that okay so now with my remote okay you got pretty good focus there let me come back and see give you a view where you can see the function coming off of there I think I can make that a little bit a little smaller like that okay and you got focus okay now let's see with it running if I press the function button if you'll see the function come up I'll clear this off okay so press function got function press power got power press function okay so do you see that it wasn't enough to just power the remote off the Arduino I needed to get these wires away from that power wire but it does seem to be working very nicely now and so now let's come in and let's come back to our code view okay this is a pretty good view don't you think so we'll come back to our code view and what we will do is we are going to now add a second if statement so this time and remember I already copied and pasted it so if my comm is equal to fun if you and function what do I want to do I want to set the speed to zero okay I want to set the speed to zero all right so now what do we want to do well we want to be able to change directions so now what I'm going to say here is I've got the like to fast forward and I've got the reverse so let's think of what we could do here I could say if my con equals equals and let's say fast forward what do we want to do there well what we would do is we would say digital right dur one is low digital right dur two is I bring in my semicolons okay and now motor speed we're not going to do anything with motor speed all this is going to do is set the direction and then I'm going to analog write speed in and whatever motor speed is because I'm not going to change motor speed I'm just going to change directions so this is going to stay motor speed okay so fast forward is going to do that well what is reverse going to do okay the rewind button okay you see that that that backwards button that's re v I believe in fact let's see if I can actually read it by pressing it okay re W so if my comm is equal to re W what should I do I don't want to change speed all I want to do is change directions so I would make that right door one time enter too low all right now based on this I should be able to turn it on I should be able to turn it off I should be able to make it go forward I should make it go backwards so let's try that okay starts off what do I want to do I want to press the power button well after I let it download okay press the power button you saw the happy little red light but it turned on okay did you see that now let's see if we can turn it off with the function stop button hello we turn we can turn it on we can turn it off I'm getting a little warm I think I'll turn my fan on boom whoa much too cold I'm gonna turn it off function damn did you see that we got an on/off switch on here okay now let's see if I can change direction so I'm going to turn it on okay and it looks like it's going counterclockwise and if I do fast-forward it stays counterclockwise now let's do rewind it stops and it is indeed going clockwise okay so we have on/off and we have motor direction going now what do we want to do well I think what we want to do is if I go the up if I go the up button I want to make it go faster and if I go the down button I need to go slower so I don't remember when we map those things but I'm gonna I'm gonna look at the UP button okay if I put the UP button it says up if I put the down button if I put the down button it says D in so those are the two things that I want to clue on alright so now what I need to do is I need to do a if my calm if my calm equals equals up what do I want to do I want to change my speed my speed equal my speed plus let's say from 0 to 255 0 to 255 probably it starts running about 120 so I'm going to put like jumps of about each okay and so that should speed it up okay but then what I need to say is I need to make sure if my speed is great if my speed is greater than 255 so if that messes me up and puts me above 255 what do I need to do well I need to say my speed equal to 55 so I just want to make sure that I don't try to write a value greater than 255 so if I'm sitting there hitting that UP button if it takes it about 255 this will take it back to 255 okay so I should have done that I should do it like that all right and similarly okay so that should be all of this nonsense so here we will come and we will do the same thing copy and paste but this time if my comm is equal to D D in my speed would be my speed what minus 15 and if my speed is less than zero then make my speed zero all right now what we need to do is within these we've got to make sure that we do those analogue rights so that we actually put that value in there okay so here we would come and in the if statement we want to go ahead and write that value and then here I want to write that value so now within those if statements when the speed changes you actually write it let's see if this crazy thing is going to work oh what is this nonsense my speed is I'm sure Oh M speed I'm sorry M speed it's my speed I'm speed that should be good so let's download it not did it in two places okay fix that all right it's gonna work this sooo I did it to different places that's a problem with copying and pasted pasting before you have checked your code okay let's try that this was just a how many times did I say that M speed M speed and speed M speed all right okay I guess it wants the conditional inside of a parenthesis because I do so many different programming languages I sometimes forget what different ones want I'm sure it's the same here that in this if statement it wants the conditional inside of parenthesis all right let's try that looks like it's going to be happy this time okay first thing we want to do is we're going to turn it on okay I'm gonna Matt Matt press PWR you should see PWR up here oh I turned it on okay I think you can see it better if I come over here okay now I'm gonna press stop to turn it off function stop okay boom I turned it off you see the commands are coming up properly now what do I want to do I want to turn it on okay now I want to reverse directions so I'm going to go the rewind if I do rewind let's see rewind it has not seen my rewind button okay yeah so now that changed direction and now I'm going to do the fast-forward and it does fast-forward mantra rewind again alright so the direction is going now you're asking why's counterclockwise forward because I'm a math teacher and right when you go counterclockwise that's a positive angle so I kind of do it the way math people do it most people want to think of clockwise is positive but not me okay so that is working now what do we want to do we want to see if we can slow it down with the down button so if I put slow ok let's try right it got the down did you hear it it slowed down a little bit okay I did another one it's slowing down oh this is working beautifully okay let me try again oh my this is really really really working good okay with it slow like this now let me see if I can change the direction I got to kind of see it's going clockwise so I'm going to try to make it go counterclockwise okay still going the right direction I'm going to see if I can slow it down again okay you see that dn let's go again what I wish here I can see it slowing down what I wish I'd done is I wish I'd put a print on em speed in there okay now I'm gonna change directions it is presently going counterclockwise and so I'm gonna go fast forward sees the fast forward okay I'm going to go reverse sees the reverse and it changes direction fast forward should change it again alright man do you see this working okay let's see if the speed up button works and so let me clear this so that you can see what I'm doing okay now I'm gonna see if I can speed it back up by going up so I hit up I can detect it going faster I hit up again I can detect it going up wonderful okay let's throw in a speed change mm okay guys do you see what we just did do you see what we just did we are controlling using our remote control we are controlling the on office of our fan we are controlling the forward-backward of our fan and we are controlling the speed of our fan okay me and this I think this has been just a really nice lesson remember if you do this with real motors you've got to go in and do the power calculations you've got to calculate the current you got to think of thermal properties you got to think about heat sinks and things like this but as far as the coding and the connections you can see that it's pretty easy to do this project where we are controlling the the speed direction and on honest of the motor okay your homework today is going to be to go in and I you know this up and down this up and down just make it go faster and slower from wherever it is I want you to add speed controls with the zero to nine where zero would turn it off and then nine would have it at full speed and then kind of have it in between for the in-between ones but you don't want to think okay I'll divide 255 by ten and each one will go 25 because you know that if you press 1 and have a motor speed 225 it's not gonna run you've got to be at at least a hundred or a hundred and twenty for it to run so 0 should be zero one should be somewhere around 120 and then from one to nine you want to scale from 120 to 255 it might be really good place to use a line use an equation of the line which I've kind of showed you before all right guys this has been kind of a fun little project for me I hope you've learned something from it if you got this guys tell me are you doing these projects okay are you actually doing the projects are you having success could you do it on your own did you have problems when you did on your own and it won't only got it working after you watch me do it give me some feedback how are they think these things going okay you've got your homework this has been lesson number 66 you've got your homework I am NOT going to go in and do that one for you you're just gonna have to do that one on your own and so in lesson 67 we will be moving on to new and exciting things palma quarter from top tech boy comm if you guys like this think about giving us a thumbs up think about subscribing to the channel make sure you ring that little bell so that you will get notifications of future future videos and then think about sharing this with other people man it's like you know just a couple of bucks you get the components you want and we at least I'm having a lot of fun with this okay Palma quarter from tuck tech boy comm I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 28,132
Rating: undefined out of 5
Keywords: L293D, DC Motor Control, Remote, IR, Arduino
Id: OJO12x0Bvco
Channel Id: undefined
Length: 60min 30sec (3630 seconds)
Published: Tue Jun 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.