Breadboard
docs
Example project · ESP32

Servo on PWM (LEDC)

A servo on G4 driven by the real ESP32 LEDC peripheral. The serial monitor opens with a ready-made sweep script; press ▶ Run script and watch the horn move.

The Servo on PWM (LEDC) circuit as rendered by the simulator

What's on the bench

  • Battery
  • ESP32-C3
  • Servo

The code

This MicroPython script runs on the emulated board every boot; edit it in the Code tab.

from machine import Pin, PWM
import time
s = PWM(Pin(4), freq=50)
for us in (3277, 4915, 6553, 4915):  # 0°, 90°, 180°, back
    s.duty_u16(us)
    time.sleep(1)
print("sweep done")