 This is a servo, and I'm gonna teach you how to do this. Okay, well, not this, but I'm gonna teach you how to have it turn back and forth and stuff. Also, don't forget to like the video. When it comes to electric motors, we have a lot of options. This is a typical DC motor. It takes power in, sends power out through ground, so five volt ground. Super simple. When it's given power, it turns on, it starts spinning really fast. We've used this before in our clap sound video where we clapped and this turned on a fan and we clapped again and it turned it off. You can't do much with these. You don't get any position data. You can't control the speed unless you use a technique called pulsing where for example, if you have one second where you're running the motor, 50% of it should be off, 50% of it should be on at tiny little increments. And then doing that, you can keep it at 50% speed because you're only giving it 50% power and you keep turning it at 100% off, 100% off and it averages at 50%. But you really don't get much with these. They're kind of just turn on something like a fan that's cooling room or AC or whatever and then turn it off when you're done. Your next option up is to use a stepper motor. The problem with stepper motors is that they're really slow while being precise, they're really slow and the way they work is really different from the DC motor. In here, you have a bunch of pins that are electronically controlled magnetic poles and depending on which one's being turned on the axle will rotate towards that pin. So these kind of motors are really good on 3D printers, for example, where you need super precise movements at a very, very slow speed. And also these are really cheap. So for 3D printer kits, they're usually the perfect motor because 3D printers can get expensive so people try and make them really cheap. Then your last option is to use a servo motor. A servo motor, in my opinion, is better than a stepper motor in many ways, except for one little problem that is the only reason we don't use this on everything is because most servo motors have limited rotation. For example, this one is 180 degrees. While it can loosely do 360s electronically, it can only do 180, so go from here to here, and that's it. And it has to return back into the original position. It can't go out of those bounds. I have another one here that's absolutely gigantic compared to that little one. This one is only 120 degrees. So right now it's actually locked. And if you move it to 120 degrees, you're gonna go and lock it again. We're gonna be using this servo motor, which has three cables coming out of it. Brown, red, and orange. Brown is your ground, red is your power, orange is your signal. And if I pull my Arduino into the shot here, you can see that I already have that wired up. I have a black cable going to the brown, a red cable going to the red, and then this like tan brown cable going to the orange. Then on your Arduino board, you're gonna put the five volt into your five volt power, you're gonna put the ground into your ground, and then the brown can go into any digital port I put it into number two. Next up, just go and open up your Arduino editor and let's write the code. The first thing is we're gonna need to include the library for the servo. The Arduino editor includes this library. If you're using a different one, you're gonna have to go and install it. It's super easy. So we're gonna go in here and just include our servo library, servo.h. And then under that, we can get right into it. We can call the library. I'm calling the word servo and set it to the word servo with a lowercase s. So we can make this anything, this could be banana, chocolate, doesn't matter. I'm just putting it to the word servo because it's super easy for us to know what it is. In your setup, you're gonna want to go and grab that servo and attach to it pin number two. Now we can pretty much do anything. We can tell the servo that we want it to move based off of a button press or move based off of something happening in the room, a sensor's being activated. Let's say you're walking in front of your door and you want it to unlock the door. That's the kind of things you could do with the servo. I don't really have much to show you guys. I'm just gonna go and tell it to rotate all the way 180 and then rotate all the way back 180. So we're gonna call a loop here. And inside of it, we're gonna call a variable called position, POS for short. Problem is we need to go and declare position at the top of our program here. So we're just gonna do int POS equals zero. And then down here, we're gonna set it to zero again. We're gonna tell our loop if you're less than or less than or equal to 180, keep incrementing by one. Now we're gonna go and just copy paste this and repeat this loop one more time. But now instead of it starting at zero and going to 180, we're gonna tell it to go from 180 to zero. And then we're gonna change those to be greater than or equal to. Then here we wanna remove by one. So what's gonna happen is we're gonna go zero, loop 180 times until we hit 180, then go down here, 180, loop 180 times until we hit zero and then repeat the whole process. In here, really simple, all we have to do is tell it to take our servo and write to it the position which is going to be position. Then you can add a delay. Delays are usually for how fast you want the servo to go. Really fast would be like five milliseconds, really slow would be like half a second more. So let's just do 10 for the first example. Let's grab this, put it in here, control T to format. And we can upload this to our Arduino. Give it a second and our Arduino should start freaking out. There we go. Now it's going from 180 to 180. Now this is how you make it move. You can really go anywhere you want with it. Like for example, let's say I want to go and change this instead of 180 to be 50. And for this one to be 50. And then I'll go change my delay to three and delay three. And now it's gonna rotate insanely fast from zero to 50 degrees and 50 degrees to zero. So upload that to the Arduino and look at it freak out. That's pretty much it. All you have to do is set up a conditional that let's say says if button is being pressed, turn on servo. If button is not being pressed, turn off servo. Or you can go and get some kind of like potentiometer or some kind of knob that will give you a very descriptive reading of where it's being aimed at. And you can link that potentiometer to a servo. So for example, I'm on my desk and I'm turning a knob and as I'm turning the knob, it's turning the servo. You can do something really cool like that. The cool thing about servos is that they can return information as well. So you don't have to use it as a motor, but you can use it for position data. So for example, I had the servo set up here and I had something that it was connected to and I wanted to know what that thing will position it in. So it moves the servo back and forth and using that position data, I can send that to the computer and do something with it or I can send that to another servo and do something with it. They're really useful and there's just a bunch of crazy things you could do with them. If you enjoyed this video and it was helpful for you, maybe consider subscribing to the channel and liking this video. I'll see you guys in the future videos where I'll be making more content on the servos, sensors, motors, whatever.