 Today we'll be talking about servos. A servo is an indispensable little device that's used by tons of tech and electronics hobbyists creating crazy little projects. Servos are basically motors, right? But unlike traditional motors that are spin mindlessly, servos are very special because servos know precisely the location that they're angled at. That means they know if they're at 0 degrees, 45 degrees, 90 degrees and they're extremely accurate. In fact, if you tell them to go to position, they can go to that position and hold the position. Furthermore, unlike traditional motors, servos have gears inside. Because they have gears inside, they can effectively pull a lot more weight. So they don't move as much, right? They might be able to slow in terms of the movement, but they can pull a lot of weight. They have a lot of torque. You also get servos that have plastic gears, again like this one, or servos with metal gears. The servos with metal gears don't wear out easily because servos, when they're lifting any sort of weight, tend to put a lot of stress on the gears, right? So the metal gears don't wear out as quickly and plastic gears can often wear out, leaving them to be useless. Unlike traditional motors, servos have multiple different servo attachments. In fact, you can 3D print your own attachments. Having these various attachments makes it very easy to interface your servo to anything in your project that you want to add movement to. Servos work by using something called a potentiometer. This little potentiometer, which is a variable resistor, and we talk about a potentiometer in another video. But a potentiometer can basically determine what position is the servo currently at. Is it at this position? Is it at a position like this? Whatever. You can tell the potentiometer can tell and feedback to the microcontroller inside the servo as to which position the servo is resting at. There are two types of servos. You can get either continuous or non-continuous servos. This servo in my hand right now is a non-continuous servo. Its range of motion is roughly from 0 degrees to 180 degrees. Continuous servos like used in projects such as these cars can turn a continuous 0 to 360 degrees so they can rotate endlessly like a traditional motor. So wiring up your servos is actually quite straightforward. There are three simple cables. The red wire is a power cable, the brown or black wire is your ground, and the yellow or orange or white cable will be your signal cable. For power, look at the datasheet for a specific servo. Most servos run on anything from 3.3 to 5 volts. Ground is simple just connect it to the ground of your microcontroller and the power goes to the power output of the microcontroller. For the signal cable, which is usually the orange, white, or yellow cable, this one's actually quite interesting. The servo uses something called a PWM signal, pulse with modulation. Those signals look something like this. Those signals basically work by telling the servo to move to a central position based on how wide these gaps are between each pulse that your microcontroller sends. On a board like the Arduino, you have special ports that support PWM. Note, not all pins of your microcontroller or microprocessor support PWM. You have to connect your servo to a pin that specifically supports PWM signals. Once you've connected your servo to a PWM compatible pin, we can go ahead and code our servos. Okay, so here I've opened up the Arduino IDE and we're going to go ahead and write code for a servo. First thing we're going to do is go into the file, examples, and go all the way down to servo. Here you'll see the two examples. We won't use an option, we'll just use reach. So click on that and it'll open up a new file that looks something like this. Let me walk you through what's happening. First of all, remember how I said the servo has something called a PWM signal? To use this PWM signal, you can use the servo.h library so you don't have to code all these PWM signals yourself. You can just give it an angle and the servo will go to the angle that you want it to. To use this library, what we need to do is create an object within the servo class. So in this case, this example code has servo, that's the classifier, and the object is my servo. Let's call this anything we want. We can call this, I don't know, our quality name. Let's call it here. The next thing is initial position. We don't need this, but in this exact, in this code, it's going to be there. It's basically creating a variable to hold our position. Then after that, we go into my servo.attach. Again, when we're not using the my servo name, we just created our squad here. So I'm going to change that. What this basically tells us is that which pin is our servo attached to. In our situation, we use pin nine, so we're going to leave it at pin nine. It's actually a little bit complicated. What I want to do is something a lot simpler. What we're going to do is actually we're going to just do gay dot, right? And we'll write the angle, let's say 50 degrees. So that's the first angle. Then the, let me type in the code. Then maybe let's delay, delay, let me pause for, let's say half a second, 500 milliseconds, and then gay dot, right? Let's move to the angle, maybe 120, and then let's repeat, delay, wait for half a second. Actually, let's wait for one second this time. So we're waiting for 1000 milliseconds, which is one second. What does the microseconds? I think, and then we're going to write to, we're going to move to gay dot, right? That's on 20. So now what our servo is going to do is it's going to go to an angle of 50 degrees, then to an angle of 120 degrees, then to an angle of 180, which is flat. And then it's going to repeat this. Let's add another one here, delay, half a second, and then repeat. So this is how you can use servo libraries in Arduino to control their position. You basically have to use, you have to make sure to include the servo library, which is this line. You have to create the servo object, which is right here. I named mine gay. In fact, let me capitalize instances. And then you also got to attach it in the setup part of the code. You got to attach it to a pin, which is whichever pin you connected it to. So yeah, that's how you use a servo. If you like this video, go ahead and hit a like. If you have any questions, go ahead and put them down in the comment section. Thanks.