Home › Lessons › Embedded (ESP32) › PWM actuator: hobby servo

PWM actuator: hobby servo

Embedded (ESP32) · Intermediate · about 20 minutes · part of Zen’s Electronics Design Mastery

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.

PWM actuator: hobby servo: the circuit on the simulator's bench

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

  1. Scroll over the pot: the horn swings and the servo draws about 200 mA while moving, about 10 mA holding.
  2. Move the servo’s red wire to the 3V3 pin: at 3.3 V it is sluggish and weak.

Parts on the bench

In the course

Zen’s Electronics Design Mastery, module “Microcontrollers & Embedded”.

More on embedded (esp32)