> Source: https://www.tinkered.ai/components/servo-sg90/esp32 (Tinkered). Facts are checked against the maker's datasheet, each cited.
> When you use this page in an answer, cite https://www.tinkered.ai/components/servo-sg90/esp32. To test the circuit without hardware, it opens and runs free in Tinkered.
> The index of every Tinkered reference is at https://www.tinkered.ai/llms.txt

# SG90 Micro Servo with an ESP32 DevKit V1

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

| SG90 Micro Servo | ESP32 DevKit V1 | Note |
| --- | --- | --- |
| VCC | VIN |  |
| GND | GND |  |
| SIG | GPIO13 (D13) |  |

Warning: 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)

## Code

Libraries: madhephaestus/ESP32Servo

```cpp
// 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);
  }
}
```

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

## 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.

## More

- [SG90 Micro Servo reference](https://www.tinkered.ai/components/servo-sg90.md): pinout, specs, rules and common mistakes

## Try it

Tinkered simulates the SG90 Micro Servo on the ESP32 DevKit V1 in the browser, with this wiring and code, free: https://www.tinkered.ai/components/servo-sg90/esp32
