Overview & Types
Servo motors are rotary actuators that provide precise angular positioning through an integrated closed-loop feedback system. The term “servo” comes from the Latin servus (servant) – these motors faithfully track a commanded position signal.
Common Types
- SG90 (Micro Servo): 9 g, plastic gears, 180° range, 1.8 kg·cm torque. Ideal for small projects, pan-tilt cameras, and lightweight robotics.
- MG90S (Metal Gear Micro): 13.4 g, metal gears for durability, 2.2 kg·cm torque. Upgrade path from SG90.
- MG996R (Standard Servo): 55 g, metal gears, 11 kg·cm torque at 6 V. Popular for robotic arms and RC vehicles.
- DS3218 (High-Torque Digital): 60 g, 21.5 kg·cm torque. Used in walking robots and heavy-duty applications.
- Continuous Rotation Servos: Modified servos where the potentiometer is replaced with fixed resistors, enabling 360° continuous rotation with speed/direction control instead of position.
Working Principle
A standard (positional) hobby servo uses a closed-loop control system:
- Input Signal: A 50 Hz PWM signal (20 ms period) where the pulse width encodes the desired angle.
- Error Detection: The internal control IC compares the pulse width to the potentiometer reading (actual position).
- Motor Drive: If there’s a difference, the control IC drives the DC motor to reduce the error.
- Gear Reduction: Gears reduce speed and multiply torque (typical ratio: 200:1 to 300:1).
- Feedback Loop: The potentiometer on the output shaft continuously reports position back to the control IC.
PWM Signal Mapping
| Pulse Width | Position | Notes |
|---|---|---|
| 500 μs | 0° (full left) | Some servos use 544 μs |
| 1000 μs | ~45° | |
| 1500 μs | 90° (center) | Neutral position |
| 2000 μs | ~135° | |
| 2500 μs | 180° (full right) | Some servos use 2400 μs |
Continuous Rotation Servos
In continuous rotation mode, the PWM signal controls speed and direction instead of position:
- 1500 μs: Stop (dead zone)
- < 1500 μs: Rotate one direction (speed proportional to deviation from 1500)
- > 1500 μs: Rotate opposite direction
Electrical & Mechanical Specifications
| Parameter | SG90 | MG996R | DS3218 |
|---|---|---|---|
| Voltage | 4.8–6 V | 4.8–7.2 V | 4.8–6.8 V |
| Stall Torque (6 V) | 1.8 kg·cm | 11 kg·cm | 21.5 kg·cm |
| Speed (no load, 6 V) | 0.1 s/60° | 0.14 s/60° | 0.16 s/60° |
| Weight | 9 g | 55 g | 60 g |
| Gear Type | Plastic | Metal | Metal |
| Rotation Range | 180° | 180° | 270° |
| Stall Current | ~360 mA | ~900 mA | ~1.5 A |
| Dead Band | 10 μs | 5 μs | 3 μs |
| Connector | 3-wire: Signal (orange/white), VCC (red), GND (brown/black) | ||
Driver Circuits
Direct PWM (Simple Setup)
Hobby servos include their own motor driver IC, so they can be controlled with a single GPIO pin producing a PWM signal. The microcontroller only provides the signal; power comes from a separate supply.
PCA9685 (Multi-Servo Controller)
The PCA9685 is a 16-channel, 12-bit PWM driver controlled via I²C. Essential for projects needing more than 2–3 servos:
- 16 independent PWM channels
- 12-bit resolution (4096 steps per channel)
- Adjustable frequency: 24–1526 Hz
- I²C address: 0x40 (configurable, up to 62 boards = 992 servos)
- External V+ terminal for servo power (up to 6 V)
Wiring Essentials
- Signal wire → PWM-capable GPIO pin (3.3 V logic OK for most servos)
- VCC wire → External 5–6 V regulated supply
- GND wire → Common ground (MCU + servo supply)
- Add a 470 μF electrolytic capacitor across the servo power supply to absorb current spikes
Control Methods
Angle-Based Position Control
The standard approach: map a desired angle (0–180°) to a pulse width (500–2500 μs) and send it 50 times per second. The internal controller handles the rest.
Smooth Motion Profiling
Instead of jumping to a target angle, gradually increment the position to create smooth, natural-looking motion. This reduces mechanical stress and current spikes:
- Linear interpolation: Move at constant angular velocity.
- Ease-in/ease-out: Accelerate and decelerate smoothly using sine or cubic curves.
Sweep & Scan Patterns
Common in sensor platforms (radar, lidar), pan-tilt cameras, and animatronics. The servo sweeps through a range while another system captures data at each position.
Code Example — Arduino & ESP32
Arduino: Basic Servo Control
// Servo control using Arduino Servo library
// Wiring: Signal→D9(PWM), VCC→External 5V, GND→Common
#include <Servo.h>
Servo myServo;
const int SERVO_PIN = 9;
void setup() {
Serial.begin(9600);
myServo.attach(SERVO_PIN, 500, 2500); // min/max pulse width
myServo.write(90); // Start at center
delay(500);
}
void smoothMove(int from, int to, int stepDelay) {
int step = (to > from) ? 1 : -1;
for (int pos = from; pos != to; pos += step) {
myServo.write(pos);
delay(stepDelay);
}
myServo.write(to);
}
void loop() {
Serial.println("Moving to 0 degrees");
smoothMove(90, 0, 15);
delay(1000);
Serial.println("Moving to 180 degrees");
smoothMove(0, 180, 15);
delay(1000);
Serial.println("Returning to center");
smoothMove(180, 90, 15);
delay(2000);
}
ESP32: Multi-Servo with LEDC
// Multi-servo control on ESP32 using LEDC PWM
// Wiring: Servo1→GPIO18, Servo2→GPIO19, VCC→External 5V
#include <Arduino.h>
// Servo configuration
struct ServoConfig {
int pin;
int channel;
int minUs; // 0 degrees pulse width
int maxUs; // 180 degrees pulse width
};
ServoConfig servos[] = {
{18, 0, 500, 2500}, // Pan servo
{19, 1, 500, 2500}, // Tilt servo
};
const int NUM_SERVOS = 2;
const int PWM_FREQ = 50; // 50 Hz = 20 ms period
const int PWM_RESOLUTION = 16; // 65536 steps
void setup() {
Serial.begin(115200);
for (int i = 0; i < NUM_SERVOS; i++) {
ledcSetup(servos[i].channel, PWM_FREQ, PWM_RESOLUTION);
ledcAttachPin(servos[i].pin, servos[i].channel);
}
Serial.println("Servos initialized");
}
void setServoAngle(int servoIdx, int angle) {
angle = constrain(angle, 0, 180);
int pulseUs = map(angle, 0, 180,
servos[servoIdx].minUs,
servos[servoIdx].maxUs);
// Convert microseconds to duty cycle
// Period = 20000 us, resolution = 65536
int duty = (pulseUs * 65536) / 20000;
ledcWrite(servos[servoIdx].channel, duty);
Serial.printf("Servo %d → %d° (pulse: %d us)\n",
servoIdx, angle, pulseUs);
}
void loop() {
// Pan-tilt sweep
for (int angle = 0; angle <= 180; angle += 10) {
setServoAngle(0, angle); // Pan
setServoAngle(1, 90); // Tilt center
delay(200);
}
delay(500);
for (int angle = 0; angle <= 180; angle += 10) {
setServoAngle(0, 90); // Pan center
setServoAngle(1, angle); // Tilt sweep
delay(200);
}
delay(1000);
}
Real-World Applications
Robotics
- Robotic arm joints (3–6 DOF)
- Walking robot legs (hexapod, biped)
- Gripper open/close mechanisms
- Pan-tilt camera platforms
RC & Aerospace
- RC aircraft aileron/elevator/rudder control
- RC car steering
- Drone gimbal stabilization
- Satellite antenna positioning
Advantages vs. Alternatives
| vs. Actuator | Servo Advantage | Servo Disadvantage |
|---|---|---|
| DC Motor | Built-in position feedback, precise angle control | Limited range (usually 180°), lower speed |
| Stepper Motor | Simpler wiring (3 wires), self-contained control | Generally lower torque-to-weight ratio |
| BLDC Motor | No external encoder/driver needed | Limited to ~180° (standard), lower power |
| Linear Actuator | Compact, fast response for rotary motion | Cannot provide linear force directly |
Limitations & Considerations
- Limited Rotation Range: Standard servos only cover 180° (some 270°). Continuous rotation servos sacrifice precise positioning.
- Jitter: Noise on the PWM signal causes visible oscillation. Use hardware timers (not software PWM) and keep signal wires short.
- Current Spikes: Stall current can be 5–10× the running current. Size power supplies accordingly and add bulk capacitors.
- Gear Backlash: Plastic gears in cheap servos exhibit backlash (dead zone when reversing direction). Metal gears reduce but don’t eliminate it.
- Holding Torque = Continuous Current: A servo holding position under load draws continuous current, generating heat. Duty-cycle limits apply.
- No True Feedback Output: Standard hobby servos don’t expose the potentiometer reading to the microcontroller. Smart servos (Dynamixel) provide digital feedback via serial.