An SG90 on a XIAO ESP32S3 — perhaps panning a Sense camera — needs only a signal wire from D0. Its power comes from a separate 5 V supply, with the ground shared.
The sketch sweeps the servo 0–180° and back in 30° steps.
Wiring
| XIAO ESP32S3 | SG90 micro servo (9 g) | Wire | Notes |
|---|---|---|---|
| D0 | SIG | orange | |
| 5 V 1 A supply · +5V | VCC | red | |
| 5 V 1 A supply · GND | GND | brown | |
| GND | GND | black | Common ground. |
4.8–6 V (several hundred mA while moving or stalled) part, 3.3 V board. The signal input is happy with 3.3 V logic, so ESP32 and Pico drive it directly. On ESP32 use the ESP32Servo library — the standard Servo library is for AVR and RP2040.
Board quirks
- D0 is GPIO1, boot-safe. Avoid D6 (TX — boot messages twitch the servo) and D2 (strapping).
- A servo on the XIAO’s own 5V pin works only on USB and only unloaded; the Sense board’s camera adds to the load, so stall current resets the board. Use a separate supply.
- ESP32Servo drives the S3’s LEDC PWM. Two servos on D0/D1 make a pan-tilt head for the Sense camera.
Code
// SG90 servo on a Seeed XIAO ESP32S3 with ESP32Servo.
// SIG → D0 (GPIO1). Servo VCC/GND → a separate 5 V supply; its GND → XIAO GND.
#include <ESP32Servo.h>
Servo servo;
void setup() {
Serial.begin(115200);
uint32_t t0 = millis();
while (!Serial && millis() - t0 < 3000) {}
servo.setPeriodHertz(50);
servo.attach(D0, 500, 2400);
Serial.println("Sweeping 0-180 degrees on D0");
}
void loop() {
for (int a = 0; a <= 180; a += 30) {
servo.write(a);
Serial.printf("Angle %d\n", a);
delay(500);
}
for (int a = 180; a >= 0; a -= 30) {
servo.write(a);
Serial.printf("Angle %d\n", a);
delay(500);
}
}// SG90 servo on a Seeed XIAO ESP32S3 with ESP32Servo.
// SIG → D0 (GPIO1). Servo VCC/GND → a separate 5 V supply; its GND → XIAO GND.
#include <ESP32Servo.h>
Servo servo;
void setup() {
Serial.begin(115200);
uint32_t t0 = millis();
while (!Serial && millis() - t0 < 3000) {}
servo.setPeriodHertz(50);
servo.attach(D0, 500, 2400);
Serial.println("Sweeping 0-180 degrees on D0");
}
void loop() {
for (int a = 0; a <= 180; a += 30) {
servo.write(a);
Serial.printf("Angle %d\n", a);
delay(500);
}
for (int a = 180; a >= 0; a -= 30) {
servo.write(a);
Serial.printf("Angle %d\n", a);
delay(500);
}
}Library: Servo (Arduino) — compiled with ESP32Servo 3.2.1.
Expected serial output
Sweeping 0-180 degrees on D0
Angle 0
Angle 30
Angle 60Sweeping 0-180 degrees on D0 Angle 0 Angle 30 Angle 60