Your first ESP32 build: a servo that sweeps
If you just shipped an Arduino LED project and want to try something with an actual moving part — this is the next step.
We'll wire an ESP32 DevKit to a hobby servo, add a status LED that turns on while the code is running, and write a 20-line sketch that sweeps the servo back and forth. Total part count: five.
What's new about the ESP32
The ESP32 is a 3.3V microcontroller with WiFi and Bluetooth baked in.
For this project, you can treat it exactly like an Arduino — the
Arduino IDE supports ESP32 as a board target, and libraries like
ESP32Servo give you the same servo.write(angle) API you'd use on
an Uno.
Two things to remember:
- Power rail is 3.3V, not 5V. Your LED current-limiting math doesn't change much — a 330 Ω resistor still keeps a 2V LED under its 25 mA limit — but servos typically want 5V, so run them from external supply if the servo strains or stalls.
- Pin labels are GPIO numbers. GPIO18 and GPIO23 are common choices because they're easy to reach on every ESP32 board and they're not used by boot-strap or JTAG.
Wiring
Drop these five parts onto the canvas:
- ESP32 DevKit — from Microcontrollers
- Servo — from Actuators
- 330 Ω resistor — from Passives
- LED — from Diodes & LEDs
- Ground — from Power
Then wire them:
| From | To |
|---|---|
ESP32 · 3V3 | Servo · V+ |
ESP32 · GND | Servo · GND |
ESP32 · GPIO18 | Servo · S (signal) |
ESP32 · GPIO23 | Resistor · a |
Resistor · b | LED · anode |
LED · cathode | Ground |
That's it. Hit Simulate and the LED should glow — GPIO23 is seeded to
3.3V in the lab so the sim reads "LED on" without needing the code to
run. Drag the servo's position property in the inspector and watch
the arm rotate.
The code
#include <ESP32Servo.h>
const int SIG_PIN = 18;
const int LED_PIN = 23;
Servo servo;
void setup() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, HIGH);
servo.attach(SIG_PIN);
}
void loop() {
for (int pos = 0; pos <= 180; pos++) {
servo.write(pos);
delay(8);
}
for (int pos = 180; pos >= 0; pos--) {
servo.write(pos);
delay(8);
}
}
What to build next
- Swap the servo for a DC motor + relay — the new motor symbol actually spins in the sim, and a relay lets the ESP32 reverse direction without melting itself.
- Swap the ESP32 for a Pi Pico — the sketch is nearly identical;
the pin labels change to
GP0,GP1, … but the wiring pattern is the same. - Add a photoresistor (LDR) to GPIO A0 and make the servo position follow the room's brightness. All the parts are in the palette.
Happy building.