To use a standard hobby servo, you must send a 50 Hz PWM (Pulse Width Modulation) signal with a pulse width between 1.0 ms (0°) and 2.0 ms (180°) to the control wire, while supplying dedicated 5V-7.4V power to the VCC and GND pins. Unlike continuous DC motors, a servo contains an internal potentiometer and control board that reads this PWM pulse and drives the motor to match the commanded angle, holding it there against physical resistance.

This guide assumes you are working with standard RC-style hobby servos (analog or digital) for embedded projects, not industrial AC servo drives used in CNC machining. We will cover how to select the right actuator, size it for your mechanical load, wire it safely to a microcontroller, and troubleshoot the most common failure modes.

Servo vs. Stepper vs. DC: Choosing the Right Actuator

A common mistake on the workbench is treating steppers and servos as interchangeable because both can move to precise angles. They are fundamentally different. A standard RC servo is a closed-loop system; it knows its position and will fight to maintain it. A stepper motor is open-loop; it moves in discrete steps but has no feedback if it skips a step under heavy load.

Use the table below to determine which motor type fits your specific load profile.

Motor Type Torque Curve & Behavior Control Needs Avg Cost Best Load Profile
RC Servo Max torque at zero speed (stall). Fights to hold position. Direct 50Hz PWM from MCU GPIO. No external driver needed for 1-2 units. $2 - $25 Robotic arms, pan-tilt camera mounts, RC steering.
Stepper (NEMA 17) High holding torque, but drops sharply as speed increases. Requires dedicated stepper driver (A4988, TMC2209) and step/dir pulses. $12 - $30 3D printers, CNC routers, linear actuators.
DC Gearmotor Linear torque drop as speed increases. Zero holding torque. H-Bridge (L298N, DRV8871) for direction and speed PWM. $5 - $15 Drive wheels, conveyor belts, continuous rotation.
Decision Framework: Choose a servo when you need high holding torque at low speeds with minimal wiring. Choose a stepper when you need continuous, high-speed rotation with precise positional accuracy over thousands of revolutions without mechanical drift.

Sizing Your Servo: Torque, Load, and the 50% Rule

Servo torque is rated in kilogram-centimeters (kg-cm) or ounce-inches (oz-in). This rating represents the stall torque—the maximum weight the servo can hold at the end of a 1 cm (or 1 inch) lever arm before the motor stalls and strips its gears.

The 50% Sizing Rule of Thumb: Never size a servo to operate at its rated stall torque. Continuous operation at stall will melt the internal potentiometer and burn out the DC motor. Always select a servo with a rated torque at least double (50% safety margin) your calculated static load.

Worked Load Example: Pan-Tilt Camera Mount

Suppose you are mounting a 400g Raspberry Pi camera module on a pan-tilt bracket. The center of gravity of the camera is 6 cm away from the tilt servo's output shaft.

  • Static Load: 400g (0.4 kg)
  • Lever Arm: 6 cm
  • Calculated Torque: 0.4 kg × 6 cm = 2.4 kg-cm
  • Dynamic Factor: Add 20% for acceleration/deceleration forces = 2.88 kg-cm
  • Required Servo Rating (x2 safety margin): 2.88 × 2 = 5.76 kg-cm

Based on this math, a micro SG90 (1.8 kg-cm) will instantly strip its plastic gears. You need at least an MG996R (13 kg-cm) to handle the load reliably with headroom for vibration and dynamic movement.

Model Stall Torque (6V) Weight Gear Material Stall Current Typical Price
Tower Pro SG90 1.8 kg-cm 9g Plastic (Nylon) 0.5A $2.00
Tower Pro MG90S 2.2 kg-cm 13g Metal (Brass) 0.8A $4.50
Tower Pro MG996R 13.0 kg-cm 55g Metal (Steel) 2.5A $6.00
DS3218 20kg 20.0 kg-cm 60g Metal (Steel) 3.0A $14.00
LXD35 35kg 35.0 kg-cm 120g Metal (Steel) 4.5A $32.00

Wiring, Terminals, and ESP32/Arduino Integration

Standard hobby servos use a 3-pin JST or Dupont connector. The wire colors follow a strict industry standard, though the signal wire color can vary slightly by manufacturer.

  • Ground (GND): Brown or Black. Must be tied to the microcontroller's GND and the power supply's GND.
  • Power (VCC): Red. Requires 4.8V to 6.0V for standard servos, up to 7.4V for high-voltage (HV) digital servos.
  • Signal (PWM): Orange, Yellow, or White. Connects to a PWM-capable GPIO pin on your MCU.
Power Supply Warning: Never power an MG996R or larger servo directly from the 5V pin of an Arduino Uno or the USB VBUS of an ESP32-WROOM-32. A stalled MG996R pulls 2.5A. This will instantly trip the USB polyfuse, brownout the microcontroller, or melt the PCB traces. Use a dedicated 5V buck converter (like an LM2596) rated for at least 3A per servo, and ensure the buck converter GND is bonded to the MCU GND.

ESP32 PWM Control Code

While the classic Arduino Servo.h library works for 8-bit AVR boards, it is deprecated and often causes watchdog resets on the ESP32. For the ESP32, use the native LEDC (LED Control) peripheral, which handles the 50Hz timing in hardware without blocking the CPU. Note that in Arduino Core v3.x for ESP32, the setup functions have been simplified.

#include <Arduino.h>

const int servoPin = 13;
const int freq = 50;       // 50Hz standard for RC servos
const int resolution = 16; // 16-bit resolution (0-65535)

// 50Hz = 20ms period. 
// 1ms pulse (0 deg)   = (1/20) * 65535 = 3276
// 1.5ms pulse (90 deg)= (1.5/20) * 65535 = 4915
// 2ms pulse (180 deg) = (2/20) * 65535 = 6553

void setup() {
  // Attach the pin to the LEDC peripheral with 50Hz and 16-bit resolution
  ledcAttach(servoPin, freq, resolution);
}

void loop() {
  // Move to 90 degrees (center)
  ledcWrite(servoPin, 4915);
  delay(2000);
  
  // Move to 0 degrees
  ledcWrite(servoPin, 3276);
  delay(2000);
  
  // Move to 180 degrees
  ledcWrite(servoPin, 6553);
  delay(2000);
}

Driver Scaling: If your project requires more than two servos, GPIO routing and software timers become messy. Use a PCA9685 16-channel I2C PWM driver board (approx. $4). It offloads the 50Hz pulse generation to a dedicated IC and communicates via I2C, freeing up your ESP32 or Raspberry Pi Pico for sensor processing.

Diagnosing Servo Failure Signatures: Hum, Jitter, and Overheat

When a servo fails, it rarely just stops working; it gives you physical and electrical feedback. Here is how to read those failure signatures and fix them.

1. The 'Hum' or High-Frequency Jitter

Symptom: The servo holds position but vibrates rapidly, emitting a buzzing or humming sound. The horn oscillates by 1-2 degrees.

Causes & Fixes:

  • Noisy PWM Signal: Long, unshielded signal wires act as antennas, picking up EMI from nearby switching regulators or brushless motors. Fix: Keep signal wires under 15cm, or use a twisted-pair cable with the ground wire.
  • Ground Loop / Voltage Sag: If the MCU and servo share a thin ground wire, the servo's current spikes cause the MCU's ground reference to bounce, altering the perceived PWM pulse width. Fix: Use a star-ground topology where the power supply ground splits directly to the MCU and the servo.
  • Worn Potentiometer: The internal carbon-track potentiometer has developed a dead spot. Fix: Replace the servo; internal pot replacement is rarely cost-effective.

2. Overheat and Thermal Shutdown

Symptom: The servo casing becomes too hot to touch (>60°C), smells like melting plastic, and eventually stops responding.

Causes & Fixes:

  • Prolonged Stall: Think of a stalled servo like a kinked garden hose connected to a pump running at full pressure—the pump (your power supply) is pushing maximum current (e.g., 2.5A on an MG996R), but no mechanical work is being done, so all that energy turns into heat in the rotor windings. Fix: Implement software limits to prevent commanding the servo past its physical hard stops, and add a 2A hardware fuse on the VCC line.
  • Overvoltage: Feeding a standard 6V servo with a 2S LiPo (8.4V fully charged). Fix: Use a 5V UBEC (Universal Battery Eliminator Circuit) between the LiPo and the servo VCC.

3. Mechanical Stall and Gear Stripping

Symptom: The motor spins audibly, but the output shaft does not move, or it moves with a loud grinding noise.

Causes & Fixes:

  • Exceeded Static Load: The load torque exceeded the gear train's physical limits. On metal-gear servos, this usually strips the final output spline. On plastic servos, it shatters the intermediate gears. Fix: Recalculate your load using the 50% rule above and upgrade to a higher-torque model (e.g., moving from MG996R to DS3218).
  • Binding Linkage: The mechanical linkage (pushrod or arm) is binding at the extreme ends of travel, creating infinite resistance. Fix: Disconnect the horn and verify the mechanism moves freely by hand through the full range of motion.

For deeper integration with ESP32 peripherals and advanced timer configurations, refer to the official Espressif LEDC API documentation. Always verify your specific servo's datasheet for exact pulse width limits, as some digital servos use a narrower 900µs to 2100µs range for extended 270-degree travel.