Servo
Controlling SG90 Servo with ESP32
What is the SG90?
SG90 practical reference
The most common hobby servo in existence — 180° rotation, 9g weight, and near-universal library support across every microcontroller platform.
Key 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
Pinout and connection notes
Wire color order (GND-VCC-Signal vs Signal-VCC-GND) varies by manufacturer — check the connector keying, not just color, before powering on.
- GND: Ground — usually the brown or black wire
- VCC: Power, 4.8V-6V DC — usually the red wire
- Signal: PWM control input — usually the orange or yellow wire
Integration checklist
- Confirm the exact part number and breakout-board revision.
- Verify supply voltage, current demand, logic levels, and signal direction against the datasheet.
- Check controller pin assignments and bus address or interface mode against the example code.
- Power up with external loads disconnected, then test signals before full integration.
- If readings or communication fail, check power and ground first, then pin mapping, interface settings, and library initialization.
Troubleshooting and reproducibility
Record the board used, wiring, library/version, supply arrangement, and measured behavior. Use the selected board-specific wiring example as the source of truth. Never assume visually similar modules share identical voltage tolerance or pin order.
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 |
Swipe sideways to see every column →
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 Components
Active Buzzer
Self-oscillating buzzer that beeps with just a single HIGH signal — no PWM required.
BLDC ESC
High-speed brushless motor and electronic speed controller combo.
Continuous Servo
Modified servo that spins continuously like a geared motor.
MG996R
High-torque metal-gear servo for robotic arms, RC vehicles, and load-bearing joints.
Related Guides & Projects
MicroPython vs Arduino on ESP32: Which Should You Learn First?
An honest comparison for beginners: where MicroPython is easier, where Arduino C++ is faster, how libraries and memory differ, and how to choose based on your project instead of hype.
MicroPython ESP32 Web Server: Control an LED or Relay from Your Browser
Create a working web server with the socket module, parse requests, serve a responsive control page for an LED or a relay, keep the displayed state truthful, choose a safe relay startup state and make the server survive bad or repeated requests.
MicroPython on ESP32 and Raspberry Pi Pico W: The Complete Guide
A structured MicroPython learning path for ESP32 and Pico W. Set up your tools, control GPIO, read sensors, connect to WiFi, build web servers, publish MQTT data and make projects reliable. Start here, then follow the links by level.
boot.py vs main.py in MicroPython: What Runs, When and Why
Understand the difference between boot.py and main.py in MicroPython, startup order, Wi-Fi setup, project structure, and recovery from boot errors.