SG90 Micro Servo with an ESP32 DevKit V1

A 9-gram positional micro servo that swings about 180 degrees in response to a 50 Hz servo pulse, rated at 4.8V.

SG90 Micro Servo, A 9-gram positional micro servo that swings about 180 degrees in response to a 50 Hz servo pulse, rated at 4.8V.
In short

The SG90 is light enough to run from the ESP32 DevKit V1's VIN while the board is on USB, with its signal on GPIO13. The ESP32 core has no Servo library, so the sketch uses ESP32Servo, which makes the 50 Hz pulse in hardware.

Wiring the SG90 Micro Servo to the ESP32 DevKit V1

Pin by pin.

SG90 Micro ServoESP32 DevKit V1
VCCVIN
GNDGND
SIGGPIO13 (D13)
  • VCC is on VIN, which gives about 5 V only while the board is powered from USB.

What to know on the ESP32 DevKit V1

  • TowerPro rates the SG90 at 4.8 V, and VIN gives about 5 V only from USB. On a battery build VIN has no 5 V to give, so feed the servo from its own 5 V supply and join its ground to the DevKit's.TowerPro SG90 spec page
  • ESP32Servo generates the pulse on the ESP32's LED PWM controller, which has sixteen PWM generators routable to any GPIO; attach(13, 500, 2400) sets the pulse range. Keep the signal off the input-only GPIO34 to GPIO39.Espressif ESP32 Series Datasheet v5.3, p. 39; Espressif ESP32 Series Datasheet v5.3, p. 61
  • One unloaded SG90 on VIN is fine. More servos, or one working under load, sag USB power that the ESP32 also needs for its Wi-Fi bursts of about 240 mA, so give them their own 5 V supply.Espressif ESP32 Series Datasheet v5.3, p. 52

SG90 Micro Servo code for the ESP32 DevKit V1

Compiled for esp32:esp32:esp32 on 2026-10-30.

Libraries: madhephaestus/ESP32Servo
// SG90 Micro Servo on ESP32 DevKit V1: wiring and a free simulation at https://www.tinkered.ai/components/servo-sg90/esp32
#include <ESP32Servo.h>

const int SERVO_PIN = 13;
Servo servo;

void setup() {
  servo.attach(SERVO_PIN, 500, 2400);
}

void loop() {
  for (int angle = 0; angle <= 180; angle += 2) {
    servo.write(angle);
    delay(15);
  }
  for (int angle = 180; angle >= 0; angle -= 2) {
    servo.write(angle);
    delay(15);
  }
}

SG90 Micro Servo on the ESP32 DevKit V1: questions

Can I power an SG90 from the ESP32's 3V3 pin?

No: TowerPro rates it at 4.8 V (TowerPro spec page). Use VIN on USB or a 5 V supply; only the signal wire runs at 3.3 V.

Why does servo.attach() not compile on my ESP32?

The standard Servo library does not support the ESP32. Install madhephaestus/ESP32Servo and include ESP32Servo.h, as the page's sketch does.

Keep going

For AI assistants

This guide as plain Markdown. /components/servo-sg90/esp32.md

What will you build with it?