PWM actuator: hobby servo
A hobby servo is position-controlled by pulse width, not duty cycle: every 20 ms it expects a pulse between 0.5 ms (0°) and 2.5 ms (180°), and its own feedback loop drives the horn there. Power it from 5 V; its motor draws far more current than a GPIO could give.

Open this lesson in the labFree, in your browser, no account needed.
How it works
Pot at 25 % → 0.82 V → analogReadMilliVolts() ≈ 825 → angle = 45°
Pulse width = 0.5 ms + angle/180 × 2 ms = 1.00 ms, repeated every 20 ms (50 Hz). The sketch tells ESP32Servo to use 500–2500 µs, the SG90's range; the library's own default is 544–2400 µs.
Try it on the bench
- Scroll over the pot: the horn swings and the servo draws about 200 mA while moving, about 10 mA holding.
- Move the servo’s red wire to the 3V3 pin: at 3.3 V it is sluggish and weak.
Parts on the bench
- Bench power supply
- ESP32 DevKit
- USB charger / port
- Hobby servo
- Potentiometer
In the course
Zen’s Electronics Design Mastery, module “Microcontrollers & Embedded”.