How does a servo know where to point?
The ESP32 sends a tiny pulse 50 times every second. The length of each pulse is the message: short = turn one way, long = turn the other way.
🎯 Try this: drag the slider and watch only the width of the high pulse change, while the 20 ms period stays the same. Then switch servo type: the same angle needs a different pulse!
What is inside a servo?
A servo is a motor + gears + a position sensor + a tiny brain. The brain keeps comparing where the horn is to where you asked it to be, and pushes the motor until the error is zero.
🎯 Try this: grab the white horn and drag it away, then let go: it fights back! Next, crank Kp up to 12 and watch it overshoot and wobble. Turn Kp down and it gets lazy. Real servo makers tune this balance.
Fly the ESP32 drone with servos
On a fixed-wing drone, servos tilt control surfaces. Move the stick and see which servos turn, by how much, and how the plane responds.
Keys: ← → roll, ↑ ↓ pitch, Q E yaw
🎛️ Tune the auto-level (roll)
Press Run step test: the plane is tipped 30° and the ESP32 must level it. The chart shows what it does. Change the numbers and test again.
🎯 Try this: push the stick right and see the two ailerons move in opposite directions. Hit Gust to knock the plane over, then switch on Auto-level: the ESP32 reads its tilt sensor and commands the servos to level the plane. Finally try Flying-wing mix: two servos now do both jobs, so the code must mix pitch and roll.
A servo that keeps the camera level
When a drone tilts, a gimbal servo turns the opposite way so the camera keeps looking at the horizon. The ESP32 reads the tilt (IMU) and sets the servo angle.
🎯 Try this: start Turbulence, then turn stabilise on and off. Slow the servo down and the picture lags behind. Tilt past 90° and the servo runs out of range, so no gimbal can do the impossible.
Wire it up without frying anything
Servos draw big bursts of current when they move. Pick how to power them, press Move all servos and see what happens. Click a wire to learn what it does.
📌 ESP32 pin notes
GPIO 13, 14, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33 (any output-capable pin works with LEDC PWM).
GPIO 0, 2, 12, 15 (boot/strapping pins can glitch at start-up), GPIO 6–11 (flash), GPIO 34–39 (input only).
The ESP32 outputs 3.3 V logic. Most servos accept it on the signal wire even though they run on 5 V. If one twitches, add a level shifter.
ESP32Servo uses the LEDC PWM hardware: up to 16 channels, 4 timers. Call
ESP32PWM::allocateTimer() first.VCC→3V3, GND→GND, SDA→GPIO21, SCL→GPIO22 (I²C). Keep it away from motors and vibration-isolate it.
5 V BEC for servos. Power the ESP32 from the same battery via its own regulator or the BEC's VIN, never from a servo wire.
🎯 Try this: compare all four options. Only one is right for a real drone: a separate 5 V supply for the servos, with grounds joined so the signal has a reference.
Quadcopters: where are the servos?
A typical quadcopter has no servos. It steers by spinning its four motors at different speeds. Each motor is driven by an ESC (electronic speed controller) that reads the same kind of 50 Hz pulse a servo does, but 1000 µs = stop and 2000 µs = full power.
| Servo | ESC + motor | |
|---|---|---|
| Pulse | 500–2500 µs | 1000–2000 µs |
| Rate | 50 Hz | 50 Hz (or faster) |
| Output | an angle | a speed (3-phase power) |
| Power | up to ~2 A | 10–40 A per motor |
🎯 Try this: raise the throttle before arming: nothing happens, ESCs ignore you until armed. Arm at zero throttle, then add throttle. Now push Roll right: the two right motors slow down and the left ones speed up. No servos needed!
More jobs for servos on a drone
Beyond flight controls, servos open doors, lift wheels and tilt motors. Each one is the same 50 Hz pulse, just a different angle for a different job.
🛬 Retractable landing gear
📦 Payload release
🛩️ Tilt-rotor (VTOL)
🎯 Try this: watch the servo angle in each card. Landing gear and payload latches need only two positions, while a tilt-rotor needs the servo to hold any angle in between while carrying the motor's weight and thrust.
Pick the right servo (and the right power)
A control surface pushes back against the air. Estimate that push, then choose a servo that is strong enough, fast enough, and a BEC that can feed it.
Your control surface
Your parts
Results
Rule-of-thumb estimate for teaching. Real aircraft need testing; use datasheet values for your exact servo.
🎯 Try this: raise airspeed to 40 m/s and widen the surface. The required torque explodes (it grows with speed squared!), so a micro servo flutters or stalls. Then try shortening the control horn: it trades speed for force.
Check what you learned
📖 Glossary
💻 ESP32 code for this station
Uses the ESP32Servo library (Arduino IDE → Library Manager). Teaching code only: bench-test with propellers removed.