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 voltage | 4.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 signal | PWM, 50Hz, ~1ms-2ms pulse width (1.5ms = center) |
| Weight | ~9g |
SG90 Pinout
| Pin | Name | Description |
|---|---|---|
| 1 | GND | Ground — usually the brown or black wire |
| 2 | VCC | Power, 4.8V-6V DC — usually the red wire |
| 3 | Signal | PWM 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
Wiring
| Component pin | ESP32 pin | Note |
|---|---|---|
| VCC | 5V (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 |
| GND | GND | — |
| Signal | GPIO18 | Any PWM-capable GPIO works |
Example code
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

ESP32-CAM Web Server: Stream Live Video in 5 Minutes
A complete, no-guesswork walkthrough for flashing an AI-Thinker ESP32-CAM as a live MJPEG video stream -- wiring, Arduino IDE setup, the CameraWebServer sketch, and every failure mode that actually causes problems.

ESP32 MQTT Tutorial: Publish and Subscribe with Arduino IDE
A complete, broker-agnostic ESP32 MQTT tutorial -- topics, QoS, retained messages, Last Will and Testament, TLS security for production, and a working publish/subscribe example with PubSubClient.

Installing ESP8266 in Arduino IDE: NodeMCU (ESP-12E) Complete Setup Guide for Windows
From driver headaches to a blinking LED — the full Windows walkthrough for getting NodeMCU ESP8266 boards running in Arduino IDE, plus notes for Mac and the bare ESP-01 module.

ESP32 Pinout Guide: Every GPIO, ADC, PWM, and Restricted Pin Explained
Complete ESP32 pinout guide covering all GPIOs, input-only pins, strapping pins, flash-reserved pins, dual ADC channels, PWM via LEDC, I2C, SPI, UART, and deep sleep wake pins.