How to wire a servo to an ESP32-S3
To wire a servo to an ESP32-S3, connect GND to G, VCC to 5V and PWM to GPIO 5. The servo takes 5 V on its power wire, while the signal wire comes from a 3.3 V pin, which an SG90 reads as high without a level shifter. The sketch below uses the ESP32Servo (ESP32Servo.h) library. It sweeps the horn from 0 to 180 degrees and back, printing a line at each end.
- 3.3 V logic
- Library: ESP32Servo.h
- 3 wires
Servo to ESP32-S3 wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| Servo pin | ESP32-S3 pin | Wire color | Why |
|---|---|---|---|
| Brown (GND) | G | blue | The signal is measured against this, so it must be shared with the board. |
| Red (V+) | 5V | red | An SG90 wants 4.8 to 6 V. At 3.3 V it barely moves, so it takes the 5 V rail, not 3V3. |
| Orange (signal) | GPIO 5 | amber | Any GPIO with an output driver; the ESP32 makes the pulse in its LEDC hardware. |
Power and logic levels for servo and ESP32-S3
Logic level
The ESP32-S3’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.
Supply
The servo takes 5 V from 5V. That is the ESP32-S3’s 5 V rail, so the part shares the current the board can supply.
This pair
The servo runs from 5V while its signal comes from a 3.3 V pin. That works: an SG90 reads anything above about 2 V as high, so no level shifter is needed. On a real bench, a servo under load can pull more current than USB gives; then power it from its own 5 V supply and join the grounds.
Pins to leave alone
GPIO 19 and 20 are the USB port’s data lines, GPIO 35 to 37 belong to the PSRAM on octal-PSRAM boards such as the N8R8, and GPIO 0, 3, 45 and 46 are strapping pins.
The working code for the ESP32-S3
Library: ESP32Servo (ESP32Servo.h). This is the sketch the circuit above runs.
#include <ESP32Servo.h>
const int SERVO_PIN = 5; // signal, GPIO 5
Servo servo;
void setup() {
Serial.begin(115200);
servo.attach(SERVO_PIN); // 544 to 2400 us, 50 times a second
Serial.println("Sweeping");
}
void loop() {
for (int angle = 0; angle <= 180; angle += 2) {
servo.write(angle);
delay(15);
}
Serial.println("at 180");
for (int angle = 180; angle >= 0; angle -= 2) {
servo.write(angle);
delay(15);
}
Serial.println("back at 0");
}
What you should see
The servo horn turns from 0 to 180 degrees in about 1.4 seconds and then back. The serial monitor, at 115200 baud, prints Sweeping once, then at 180 at the top of each sweep and back at 0 at the bottom.
A servo that buzzes or does not move is almost always a missing common ground or a supply that sags under load.
The serial monitor prints this, recorded from the circuit above running for two and a half seconds:
Sweeping
at 180Common mistakes wiring a servo to an ESP32-S3
Powering the servo from 3V3
The ESP32-S3’s 3.3 V regulator is sized for the chip, not a motor, and an SG90 at 3.3 V jitters or stalls. The red wire goes to 5V.
Forgetting the common ground
With the servo on a separate supply and only the signal wire to the board, the servo has nothing to measure the pulse against and twitches at random. Connect the supply’s ground to the board’s GND.
Using the USB or PSRAM pins
GPIO 19 and 20 are the USB port’s data lines and GPIO 35 to 37 belong to the PSRAM on N8R8 boards. Wire the servo signal to one of those and the USB socket or the memory stops working on a real board, even though the simulator carries on. Stay on GPIO 4 to 18.
Build your own servo project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.