ESP32 servo sweep — 5 parts, 20 lines of code
This is a classic "hello world" for the ESP32: drive a hobby servo back and forth, with a little status LED that confirms the board is alive.
Bill of materials
- 1 × ESP32 DevKit (or any ESP32 board with GPIO18 + GPIO23 broken out)
- 1 × Hobby servo (SG90 or similar — anything that runs on 3.3–6V)
- 1 × 330 Ω resistor
- 1 × LED (any color)
- 1 × Ground rail
Wiring
ESP32 3V3→ ServoV+ESP32 GND→ ServoGND→ Ground railESP32 GPIO18→ Servo signalESP32 GPIO23→ 330 Ω resistor → LED anode → Ground
How it runs
Flash the code, power the board, and the servo will sweep 0 → 180 → 0 over roughly three seconds while the status LED stays lit. If the LED stays dark, GPIO23 isn't writing high — check the wire order.
Try it
Hit Simulate in the lab. The status LED turns on because GPIO23 is set to 3.3V in the initial props. Drag the servo position in the inspector and watch the arm move.