LESSON 16: Controlling a Servo with Arduino

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is polemic order and I am here with Arduino lesson number 16 and hopefully you've been through the earlier lessons with us we're you know learning a little bit more every lesson a little bit more about programming a little bit more about circuits a little bit more about programming a little bit more about components and it this point you've got a really good idea for the the basics that you need to do some pretty sophisticated programming so we're going to start looking at additional components we're gonna start looking a little bit more on the circuit side of things and so what we're going to do today is we're going to start looking at making things move where we can get get things moving with the Arduino and so the component that we're going to be looking at is called a servo and the way a servo works is it moves the position of this little horn can be controlled by the commands that we send to this from the Arduino the important thing to understand about a servo is is that you need to understand that it is not a motor you can't just turn it on and have it go in a circle it typically has a limited range of motion and that limited range of motion is usually from about zero degrees to 180 degrees nominally that's kind of what they say they are most of them don't actually go to through that full range and so we'll talk about we'll talk a little bit more about that in a minute but this opens up all types of exciting new possibilities on your project to where you could get input from the user and you could use that to control where this thing went to or you could have a sensor and have the sensor control what this thing did so you could have it you know you could imagine something where you could have like a little window and if it got hot then this thing could open the little window or close it and again you know there's a lot bigger ones that you could use but we are we're playing around with a small one this small one is the one that comes in the sparks on inventor kit and for this one there are basically it's a small one and it can be driven directly from the Arduino there are three lines on most servos there is on this one the color code is there's a black there is a red and there is a white and what those are is the red is where you put the power to the servo for this one it wants five volts the black is for ground and the white is the control line of where you send the commands to make the thing actually move now this is really really really important these small ones like this one it comes in the spark phone kit you can power those directly from the Arduino the Arduino has enough power to power a small one like this but the thing is is that these servos draw a lot more current in a lot more power than what you think they would because it look like it's doing that much just spinning back and forth but it turns out these things really really draw a lot of current you want to make sure that you're not trying to drive one from the Arduino power supply that is trying to draw more current than what the Arduino can provide and some of them that are just a little bit bigger than this are too much to try to put on the Arduino several things happen one is you can damage the Arduino you can burn out your Arduino another thing is is that maybe it doesn't burn out the Arduino but it doesn't run very smoothly and you get a bunch of glitchy type of behavior out of it so you want to make sure that you have enough power for the servo that you're using in some cases what you can do is you can still use the control line hooked up to the Arduino but on the power line you could power it from something that could provide more current like an external voltage supply you could you could power it making sure you're always using the right voltage for the particular servo that you're that you're running so sometimes the Arduino can control larger servos but it just needs to be doing it through the control line and not through the and not trying to draw power the power from the Arduino one thing I always remind you any time you start getting more power supplies or getting your circuits more complicated make sure all of your grounds are hooked together the ground from the Arduino needs to be hooked to the ground from the circuit that needs to be hooked to the ground from the power supply so when you're doing these things you know usually when I'm looking at students work one of the common problems that I see when they're having problems is they don't have all their grounds hooked together so make sure that you get your ground your circuit really grounded your circuit really grounded well so this is a pretty pretty exciting little component that we can start working with another kind of warning I got to give you is that me and so much of the stuff that you do with Arduino Xand electron and engineering is like everything works perfectly just all these components are like cheap and they work great the servos not so much the servos thing like I have more problem with servos than just about anything else I'll get one and it doesn't work or I get one and it's jittery or I get one and it doesn't work the way it's supposed to and so just to understand there's a lot of there's a lot of kind of not-so-great servos out there and particularly these little cheap ones a lot of times you'll get one that doesn't work very well and one of the things to be aware of is when you buy one of these little guys it says that it can go from 0 to 180 so if I hooked a pin up to this this would be like it would you could position it supposedly from 0 to 180 ok from 0 to 180 but what I found is is that they rarely ever go over the full range that they advertise and one of the things that's a problem is is that if you try to overdrive it if you try to drive it past the point that it wants to go it starts chittering and it starts drawing a whole lot of current that could damage your Arduino or it could damage your servo and so what you've got to do is usually when I get a servo the first thing I do is I write a little program just to see for that servo how far it wants to go and like if you look at this little guy here that I have you can see that he's not going over the full hundred and eighty degree range and that's because I'm not driving him to go over the full hundred and eighty degree range because when I was playing with it I saw that he didn't want to go all the way to zero and so I didn't try to drive him always all the way to zero so when you get a servo it's good to play around with it and see its natural range of motion that you can get without it starting to starting to jitter the other thing is is that don't try to turn this with your hand that that can be very bad on a servo don't force drive it you know only drive it electrically don't come in and start trying to spin it by hand because that can cause a problem with some of with some of the some of the servos and so Sarah is one of the trickier little components to work with if you're having trouble with one you know sometimes what you need to do is you just need to kind of toss it and get another one because a lot of times some of these things just don't work very well okay so what are we going to do we're going to start playing with this thing and I guess a couple of things what the objective of this lesson is is that we want a circuit where we have a potentiometer and then we want the Arduino to read the voltage off the potentiometer is a voltage divider I think it was lesson 10 things that we went through how to use the potentiometer as a voltage divider and how to make Arduino Reed's from it so what we're going to be doing is we're going to be reading the position of the potentiometer by reading the analog voltage off of the center pin and then as you spin this thing around that that number that you read the voltage will go from zero to five volts the number that you read will be between zero and ten twenty three with ten twenty three representing representing five volts and 0 representing zero volts and so you'll be reading a number on an analog pin between zero and ten twenty three then what I want you to do is to take that number and have that then control where the where the servo is pointing so basically I want the servo I'm not the servo to track the potentiometer so if you have the potentiometer all the way to the left the servos all the way over if you put the potentiometer the servo smoothly tracks where you set the set the potentiometer so that's the assignment what the good news is is that you pretty much already know how to do the servo or if you don't go back and look at I think it was lesson 10 and then you'll see how to use the I'm sorry the potentiometer go back and look at circuit at Arduino lesson number ten to see how to use the potentiometer and what we're going to learn today is we're going to learn how to use this servo and so we're going to probably just jump right in here I guess I need to go back in pay for the code I'm using for the code that I'm going to be using here we use this schematic this is on my website at top tech boy comm and this is again lesson 16 and this is the schematic of how I've hooked up the potentiometer and the center leg going to pin a zero the bottom leg going to the power real here the power real going to five volts and then this leg going to ground and then ground going to ground so again all my grounds hooked up and then reading off of this Center Kent and so that's how you do the the potentiometer side of things I couldn't draw the servo over here so I'll just kind of have to tell you how I did the how I did the servo being on the on the servo I am hooking the control line of the servo for this one it's the white line I'm hooking that to pin nine okay the servo is hooked to 10 9 and to be used as the as the control line the thing to understand about that though is is that you can use any of these digital pins you want as long as it's one with a squiggly line because you're going to be doing one of these analog writes to it and so because we're doing analog writes you need to make sure it's a pin you can analog right - and those are the ones with the squiggly lines bottom nine is a good choice and that is the one that I'm going to use okay so I've got on this servo I've got the control line which is the white line hooked up to ten nine I've got the 5 volts to 5 volts I'd go through a rail here that I establish from the from the Arduino and then ground to ground and with that then you're going to be nominally set up to start working with this thing so let's see if we can go in and let's see if we can start writing some code let me get me a new Arduino integrated development environment up here so that we can get going ok the good thing is is you start getting into some of these components like servos and getting into some of these more sophisticated devices there's what's called libraries and libraries are code that someone else has written either the people that develop the Arduino or the people that develop the servo or component product whatever it may be they write libraries and then when you use those libraries it makes it a lot simpler and more intuitive to work with the component it just makes it really easy to send commands to it so you're not having to work down there at a very very low level you're able to work up where it's a little bit easier but to use those libraries you have to begin downloading the librarian I don't think we've done this before the way you load the library is you've got to know the name of the library and you start to load a library by the the pound sign and you say include that is telling arduino to load a library and then you have to tell it the name of the library this is servo dot h and then close it and then what are we doing we are loading the servo library okay now another way you can do it let me just let me take this much of it off and you believe it or not believe it or not on these loads I messed up here you don't put a semicolon it just ends like that so on your library includes one of a few places no semicolon okay there's another way you can load it a lot of times what you can just do is you can come in here and if you look under tools and you can look under sketch I'm sorry yeah under scanner brer e and you can see the servo library is right there and I can just load my servo library there include servo H which I said and let me put my comment back up there okay loading the servo library all right now what we need to do is we need to set up some variables well one thing that we're going to have to do is we're going to have to write to this thing we're going to have to make writes telling it where to go to so we need a variable to hold that number that we're going to write and what we're going to write is we're going to write position so I'm going to put a variable called position and I'm going to set it initially equal to zero okay declare and initialize the POS variable okay so that gets us a variable to use the other thing is we need to keep track of our pins and remember we've got the servo hugged up so we're going to say servo pin and where did we hook that in my cert in my circuit we hooked it up to nine so we need to tell it tell our we know Arduino that that servo is what - can i okay then I'm going to have a potential not not quite yet what I'm also going to have is I'm going to basically every time you write the servo you need to pause just a little bit of time to give it time to move and so I'm going to have a servo delay so that I can put this in just to slow it up a little bit so you're not trying to overdrive it okay 25 and then okay and then then that's probably going to be my variables now let me tell you what we're trying to do in this remember how I told you that on these on these servos you don't want to overdrive them right that they say they go from zero to 180 but typically they don't really go from zero to 180 and so if this one only wants to go to 25 you shouldn't try to drive it to zero because then it starts shaking and it starts drawing a lot of current it can burn the servo out or it can damage your Arduino so what you want to do is for the servo you're using you want to kind of find what the natural range is and so what I want to do with this first little program is I just want to go out to the user and I want to ask the user over the serial port what position would you like to set it to and then I want to move to that position and what I can do is I can try to go to zero and if it starts shaking I shouldn't go to zero so I'll come back and I say well maybe I can go to 10 or maybe I can go to 20 and kind of find that range of how small of an angle it can go to without a problem and then at the same time I want to find at the high end will it go to all the way to 180 or does it only want to go to 175 so I sort of need the low end and the high end that this thing naturally is happy is happy running at and so I've got to write a program that will go out and ask the user for a number you type the number in and then it goes to that value and then you can just sit and just sort of observe it and see what range that it seems to be that it seems to be happy at going in and so that's why I need to write this program so position is going to be the value that you get from the user that you're going to set you're going to try to set it to that position servo pen it's not that's where I am getting the V that's where I'm sending the command to the servo of how foot position to go to and then servo delay is how long I'm going to wait after I write it I think that's pretty good on my variables now this is the new part okay when I put this servo that I'm going to be working with with a library I need to now create an object for Arduino to work with and that object is going to be a servo object that I got to name the object I going to tell it what do I want my servo to be called and I create that object when it's a servo object with this library with it with the command servo and you do this up at the top of the program like where you're declaring your variable servo and since this is a pointer I could call it I could call it my servo or I could call it you know little servo but I think because I'm pointing I'm going to call it my pointer okay so what this tells Arduino is create a servo object called my pointer you could call it whatever you wanted to that you tell Arduino it's a server with a servo with the uppercase s okay so now I have created the servo okay I've created the object called servo to work with an Arduino right now let's come down to the set up and what are we going to need to do well we're going to be working over the serial monitor so we need to do a serial dot begin okay and we'll work at 9600 just because that seems to work pretty well and then what we need to do is we have to tell the Arduino we told the Arduino hey I've got a servo it's called my pointer now we have to tell it how do you communicate to my pointer where is my pointer connected and the way you do that is and you tell it that my pointer dot the catch you're telling it that this object that's a servo called my pointer my pointer is attached to the Arduino at ten nine right no it is attached to pin nine but I don't put in pin nine in here that's why I put this up here servo pen okay it sat at my my pointer which is a servo that I created here is attached the server at servo pin and servo pin is nine okay so now Arduino knows that I have this object called that this object that's a servo that we've named my pointer where is it attached it's attached to the circuit at servo pin which is pin 9 okay so hopefully that makes sense I think that's all we need to do right now in our void setup now in our void loop what are we going to do we're going to go ask the user for input and then we're going to put the servo at the angle that the user indicated so to get input from the user over the serial port what do we do three things number one we prompt the user for input after we prompt them for input we wait for him to put it in and then after he puts it in we read it so the first thing we do is we are going to prompt him and we will do that with a AC r VL dot println it's all in one line so I'll put a bell in what where would you like to position position the servo okay so what are we doing prompt user for input okay now after we pump to them for input what do we do we wait for it how do we wait we wait in a while loop or the condition is serial dot available equal equal zero so what's that saying if there's nothing on the serial port that means he hasn't put the data yet while we're waiting for data we sit here in this loop between here and here and we do absolutely nothing it just sits there is there anything on the serial port no is there anything on the serial port no is there anything on the serial port no as long as there is nothing on the serial port it just sits in loops as soon as he enters the number then there is something on the serial port serial available is not zero and it drops out to the next set so this just hangs until the person puts the data in then what do we want to do well we want to get that and where do we read that number into well that's the position number that's going to tell us where to go and we've already set that up so we're going to say position is equal to how do I read an int off of the serial port that was parse that was I'm sorry serial dot parse and thing like that so it goes out and it gets that number off the serial port and it puts it into the variable POS okay so that should do that so now we know what the position is so how do we get the servo to go to that well we talked to the servo what's our servo name my pointer so we go my pointer why because that's what I named it okay my pointer that's what I named it dot what do we do to it right and what do we write we write our position okay so this number position we're going to write to the servo called lap pointer and that's what it's going to do okay let's get Bette back up here and put some comments and read user input right POS to servo alright I think this is going to work okay look at this this is happy so let's go to our serial monitor and it's asking me where would you like to put the servo well let's just say 90 degrees kind of in the middle okay we were probably already about there let's say 45 degrees okay there it goes let's say 130 degrees there it goes okay what was the purpose of this program it was to find that range of motion that this is comfortable going without it starting to shake and vibrate so let's just say if I go to zero okay now what I can do is I can feel this thing is really shaking and straining even though that you can't see it I can see that's not good so I'm going to go to like 30 degrees to get it off of that you wouldn't want to leave it there okay so now it's come up and it's gone away from that let's say see if I could go down to five degrees okay it's still it's still straining at five that's too far let's go back to 30 okay let me see if I can go to ten still not happy okay at 15 it seems pretty happy so let's see you see if I go to 25 it goes there I go back to 15 it goes there so it seems out let's see if I can go to 20 you see it seems like down in that region 15 is about the low end of where you can go with with it still being happy and so make note that the low end the low end is 15 degrees so I've written that down now let's look at the high end if I go to 180 okay it is straining so let's go to 160 okay 175 okay it's still straining a 160 okay let me try going to 170 you know it seems pretty happy at 170 and if I go to 165 you can see it moves and if I go to 170 it moves and so you see 160 170 it's happy it's still in that range and so I'm going to say for this particular sensor that I mean for this particular servo I'll the one down here but that particular servo is doing pretty good from 15 to 170 so basically I can go from 15 degrees which is over here to 170 now the thing that kind of irks me you pay for 0 to 180 and you get 15 to 170 it's like you're kind of getting cheated out of 25 degrees but I guess that's what happens when you buy a three dollar servo that if you spend $30 on a servo you'll probably get one that works a little bit a little bit better than this but now we sort of see that the range of motion and that this servo is happy working in so let's let's play around with our program a little bit and let's kind of take it up to the next level I sort of know 15 to 170 so let's see if I can just kind of sweep back and forth between those two so how would I do that how would I smoothly sweep over a range well I could do that with a for loop I could say 4 and what would I want to loop on well I'm wanting to loop on what the position okay so I can go from position is equal to where do I want to start so Europe no because 0 is too far let's start where I want to start at 15 so for position is equal to 15 and then to position keep looping as long as position is less than or equal to what 170 was what seemed to work pretty well ok and then what we would say is position is equal to position plus 1 okay and this is a for loop so we start a clause and then we come down here and we end the clause and everything in between here it will do starting the first time through position POS is going to be 15 and then 16 17 18 it's going to keep looping as long as POS is less than or equal to 170 once it is not equal to one less than or equal to 170 which means when it gets to 171 it'll drop out and then move on what's the rest of the code and then we tell it POS as POS plus one okay so what do we do inside of this loop well we will want to do a my pointer dot right and what do we want to write physician send servo to us okay and we got to be good and remember our semi cannot once and then after we write it it's always good to delay so we're going to delay a little bit so that we're not trying to drive it too fast and I'm going to say 25 I'm saying the 25 milliseconds is good so we set that up a servo delay and the cool thing about this is is that if you have lots of delays in there and you want to tweak them you just do it one place up here and then everywhere you use servo delay it'll it'll change it so let's just say this is going to pause a mo moment okay this should go from 15 to 170 it should be happy in there but once we go there we want to sweep back so it's going back and forth so we need a second look that first loop is going to take it all the way over to here and now we need to take it back well I like to copy and paste and so I'll just copy and paste this and then kind of fix the things that needed to be fixed and so here is the second loop but here instead of going from 15 to 170 where do we want to go that's right we want to go backwards we want to go from 170 to 15 but you got to think you want to loop as long as position is less than fit know in this case you're going backwards it would be greater than or equal to 15 so you would want to go 170 69 68 so you would go as long as you're more than 15 and because you're coming backwards this that should not be post that should be poss position position position plus 1 positions position plus 1 but we don't want position to go plus 1 we want to go to go from 170 down to 15 so position beat should be what position should be position equal position minus 1 so on this one it's counting backward so it counts forward to 170 and then backwards from 170 and then the rest of this should be work right I think this is going to work look at that this is going to work okay and here it goes okay it's sweeping up to 170 and then sweeping smoothly down from 170 and looking at it like this you can see that you're really getting cheated out you're not getting you know you're not getting 180 degrees out of this thing that you'd hope to that that's up you know that's not that's not such a hot deal but the rather limited range of these these cheap not cheap guys but nonetheless that is really something that I think is pretty cool and you can imagine that there's all types of things you could do what's a way that we could make it run a little faster maybe well you could say take out the delay but you really need a delay in there right you really need that delay in there because you don't want to overdrive it what what can we do what if we said position is position plus 2 and then let's let it go slow on the way back so it's going to go faster this way and slower that way let's see if that happens yeah look at it go and then nice and slow smooth back and then faster coming this way and slower going back let's say if we can even exaggerate that a little bit more you see real fast in one direction slower in the other because we're jumping five steps at a time going in the forward direction five steps at a time so you can play around with this and there's a lot of different parameters that you can play with to kind of make it do different things and sort of do what you do what you would like it to do okay but what was the objective that we wanted here we wanted this thing we just kind of been playing around with it to see what its range of motion was what we really wanted to do is we want it to track the position of the potentiometer and I'm going to download that first program so this thing will stop spinning back and forth ah okay stop it there for a second alright so what do we want this thing to actually do we want it to not be set by a position from the serial monitor we want its position to be set by where this potentiometer is and remember we're reading this potentiometer the center leg of the voltage divider over here at Penn zero when you read a voltage from the potentiometer you are going to be reading for the circuit the way we have it set up here hooked up to 5 volts you're going to be reading a voltage from 0 to 5 volts ok but what number are you going to see at the at the analog input pin 0 to 5 volts is going to correspond to a number between 0 and 10 83 okay so the number we're going to be working with is 0 to 10 83 and then that needs to map to now you got to think about this you don't want 0 a read of 0 on the potentiometer to take you to zero because that would be over driving the potentiometer and if somebody came in and didn't know all this stuff you and I know about not overdriving potentiometers and they turned it all all the way to the left and it would put it in that position to where it would be shaking and the user without knowing any better it could burn I could burn your stuff out so you got to make sure that he cannot set this at lower than what we determined the low end was 15 so when I read a value of zero from the potentiometer what now you should I write to the servo not zero I should write 15 okay think about that and similarly on the high end when I'm all the way to the other end and the potentiometer is reading 1083 I don't want that to write to 180 I want that - right - what 170 okay guys this is not something you can just wing and if there's nothing else you learn in these classes I hope that you learn how to do how to apply the math that you learned in a math class to a problem like this what is our independent variable what is our variable on the horizontal axis it's zero - 1083 it's what's coming off this potentiometer I can set this to zero - I can set it to ten eighty three this is the independent variable it's the horizontal axis what is the axis that I'm going to the dependent variable is this it's this it's the vertical axis the vertical axis needs to go from where 15 to 170 when the horizontal axis goes from 0 to 10 83 so this is going to be some math so let's look at this I want you to be able to read this so let me see if I can okay so controlling a servo with Arduino and I wish I was one of these guys that had that real neat precision engineering looking handwriting but I am NOT one of those guys and so you will have to live with my poor handwriting I do it as neat as I can controlling the servo with Arduino number one what you need to do is figure out the minimum and maximum range of travel for your Arduino servo for mine it was 15 - 170 don't come in and use 15 - 170 if I plug this servo in it's going to be different than that one and so for the particular servo that you're using you need to find out what that safe range is for this one plugged in it's 15 - 170 what you need to do now is map that range onto the values you will get from the potentiometer so let's do our math here okay let's do our math okay so the independent variable is what I control that is the position on the potentiometer that is going to create a number between what and what between 0 and 10 23 okay so that's this horizontal axis the potentiometer reading pot reading is going to be between 0 to 1023 over that range what values do I want to apply to the servo well at the low end I want to apply 15 and at the high end I want to apply 170 so when the potentiometer reads zero the x value I want and the position or the servo to go to 15 when the potentiometer reads 10 23 I want to put the servo at 170 so we have two points and we have a line but what we need is we need the equation of that line so that for any reading on the potentiometer I can calculate the POS value the position value to put on the servo so how does that work we find the slope of the line what is the slope let's get back to math class you should been doing this for years just you guys it's like you learn all this stuff in math and as soon as you walk out of math it's like you forgot it you walk back into math you could do these all day long boom-boom-boom-boom I see you I see you working these working things working these but you won't crowd a math class and you come into engineering class and it's like you never saw a line in your life okay so know how to take those math skills that you're learning in math class and bring them into the real world how do you find the slope of the line M is y2 minus y1 over x2 minus x1 what is our y-value its 117 170 and 15 so y2 minus y1 is 170 minus 15 X 2 minus X 1 is 10 23 minus 0 1 70 minus 15 is 150 5 10 20 3 minus 0 10:23 I hope you understand this I hope you get this in your head okay then how do we we've got the slope of the line how do we get the equation of the line well what do we have we have the slope and we have a point so let's use the point slope form of the line what is the point slope form of the line y minus y1 is M onto X minus x1 I could choose from my point either this one or this one this one has a zero in it a smaller number so I think that one will be easier so I will use that one the other one would work I like to try to find the easy way so Y minus y1 is Y minus 15 is equal to M which we already said was 155 over 10 23 onto X minus x1 and what is x1 x1 is 0 so Y minus 15 is equal to 155 over 10 23 X minus 0 I can move the 15 to the other side and I have Y is equal to 155 over 10 23 X plus 15 now let's turn this into the variables that we're using I always do it in X&Y because you remember back from math class but our why was POS so our Y becomes our y becomes POS in our X was pot reading so POS is equal to 155 over 10 23 times pot reading plus 15 okay this is the equation that we use to calculate the position that we're going to write to the servo from the number that we read off of the Arduino okay offered the potentiometer on the Arduino so let's see if we can make this little guy work and I'll see if I can kind of leave this equation on here so that you can continue to see our nice math work as we continue on with this ok you know what I can probably back this off a little bit now so you can see the whole thing okay all right so hopefully you have your circuit put together and you can just code a long sight of me so let's see here let me get these things set up okay this is going to be kind of amazingly simple in our loop what do we want to do we want to go out and read that value off of the potentiometer how do we do that we say our variable what did we set up we better set up a variable up here and we're going to call that variable int and we're going to call it pot reading we're not going to give it an initial value declare variable for potentiometer leading okay and so pot reading how do I read it well we do an analog read uppercase are we got to tell it where we're going to read where do we read we read not servo pen but we read pot pen which we have not set up yet so we need a pot pen when we set up these variables we did not have a potentiometer in the circuit pot pen for me is a 0 so integer pot pin is equal to a 0 not o upper case a 0 won't work the other way okay connect potentiometer to 10a a 0 okay so now we do the our analog read where pot 10 which it knows is a zero okay what we're doing is reading both tension mixer alright so we have our pot reading now we've got to calculate our position how do we figure out the position we want to go to based on this well we just did the mat position is equal to what well it's equal to 155 divided by 10 23 and guys when I do division I always do point because if you don't put a decimal in there and you do integer division strange things can happen and they are usually not good so always put 155 point divided by 10 23 point that tells it to give me a full floating-point number in here okay times what pop reading that I just took okay plus 15 because that is what the math said now we know position what we do we write it so I say my pointer that's the name of my servo is equal to or my pointer dot right and we write that position okay so this is calculate position and this is right position to serve okay one thing to understand is your equations not going to be the same as this you need to do this for your own part and you're probably not going to be at 15 and 170 so you need to go through the math for your particular part okay and when I come around to grade this for those of you in my class I'm going to be looking and making sure that you didn't just lift my equation but that it really is right for your for your servo okay I'm going to be checking you and checking you twice on that okay if you're doing this on your own be good because you're not cheating anybody but yourself if you don't really go in and I'll have a know how to do this okay I think this is going to work let's take a look at it okay so now as I twist this knob it should gently go from 15 all the way to 170 so if I'm all the way to the left it's over there at the start and look at this I can just very smoothly let's go back a little let's come back a little you see I can put that wherever I want just by turning this all the way to 170 go back a little bit come back that is just super cool and I like the little arrow that's on there because you can kind of see you know you can kind of see where it is a little better you can see the thing moving is I turn this well I just think that this is just super super super cool okay I just I just really like I really really like playing with this thing okay but one of the things that briefly want to kind of touch base with you on is is that what I want you to do now is I want you to go out and kind of create something with this I want you to just hook up some simple little thing maybe you make a paper box that you open the window on or or something that you that you hook this to but I want you to do something and you know we for those of you in my classroom we've got the 3d printer you can print something up on the 3d printer that does something you can make something but what I want you to do is go out and be a little bit creative in what you create with what you've learned with using a servo and a potentiometer or hook the servo drive it from the serial port or drive it from something else what do you remember the color sensor put the color sensor on there and depending on the color of the card the cards the color of the card that the sensor sees make the servo do something interesting so so the problem is is that so many times in engineering quad osseous is it then we get so focused on the the nuts and the boats bolts in the code that we don't really think the 4y4 why do we learn this stuff okay the reason we learn it is we want to do cool stuff so I want us to spend more time thinking about the cool things that we can make and not just sitting here making things move for no reason and one of the things that I find that I find interesting those of you that are in my class know that for most of these projects we have a contest and you know whoever whoever does the best wins the contest wins a stereo or some some cool piece of electronic gear and in the kind of thing that I see is is that sometimes the kids that are the best coders and have their their program and their circuit all up and running in five minutes they're through their project is kind of dull and boring and sometimes it's that kid that that's maybe a little bit slower at getting his code working a little bit slower kind of like maybe sometimes the last one to finally find his mistake and get the code working but it's that kid that just blows me away with the creativity of the and I'll tell you guys being I was a I was an engineer for 30 years in electrical engineering and the successful electrical engineer is not the guy necessarily that can code the best but the guy that can make things appealing and user-friendly and attractive to a user something that that draws the users from they want to sit and play with it and so I just really want you to not lose that creative aspect of things and so I just encourage you to think creatively and how you can use the servo as part of a project that would do something neat and cool and so we'll have three or four days to work on this probably the rest of the week and then I will come around and we will we will be looking at just how creative you can create a project based on Loosli something associated with the servo and the in the potentiometer again if you're not using the servo make sure that you aren't trying to drive one from the Arduino unless you're sure the Arduino can give you the juice you need to do that okay palma quarter this was lesson number 16 I believe hope you will tune in shortly for lesson number 17 we are signing out
Info
Channel: Paul McWhorter
Views: 231,025
Rating: undefined out of 5
Keywords: Arduino, Servo, Potentiometer, STEM, High School Science, Tutorial
Id: fE4m7TyLd8M
Channel Id: undefined
Length: 46min 31sec (2791 seconds)
Published: Fri Jul 11 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.