Servo A-Go-Go!

with randofo

Introduction: Servo A-Go-Go!

A servo is basically a special kind of geared motor. What makes a servo different from a normal geared motor is that it has a built-in controller board and (typically) a feedback potentiometer (like a stereo volume knob) for accurate positioning. It is very easy to control a servo motor using a microcontroller such as an Arduino. Typically no other control circuitry is needed. Servos are basically a very easy and reliable motor to work with.


Types of Servos

Hobby servos tend to come in a wide range of sizes. They also have a variety of other options such as their overall rotation, how their gearbox is constructed, and how they communicate with microcontrollers. Follows are some basic types of servos you may encounter.



Standard Servos


Standard servos are fairly standard as far as servos go. Hence the name, standard servo. The standard name largely applies to the size of the motor (approximately 1.5" x 1.5" x .75"). Beyond that, there tends to be nothing standard about the standard servo.

There are countless different types of standard servos you may encounter. They make them with plastic or metal gearboxes, which in turn are designed for either high speed or high toruqe opration. Most have 90 degree rotation (90 degrees in both directions - 180 total), but some have 180 degree rotation (180 degrees in both directions - 360 total), or are continuous rotation and can spin freely. Some even have digital control boards, as opposed to the servos with analog boards like we are using. You can even find some that don't meet any of these descriptions. There are a lot of "standard" servos out in the world.



Nano Servos

Nano servos are small - roughly the size of a very small coin. These are used when size constraints are an issue. They are good for manipulating existing mechanisms (i.e. pressing a button), or building very - very - small robots. They are manufactured largely to do things like control flaps in RC airplanes.



Micro Servos

These are like nano servos, but slighly bigger and more powerful. They have most of the same use-cases and functionality of nano servos. They are good for building small things rather than tiny things. They are also typically manufactured for use in RC airplanes.



1/4 Scale

If you were to judge by the name you might infer that a 1/4 scale servo is very small. However, you would be wrong. These servos are meant to be used with model cars which are a quarter the size of the actual thing. Thus, they are relatively big and they are typically fairly powerful. When you need something heavy duty, this should be your go-to.

Their size and power make them ideal for drive motors. Unfortunately, these servos rarely come pre-made for continuous rotation. However, it is possible to modify a standard servo to be a continuous rotation servo and a number of retailers will do this for you for an extra charge.


Gearbox Construction

As mentioned, not all servos are created equally. Every servo performs differently depending on the type of motor used, the configuration of the gear assembly, and whether the gears are plastic or metal.

Servos with metal gears tend to be built to provide more torque than servos with plastic gears. The reason for this is that plastic gears break under heavy loads and metal gears tend to be much stronger. Thus, the metal geared servos are capable of dealing with the heavier loads and greater forces.

For those still confused, torque is basically the amount of force a rotating shaft can provide. What this means is that something with more torque is less likely to stall (or stop rotating and/or applying pressure) than something with less torque. If you need to lift something, or press down upon something, the more torque your servo can provide, the better.

The torque measurements you may typically encounter are in ounce-inch (oz-in), kilogram-centimeter (kg-cm), or Newton meter (N-m). Understanding this is a complicated matter. To simplify, bigger is typically better for most applications. You should get used to working in either oz-in or kg-cm, and then use online measurement converters to translate all measurements to the value you are most comfortable with.


Standard Servos

When using a standard servo, you are able to send it to a very specific position along it's angle of rotation. In other words, if you are using a servo capable of rotating 180 degrees, you can tell it to go to any degree (say - 112 degrees for instance), and it will move there from its current position.

The reason is is able to know what position it is at is because there is a potentiometer (or variable resistor) built into the gear box. That component is basically the twisty knob you see hovering over the top of the circuit board. The way this works is that when the gears rotate, they also rotate the knob which changes the amount of resistance in the circuit. The control board is able to sense this change in resistance and precisely determine the motor shaft's position in degrees.

Since a potentiometer can only be rotated so far, these motors cannot rotate beyond their maximum angle. Additionally, if you look closely at the largest gear on the right side of the gear box, you will notice a little plastic tab protruding from the surface. This is a physical stop preventing the servo from extending beyond its maximum rotation angle. Standard servos are physically restricted from making a full rotation in two ways.

While you obviously cannot use this type of servo to drive the robot around, it is very useful for a large host of applications. Say you are building a robot arm, for instance. You can use a servo to control each joint. By doing this, you can tell each joint to move to a very precise position, allowing it to do very complex tasks. You can also use them to do things like build multi-legged walking robot spiders, press down on other things such as a spray can nozzle, or make creepy animatronic baby dolls.


Continuous Rotation Servos

Continuous rotation servos don't have positioning ability, and are able to make a full rotation. If you look closely at the large gear on the right you will notice that there is no physical hard stop restricting its ability to rotate.

Rather than set position, continuous servos allow you to set motor direction and speed. This allows you to easily do things like specify that it goes fast in a clockwise direction, pause for a moment, and then resume very slowly in a counterclockwise direction. These servos basically have a built-in H-bridge that you can control using a microcontroller.

They are very useful as robot drive wheels, or in mechnical systems that require a motor with continuous rotation (such as with the paintbrush mechanism in the sponge bot). However, don't expect to get much speed out of them. While servos are known for easy control, and decent torque, they are not known for speed. This is because the gearboxes designed to provide torque do so at the expense of overall motor speed.

Throughout this class we will only be using servos as drive motors because nothing we are building is intended to go remarkably fast. However, as you get deeper into robotics and start feeling a need for speed, you may want to research DC geared motors and motor controllers. This may sound overwhelming, but just remember, a continuous rotation servo is basically a DC geared motor with the motor controller already built in.


Powering a Servo

A servo has 3 wires coming off of it.

Signal: Connected to a 5V digital control pin from a microcontroller.
Power:This can be connected to a positive voltage from 4.5V up to 6V.
Ground:Connected to common ground - always.

You may be tempted to just connect the servo's power wire to the 5V pin on the Arduino microcontroller. DON'T!

Connecting the servo to the 5V pin is a bad idea because:
1) The Arduino's 5V pin can only provide a limited amount of current. Thus, you will likely be under-powering the motor.
2) The 5V pin does not have much in the way of a protection circuit. What this means is that if a voltage greater than 5V shows up at the pin, you can potentially damage the Arduino board. Motors (such as servos) are particularly known for producing back current (i.e. unexpected electrical currents), and you could potentially send more than 5V back to the board.
3) Also, if you draw too much current from the Arduino board, your code simply could do funny things and not work right. It's simply best practice to power current hogs (like motors) seperately.



The simplest solution is to provide the motor with its own power supply. This can be done most easily by connecting a 6V battery supply to the servo. Well - it can almost be done that easily. There is the issue of ground. The ground wire from the battery pack needs to be shared with the ground wire from the Arduino. This may sound complicated, but it is really simple. Painfully simple in fact.

Whenever building a circuit with multiple DC voltage sources, or connecting together different circuit boards, their ground wires must be connected.


Just as it is important to have common ground between all participants in a conversation, it is important to have a common ground when working with electronics. Have a shared ground connection puts all of the voltages on the same page, and allows them to communicate.

Speaking of communicating, connect the signal wire to Digital Pin 9 on the Arduino.


Controlling a Standard Servo

Upload the following code to the Arduino to make the Servo move back and forth:


Controlling a Continuous Servo



Upload the following code to make the motor rotate clockwise:



To make the motor spin counterclockwise upload this code:

{
    "id": "quiz-1",
    "question": "Continuos servos allow you to control",
    "answers": [
        {
            "title": "Speed and direction",
            "correct": true
        },
        {
            "title": "Speed and position",
            "correct": false
        }
    ],
    "correctNotice": "Right! Way to go.",
    "incorrectNotice": "Errr. Wrong. Try again!"
}
{
    "id": "quiz-4",
    "question": "Metal gear servos are good when you need more",
    "answers": [

        {
            "title": "Speed",
            "correct": false
        },
        {
            "title": "Torque",
            "correct": true
        }
    ],
    "correctNotice": "Correct-o",
    "incorrectNotice": "Errr. Wrong. Try again!"
}
{
    "id": "quiz-3",
    "question": "Servos should be powered by",
    "answers": [
        {
            "title": "The 5V pin on the Arduino",
            "correct": false
        },
        {
            "title": "Their own separate power supply",
            "correct": true
        },
        {
            "title": "Divine intervention",
            "correct": false
        },
        {
            "title": "None of the above",
            "correct": false
        }
    ],
    "correctNotice": "Yes!",
    "incorrectNotice": "Just wrong. Try again!"
}

CLASS PROJECT

Share a photo of your finished project with the class!

Nice work! You've completed the class project