Servo Controllers

Servos are one of the most commonly used components in tandem with Arduinos. A servo motor is a self-contained electrical device, that rotates parts of a machine with high efficiency and with great precision. The output shaft of this motor can be moved to a particular angle, position, and velocity that a regular motor does not have. Because of this precision and the general small sizes and power needs of servos, they make for perfect companions for Arduinos when you need an actuator.

Types of Servos

Positional Rotation

Positional Rotation Servos can only rotate from 0° to 180° or 0° to 270°. These are used when the degree of rotation needs to be very precise. 

Continuous Rotation

Continuous Rotation Servos have an infinite degree of rotation. These are used when precision isn't required but rather speed and direction.

Linear

Linear Servos are functionally the same as other servos but the rotational movement of the servo output is converted to linear movement. This can be done with a series of specialized gears.

Inside a Servo

All Servos have a motor, set of gears, casing, and control unit. Depending on the type of servo and precision of its rotation, there are two main methods of tracking the position.

Potentiometer

A potentiometer is a variable resistor. These use a track of carbon with specific resistance to vary resistance as the shaft spins. When the resistance changes, the control unit will read a voltage drop. Depending on the voltage drop, the servo will be able to tell what position is in. This works in the opposite way as well where you can input a voltage for the potentiometer to meet which will correlate to degrees turned. These are usually found in 180° or 270° servos since potentiometers can only spin about the same distance. 

Encoder

Encoders work by measuring the distance a disc rotates where each unit will be a degree or less. This disc will sometimes be a fine tooth gear that will count each tooth that passes, or on more precise encoders, a laser that passes through equally spaced slots that is read by a light sensor. The light sensor is attached to a control unit that will output a high pulse square wave each time a light is sensed. This can further be associated and read to be a degree or less at a time. 

Controlling a Servo with PWM

Varying the pulse width between 1ms and 2ms will move the servo shaft through the full 180 degrees of its travel. You can bring it to rest at any angle you desire by adjusting the pulse width accordingly

Controlling a Continuous Servo with PWM

Varying the pulse width between 1ms and 1.5ms will make the motor spin counterclockwise with the shorter pulse widths causing the motor to spin faster.

Varying the pulse width between 1.5ms and 2ms will cause the motor to rotate clockwise with the longer pulses resulting in a faster speed.

Servo Connections

The three connections to the servo motors are as follows:

Arduino Servo Project Examples

Sweeps

A sweep while controlling a servo is when the Arduino commands the servo to spin from  0° to 180° and back to  0°, then repeats. This is a very basic Arduino Servo project but is fundamental in understanding how to control a servo. This can be done with  

Sweeps and Counts

Counts do exactly what they sound like- they count up or down. You can set ranges for counts and how much each unit will count for. Counts will count up or down to any variable you set. In the case of a servo, a good variable to use would be "position" or "degrees." In this example, "pos" was used as shorthand for position. Since servos typically range from 0° to 180°, you can define your count to be between 0 and 180. Nested in the count should be the command to rotate the servo- in this case you can rotate the servo to the same variable "pos" as the position in degrees since we already defined the 0° to 180° range above. Typically, you will also want to add a wait command to allow the servo a buffer period in instruction- this will avoid glitches where the servo tries to implement multiple commands at once. 

From there, just copy and past the count command with everything nested inside and swap 0° to 180° to 180° to 0°. Now you will have a servo that will sweep from  0° to 180° and back to  0° then repeat.

Sensor Controlled

Controlling a servo's rotation with a potentiometer or any other analog sensor is even easier. To do this, you can just map the input from the sensor to be within the servo's 0° to 180° range. In the example to the right, when you adjust the potentiometer's dial, the Arduino reads the sensors input and outputs a position for the servo that is proportional to the mapping of the potentiometer and servo.  This can be done from any range to any range depending on the sensitivity or direction needed from the servo.