10 Servo Motors: Position, Motion, and Power
10.1 Start With the Decision
A vent may be told to half open yet press against its stop. Position commands need motion limits and enough supply current.
10.2 Route Overview
This is part 1 of 2. Continue with Servo Motors: Calibration and Applications.
10.3 Part Objectives
- Map PWM pulse width to servo position.
- Budget startup and stall current for one or more servos.
10.4 Start With the Story
Move One Vent and Prove Where It Stopped
Picture a smart vent commanded to half open that presses against its end stop instead. The command alone cannot show whether the mechanism moved safely or reached the requested angle.
An actuator means a part that turns an electrical command into physical action. Pulse-width modulation means controlling a signal by changing how long each pulse stays on; it is often shortened to PWM.
Command three positions under light and heavy airflow, then remove control power. Record pulse width, supply voltage, current, angle, travel time, stall, and safe resting state.
This runway does not prove that one servo fits every load. The deeper sections explain torque, pulse calibration, gearing, power margin, linkage geometry, feedback, and safe travel limits.
Picture a smart vent that must open halfway, hold there against airflow, and close safely when the controller loses contact. A bare motor can spin, but the useful story is angle, holding torque, travel limits, and evidence that the louver reached the intended position.
A servo is attractive because it packages motor, gears, position feedback, and control electronics into one actuator. The design still has to prove power margin, linkage geometry, calibrated pulse widths, and safe behavior at the ends of travel.
Motor Max
“Sensing decides; actuating commits — and a commit to the physical world needs a safe stop.”
This is Max’s home chapter — he is a servo. His Motion Check covers the motion committed, the pulse and torque limits, and the stop that proves it parked.
- Start With the Story
- In 60 Seconds
- Phoebe’s Field Notes: What The +-5 us Deadband Is Actually Fighting
- Key Concepts
- Quick Check: Servo Selection
- For Beginners: Servo Motors
- How It Works: Servo Motor Internal Feedback Loop
- Servo Motor Fundamentals
- Putting Numbers to It
- Checkpoint: Pulse Width Means Position
- Servo vs Stepper Comparison
- Tradeoff: Servo Motor vs. Stepper Motor for Positioning
- Basic Servo Control
- Try It: Servo Sweep Simulator
- Checkpoint: Motion Code Has Limits
- Smooth Motion with Interpolation
- Try It: Easing Curve Explorer
- Interactive Lab: Servo Control
- Try It Yourself: Control a Servo Motor
- Common Servo Specifications
- Power Supply Warning
- Try It: Servo Power Budget Calculator
- Checkpoint: Power Is a Servo Requirement
- RC Servo Motor: A self-contained motor system integrating a DC motor, gearbox, position feedback potentiometer, and control electronics; position is commanded by a 50 Hz PWM signal where pulse width (1-2 ms) maps to 0-180 degree output angle
- Servo Pulse Width Protocol: Standard servo control: 50 Hz PWM (20 ms period); pulse width 1.0 ms = minimum angle (~0 degrees), 1.5 ms = center (~90 degrees), 2.0 ms = maximum (~180 degrees); exact angles vary by servo model and require calibration
- Servo Torque Ratings: Specified in kg.cm or N.cm at a defined voltage; represents the force x distance at the output horn; a 2 kg.cm servo can lift 2 kg at 1 cm from the servo axis, or 0.2 kg at 10 cm; torque drops significantly when operating below rated voltage
- Continuous Rotation Servo: A servo modified (or designed) to rotate continuously rather than position to an angle; pulse width controls speed and direction: 1.5 ms = stop, <1.5 ms = one direction, >1.5 ms = other direction; used for wheeled robot drive systems
- Servo Deadband: A small range of pulse widths (typically +-5 us) around the current position where the servo does not respond; prevents jitter from small PWM timing variations; a servo with a wide deadband appears sluggish in fine position control
- Stall Torque vs. No-Load Speed: Stall torque is the maximum torque at zero speed; no-load speed is the maximum RPM with no load; real operating points lie between these extremes on the torque-speed curve; operating near stall continuously overheats the motor
- Servo Horn and Mounting: The output hub that connects the servo shaft to the mechanical linkage; plastic horns are included with servos; metal horns are available for higher-torque applications; improper linkage geometry causes binding and reduces effective servo range
- Servo Library (Arduino/ESP32): The Arduino Servo.h library abstracts pulse width calculation; Servo::attach(pin) starts 50 Hz PWM; Servo::write(angle) converts degrees to microseconds automatically; Servo::writeMicroseconds(us) provides direct microsecond control for precision calibration
Learning Objectives
After completing this chapter, you will be able to:
- Explain servo motor construction and closed-loop operating principles
- Control servo position using PWM pulse width mapping
- Interface single and multiple servos with ESP32
- Implement smooth motion profiles using interpolation
- Build coordinated multi-servo systems (robotic arms, pan-tilt)
- Evaluate tradeoffs between servo and stepper motors for positioning applications
A servo motor is like a precise pointing finger — you tell it exactly what angle to point to, and it moves there and holds that position. Unlike a regular motor that just spins continuously, a servo can rotate to a specific angle (say 90 degrees) and stay there. This makes servos perfect for things like robotic arms, camera mounts that need to pan and tilt, or smart vents that open to a precise position.
A servo motor is like a self-driving car for rotation - you give it a destination (angle), and it figures out how to get there.
Inside every servo:
- DC motor: Provides the actual rotation force
- Gear reduction: Trades speed for torque (makes it strong but slow)
- Potentiometer: A sensor that measures the current shaft angle
- Control circuit: The “brain” that compares where you want to be vs where you actually are
The closed-loop magic:
- You send a PWM pulse: “Go to 90 degrees”
- The servo reads its potentiometer: “I’m currently at 45 degrees”
- The control circuit calculates: “I need to turn 45 degrees clockwise”
- It drives the motor until the potentiometer reads 90 degrees
- It then holds that position, fighting any external force that tries to move it
Why this matters: Unlike a DC motor (which you must monitor with an external encoder), the servo is self-contained. Send the pulse, and it handles everything else. This is why hobby servos are perfect for beginners - one pin, one library call, instant position control.
10.5 Servo Motor Fundamentals
The opening sections named the package. Now focus on the control question: what does the microcontroller actually send, and what does the servo do with it?
Servo motors provide precise angular positioning (typically 0-180 degrees) using command pulses. Inspect Figure before treating that convenience as a single component: the case hides a motor, gearbox, feedback sensor, and controller, while the horn exposes the mechanical output.
In Figure, read from the three-wire lead to the blue case, output shaft, and horn. Power and ground feed the internal loop, the signal wire carries the target, and the horn transfers limited-angle torque into a linkage. The package simplifies control but does not remove stall-current or load-margin checks.
Characteristics:
- Precise position control
- Built-in feedback loop
- Limited rotation range (standard servos: 0-180 degrees)
- Easy to control with PWM
- Self-correcting (closed-loop)
10.5.1 Internal Components
Servo motors integrate a complete feedback control system in a compact package:
- DC Motor Core: Provides rotational force
- Gear Reduction System: Amplifies torque, reduces speed
- Potentiometer: Position feedback sensor
- Control Circuit: Compares commanded vs actual position
The internal potentiometer continuously measures shaft position, and the control circuit compares this to the commanded position from the PWM signal. This closed-loop design maintains position accuracy even under varying loads.
10.5.2 PWM Position Control
Servo motors use pulse width, not motor-power duty cycle, to determine position. Inspect Figure 10.1 from the common 20 ms frame to the three different high-pulse widths before mapping any angle.
Read Figure 10.1 from the 1 ms pulse to 1.5 ms and then 2 ms: commanded angle advances while the repetition period stays 20 ms. The servo interprets high-time as a position target, so changing frame duty cycle without respecting the valid pulse window is not equivalent to controlling DC-motor power.
Key parameters:
- 50 Hz frequency (20 ms period) - Standard for hobby servos
- 1 ms pulse = 0 degrees (5% duty cycle)
- 1.5 ms pulse = 90 degrees (7.5% duty cycle, center position)
- 2 ms pulse = 180 degrees (10% duty cycle, maximum rotation)
At 50 Hz, the period is ms. A 1.5 ms pulse for 90° means duty cycle . To command 45°, interpolate: pulse width ms. For smooth motion from 0° to 180° over 1 second at 50 Hz, you send 50 commands with angular step per frame. Current draw spikes during motion (500mA) but drops to holding current (~100mA) once positioned, so energy per 2-second actuation is joules (0.00083 Wh).
Interactive Calculator: Angle to Pulse Width
Max’s Motion Check
- Commit: move to 45 degrees: pulse
1 + (45/180)(2-1) = 1.25 ms, sent every 20 ms. - Limits: a 1 s sweep at 50 Hz: 50 commands, 3.6 degrees each.
- Safe stop: arrival shows in the current: 500 mA moving falls to ~100 mA holding.
Checkpoint: Pulse Width Means Position
You now know:
- Hobby servos repeat a 20 ms frame at 50 Hz; the high-pulse width, not average duty cycle, carries the angle.
- The standard map is 1 ms to 0 degrees, 1.5 ms to 90 degrees, and 2 ms to 180 degrees, with calibration required for real hardware.
- A 45 degree command is 1.25 ms, and a 1 second 0-180 degree sweep at 50 Hz sends 50 commands, or 3.6 degrees per frame.
Important: Servo libraries handle the timing. You just write servo.write(90) for 90 degrees!
10.6 Servo vs Stepper Comparison
Option A: Servo motor: Range 0-180 degrees, resolution around 1 degree, holding torque from light-duty to high-torque packages, 5V-class power for many hobby servos, closed-loop feedback maintains position under load, simple PWM control (1 GPIO pin)
Option B: Stepper motor: Range unlimited rotation, common full-step resolution around 1.8 degrees/step (200 steps/rev), micro-stepping can improve command granularity, higher holding torque options, separate driver and higher-current supply, open-loop control requires calibration or homing, requires driver board plus multiple GPIO pins
Decision Factors: For IoT applications needing simple angular positioning within 180 degrees (smart vents, valve actuators, pan-tilt cameras), servos win on simplicity and integrated feedback. For continuous rotation, high precision, or high torque motion axes, steppers or industrial servos may be better. Servos draw the most current when moving or resisting load; steppers often draw holding current continuously. For intermittent positioning tasks, this can make servos easier to power, but the real energy budget depends on load, hold torque, and duty cycle.
10.7 Basic Servo Control
With the timing model in place, the next task is firmware discipline: attach the servo with known pulse limits, move in bounded steps, and avoid sudden mechanical shocks.
10.7.1 Single Servo Control
#include <ESP32Servo.h>
Servo myServo;
#define SERVO_PIN 18
void setup() {
Serial.begin(115200);
// Attach servo (ESP32 uses different timers)
myServo.attach(SERVO_PIN, 500, 2400); // Min/max pulse width in microseconds
Serial.println("Servo Controller Ready");
}
void loop() {
// Sweep from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos++) {
myServo.write(pos);
Serial.print("Position: ");
Serial.println(pos);
delay(15);
}
delay(1000);
// Sweep back from 180 to 0 degrees
for (int pos = 180; pos >= 0; pos--) {
myServo.write(pos);
Serial.print("Position: ");
Serial.println(pos);
delay(15);
}
delay(1000);
}
10.7.2 Multi-Servo Robotic Arm
Read the arm example as a coordinated timing path. Start with the four named joint states, then follow moveToPosition() as it samples each current angle and advances every joint through the same number of 20 ms frames. Finally trace the pick-and-place sequence through approach, grip, transfer, release, and home. Coordination reduces sudden mechanism stress, but the shared supply must still tolerate simultaneous servo current.
#include <ESP32Servo.h>
Servo baseServo, shoulderServo, elbowServo, gripperServo;
struct RobotPosition { int base, shoulder, elbow, gripper; };
RobotPosition homePos = {90, 90, 90, 90};
RobotPosition pickPos = {45, 45, 45, 90};
RobotPosition placePos = {135, 45, 45, 45};
void setup() {
Serial.begin(115200);
baseServo.attach(18, 500, 2400);
shoulderServo.attach(19, 500, 2400);
elbowServo.attach(21, 500, 2400);
gripperServo.attach(22, 500, 2400);
moveToPosition(homePos, 1000);
Serial.println("Commands: h=home, p=pick, l=place, s=sequence");
}
void loop() {
if (Serial.available()) {
switch(Serial.read()) {
case 'h': moveToPosition(homePos, 1500); break;
case 'p': moveToPosition(pickPos, 1500); break;
case 'l': moveToPosition(placePos, 1500); break;
case 's': pickAndPlaceSequence(); break;
}
}
}
// Smooth interpolated motion — all joints move simultaneously
void moveToPosition(RobotPosition target, int duration) {
int cB = baseServo.read(), cS = shoulderServo.read();
int cE = elbowServo.read(), cG = gripperServo.read();
int steps = duration / 20;
for (int i = 0; i <= steps; i++) {
float p = (float)i / steps;
baseServo.write(cB + (target.base - cB) * p);
shoulderServo.write(cS + (target.shoulder - cS) * p);
elbowServo.write(cE + (target.elbow - cE) * p);
gripperServo.write(cG + (target.gripper - cG) * p);
delay(20);
}
}
void pickAndPlaceSequence() {
moveToPosition(pickPos, 1500); delay(500); // Move to pick
gripperServo.write(45); delay(500); // Close gripper
moveToPosition(placePos, 2000); delay(500); // Move to place
gripperServo.write(90); delay(500); // Open gripper
moveToPosition(homePos, 1500); // Return home
}
Checkpoint: Motion Code Has Limits
You now know:
attach(pin, 500, 2400)records the pulse window the library should use before anywrite(angle)command.- A sweep loop is easy, but coordinated motion needs shared timing; the robotic arm uses
duration / 20steps so joints arrive together. - Home, pick, and place positions are explicit command records:
{90, 90, 90, 90},{45, 45, 45, 90}, and{135, 45, 45, 45}.
10.8 Smooth Motion with Interpolation
For professional-quality motion, use smooth acceleration/deceleration profiles:
// Ease-in-out interpolation for smooth motion
float easeInOut(float t) {
return t < 0.5 ? 2 * t * t : 1 - pow(-2 * t + 2, 2) / 2;
}
void smoothMove(Servo& servo, int startPos, int endPos, int duration) {
int steps = duration / 20;
for (int i = 0; i <= steps; i++) {
float t = (float)i / (float)steps;
float easedT = easeInOut(t);
int pos = startPos + (endPos - startPos) * easedT;
servo.write(pos);
delay(20);
}
}
10.9 Interactive Lab: Servo Control
Interactive Challenges:
- Potentiometer Control: Use a potentiometer to control servo position (0-180 degrees)
- Button Presets: Add buttons for preset positions (0, 45, 90, 135, 180 degrees)
- Smooth Sweep: Implement smooth back-and-forth sweeping motion
10.10 Common Servo Specifications
The browser lab proves the command path. The hardware table asks the next question: can the selected servo and supply survive the load when motion starts or stalls?
| Model | Voltage | Torque | Speed | Weight | Use Case |
|---|---|---|---|---|---|
| SG90 | 4.8-6V | 1.8 kg-cm | 0.1s/60 deg | 9g | Light loads, prototyping |
| MG90S | 4.8-6V | 2.2 kg-cm | 0.1s/60 deg | 13.4g | Metal gears, higher torque |
| MG996R | 4.8-7.2V | 11 kg-cm | 0.17s/60 deg | 55g | Robotic arms, heavy loads |
| DS3218 | 4.8-6.8V | 21 kg-cm | 0.16s/60 deg | 60g | Industrial, waterproof |
Do NOT power multiple servos from the ESP32 5V pin. Use an external servo supply sized for peak current. Connect ESP32 GND to power supply GND (common ground).
SG90: Up to 600mA stall current each MG996R: Up to 2.5A stall current each
A 3-servo arm with high-torque servos may need several amps of 5V supply current during startup or stall.
Checkpoint: Power Is a Servo Requirement
You now know:
- Small servos are not small loads at startup: SG90 can reach 600 mA stall, MG90S 700 mA, and MG996R 2.5 A.
- Multiple servos need a separate 5 V rail with common ground to the ESP32; the controller should send the signal, not supply the surge current.
- Staggering movements reduces peak current, but the power budget still needs margin for the worst credible simultaneous load.
10.11 Continue to the Next Part
Carry this evidence into Servo Motors: Calibration and Applications, which begins with Pan-Tilt Camera Mount.
