What it is
A hobby servo is a little motor, a gearbox, and a control circuit in one sealed case. You don't tell it "spin" — you tell it an angle, and it goes there and holds it, even against a push. The one I build with is the MG90S — a 9-gram black servo with metal gears inside.
The bare minimum to use it
- Three wires: brown/black = GND, red = +5 V, orange/yellow = signal.
- Wants ~5 V and real current — give it its own supply, not the ESP32's 3.3 V pin. Share grounds.
- Control with PWM — the
ESP32Servolibrary does the math; you just writeservo.write(90). - Center before mounting horns — command 90°, then attach the horn. Never force it by hand.
Wiring
5V supply (+) ──┬──▶ servo RED
│
ESP32 GND ──────┴──▶ servo BROWN ──▶ supply (−) (common ground!)
ESP32 GPIO 3 ───────▶ servo ORANGE (pan signal)
ESP32 GPIO 4 ───────▶ servo ORANGE (tilt signal)
C3 SuperMini pin map — the servos use GPIO 3 (pan) and 4 (tilt).
The code
Drives a two-servo pan-tilt head with a smooth sweep. Full sketch in the sidebar.
// miniRobo EP2 — MG90S pan-tilt sweep (ESP32)
#include <ESP32Servo.h>
Servo pan, tilt;
void setup() {
pan.attach(3);
tilt.attach(4);
}
void loop() {
for (int a = 30; a <= 150; a++) { pan.write(a); delay(15); }
for (int a = 150; a >= 30; a--) { pan.write(a); delay(15); }
tilt.write(60); delay(400);
tilt.write(110); delay(400);
}
The 3D-printed parts
The pan-tilt head is three printed pieces driven by two MG90S servos. The OpenSCAD is fully parametric — set part to "base", "yoke", or "tilt" to export each one, and tweak fit_tol if the servo pockets are tight or loose.
| base_plate | Holds the pan servo upright; bolts to the chassis. |
| pan_yoke | Clips to the pan horn; cradles the tilt servo. |
| tilt_bracket | Clips to the tilt horn; holds a small camera/sensor. |
What I wish I knew
- Never power servos from the ESP32 — they brown it out. Own supply, shared ground.
- Black metal gears over blue plastic — the SG90's plastic gears strip under load.
- They don't all hit a true 0–180° — test the real range and don't jam the stops.
- Center, then mount the horn — forcing it by hand strips gears.
- Jitter is power or a long signal wire, almost never the code.