To drive a servo motor with a Raspberry Pi, you must use an external I2C PWM driver like the PCA9685 and a dedicated 5V power supply capable of delivering at least 1A per standard servo. The Pi's 3.3V GPIO pins cannot source the required current and lack sufficient hardware PWM channels to generate the precise 50Hz pulse widths servos demand. Attempting to power a servo directly from the Pi's 5V rail will almost certainly cause a brownout and reboot the board under load.
Motor Selection: Why a Servo and Not a Stepper or DC?
When designing a robotic arm, camera gimbal, or automated valve, the first decision is matching the motor type to the load profile. Servos, steppers, and standard DC motors are fundamentally different in how they deliver torque and how they are controlled. Treating a stepper and a servo as interchangeable is a common bench mistake that leads to over-engineered or under-powered builds.
A servo motor fits your load profile if you need high holding torque at low speeds, precise absolute angular positioning (typically within a 180° or 270° arc), and a compact physical footprint. Unlike steppers, which require continuous current to hold position and can lose steps under sudden dynamic loads, standard hobby servos use an internal potentiometer and closed-loop feedback to aggressively correct positional errors.
| Motor Type | Torque Curve Profile | Control Needs | Typical Cost (USD) | Best Use Case |
|---|---|---|---|---|
| Hobby Servo (e.g., MG996R) | High stall torque at zero speed; drops off rapidly at high RPM. | 50Hz PWM pulse (1-2ms width). Closed-loop internal. | $8 - $25 | Robotic joints, RC steering, camera pan/tilt. |
| Stepper (e.g., NEMA 17) | Flat torque curve up to mid-range RPM; resonant vibration at low speeds. | Step/Direction pulses via driver (A4988/TMC2209). Open-loop. | $15 - $40 (+ driver) | 3D printers, CNC routers, linear actuators. |
| Brushed DC (e.g., 775) | Peak torque at stall; linear drop to zero torque at max no-load RPM. | H-Bridge for direction; PWM for speed. Requires external encoder for position. | $10 - $30 (+ encoder) | Drive wheels, conveyor belts, high-speed spindles. |
| Brushless DC (BLDC) | High torque density across a wide RPM range; highly efficient. | 3-phase ESC with Hall sensors or sensorless back-EMF zero-crossing detection. | $40 - $150+ | Drones, high-performance robotics, gimbals. |
Sizing Your Servo: Torque Curves and Load Profiling
Hobby servos are rated by their stall torque, usually expressed in kg-cm or oz-in. This is the maximum torque the motor can exert before it stalls. However, you should never size a servo based purely on static stall torque. When a servo accelerates a load, dynamic forces multiply the stress on the internal nylon or metal gears.
Worked Load Example: Robotic Forearm
Let's size a servo for a robotic forearm that needs to lift a 200g payload. The forearm itself is 15cm long and weighs 100g. We need to find the required torque at the elbow joint.
- Calculate Payload Torque: The 200g (0.2 kg) payload is at the end of the 15cm (0.15m) arm.
Force = 0.2 kg × 9.81 m/s² = 1.96 N.
Torque = 1.96 N × 0.15 m = 0.294 Nm (approx 3.0 kg-cm). - Calculate Arm Weight Torque: The arm's center of mass is roughly in the middle (7.5cm or 0.075m).
Force = 0.1 kg × 9.81 m/s² = 0.98 N.
Torque = 0.98 N × 0.075 m = 0.073 Nm (approx 0.75 kg-cm). - Total Static Torque: 3.0 + 0.75 = 3.75 kg-cm.
- Apply Dynamic Safety Factor (2.0): 3.75 kg-cm × 2.0 = 7.5 kg-cm.
Based on this math, a micro servo like the SG90 (rated at 1.8 kg-cm) will strip its nylon gears immediately. You need a metal-gear servo like the TowerPro MG996R, which offers 10 to 13 kg-cm of stall torque depending on whether you feed it 4.8V or 6.0V, giving you the necessary headroom for acceleration and mechanical inefficiencies.
Wiring and PWM Control: Bypassing the Pi's GPIO Limits
The Raspberry Pi's hardware PWM pins are limited, and software PWM (bit-banging) via standard GPIO pins introduces severe jitter due to Linux OS interrupts. A jittery PWM signal causes servos to twitch, draw excess current, and overheat. Furthermore, the Pi's 3.3V logic high is often on the very edge of what a 5V servo considers a valid 'high' signal, leading to erratic behavior.
To solve this, we use an external I2C PWM controller. The NXP PCA9685 is the industry standard for this. It offloads the 50Hz pulse generation to dedicated hardware and shifts the logic level to a clean 5V.
Servo Terminal Identification
Standard hobby servos use a 3-pin JST or Dupont connector. The wire colors almost universally follow this convention:
- Signal (Orange or White): Carries the 50Hz PWM control pulse.
- VCC (Red): Positive power supply (4.8V to 6.0V for standard, up to 8.4V for high-voltage servos).
- GND (Brown or Black): Ground reference. Must be shared with the Pi's ground.
Wiring the Pi, PCA9685, and Servo
You must use two separate power domains: the Pi's logic power and the servo's high-current power. Never route servo stall current through the Raspberry Pi's GPIO header 5V pins.
| Raspberry Pi Pin | PCA9685 Board Pin | Function | Notes & Warnings |
|---|---|---|---|
| Pin 1 (3.3V) | VCC | I2C Logic Power | Powers the PCA9685 chip itself, NOT the servos. |
| Pin 3 (GPIO 2) | SDA | I2C Data | Ensure I2C is enabled in raspi-config. |
| Pin 5 (GPIO 3) | SCL | I2C Clock | Default I2C bus 1 on all modern Pi models. |
| Pin 6 (GND) | GND | Logic Ground | Establishes common ground reference for I2C. |
| External 5V PSU (+) | V+ (Screw Terminal) | Servo Power | Use a 5V 3A+ switching supply. Add reverse-polarity protection. |
| External 5V PSU (-) | GND (Screw Terminal) | Servo Ground | Must also tie to Pi GND to complete the PWM circuit. |
Failure Signatures: Diagnosing Hum, Overheat, and Stall
When integrating servos with embedded Linux systems, failures rarely mean the motor is dead. They usually point to power delivery issues, signal integrity problems, or mechanical binding. Here is how to read the physical failure signatures on the bench.
1. The 'Humming' or Twitching Servo
Symptom: The servo vibrates audibly, twitches back and forth by a few degrees, and fails to hold a steady position.
Cause: PWM signal jitter or a mismatched PWM frequency. Servos expect a strict 50Hz frequency (a pulse every 20ms). If your software library is calculating timing based on CPU cycles rather than hardware timers, Linux background tasks will stretch the pulse width.
Fix: Verify you are using a hardware PWM driver like the PCA9685. If using direct GPIO via libraries like gpiozero, ensure you are using the `AngularServo` class with hardware PWM pins enabled, and avoid running heavy CPU loads on the Pi simultaneously.
2. Overheating and Thermal Shutdown
Symptom: The servo casing becomes too hot to touch within 30 seconds, and it may stop responding entirely.
Cause: The servo is being commanded to a position that is physically blocked (a hard stop). Because it uses closed-loop feedback, the internal H-bridge will pump maximum stall current into the motor continuously, trying to reach the target angle.
Fix: Check your mechanical linkages for binding. In your Python/C++ code, implement a timeout: if the servo is commanded to move but the current draw (measured via an inline INA219 sensor) spikes to stall levels for more than 500ms, cut the PWM signal to 0% duty cycle to save the motor.
3. System Stall and Pi Brownout
Symptom: The Raspberry Pi reboots, drops USB devices, or throws a low-voltage warning (the lightning bolt icon) the moment the servo begins to move.
Cause: Inadequate power supply amperage or excessive voltage drop across thin wires. A single MG996R can draw 2.5A at stall. If you are powering three of them from a 3A supply, the voltage will collapse below the Pi's 4.63V brownout threshold when they move simultaneously.
Fix: Calculate the worst-case stall current for all servos on the rail. Use a power supply rated for at least 120% of that total. Upgrade your power wiring from standard 22AWG jumper wires to at least 16AWG silicone wire for the main power bus, and verify the voltage at the PCA9685 screw terminals with a multimeter under load. For more on Pi power diagnostics, consult the official Raspberry Pi hardware documentation.






