Skip to content
E

Servo

Controlling SG90 Servo with ESP32

What is the SG90?

The most common hobby servo in existence — 180° rotation, 9g weight, and near-universal library support across every microcontroller platform.

Specifications

Operating voltage4.8V - 6V DC (5V typical)
Torque~1.8 kg·cm at 4.8V, ~2.2 kg·cm at 6V
Rotation~180° on most units (some batches are limited to 120° — test before mounting)
Speed~0.1 sec/60° at 4.8V, no-load
Control signalPWM, 50Hz, ~1ms-2ms pulse width (1.5ms = center)
Weight~9g

SG90 Pinout

PinNameDescription
1GNDGround — usually the brown or black wire
2VCCPower, 4.8V-6V DC — usually the red wire
3SignalPWM control input — usually the orange or yellow wire

Wire color order (GND-VCC-Signal vs Signal-VCC-GND) varies by manufacturer — check the connector keying, not just color, before powering on.

Setting Up SG90 with ESP32

Library

Servo by Arduino

Bundled with the Arduino IDE core

Library guide

Wiring

Component pinESP32 pinNote
VCC5V (VIN, if available on your ESP32 board)SG90 draws far less current than the MG996R and usually runs fine from the ESP32's 5V pin, but move to an external supply if you see brownouts
GNDGND
SignalGPIO18Any PWM-capable GPIO works

Example code

C++

SG90 typically draws under 200mA at idle, spiking higher under load -- fine from the ESP32's 5V pin on most boards, but move to an external supply if the board resets when the servo moves.

Related Guides & Projects