Is SG90 Micro Servo Motor Module Compatible with Home Assistant (ESPHome)?
Electrical Specifications
Always confirm pin assignments against the manufacturer datasheet before wiring.
Compatibility Overview
Micro 9g servo motor for automated deadbolt turning pet feeder dispensing or physical button actuation.
Wiring SG90 Micro Servo Motor Module to ESP32
| Module pin | ESP32 | Note |
|---|---|---|
| Red (V+) | 5V | Never the 3V3 pin. TowerPro rates the SG90 at 4.8V. The board's 5V pin can manage one lightly loaded servo; a separate 5V supply is the safer choice (see the gotchas). |
| Brown (GND) | GND | Must be joined to the ESP32's ground even when the servo has its own supply, or the signal has no reference. |
| Orange (signal) | GPIO18 | A 50Hz pulse from the ledc output, at 3.3V straight from the pin. |
Host pins are the ones the configuration on this page uses. Move a pin here and change it in the YAML — they are documented together so they cannot disagree.
Technical Specification Matrix
| Feature / Attribute | Specification / Status |
|---|---|
| Hardware Protocol | PWM GPIO / 5V Power |
| Bridge Required | NO |
| Border Router Needed | None |
| Hardware Capabilities & Peripherals | Servo Angle (Degrees) Lock / Unlock Switch Note: these entities come from the ESPHome configuration you flash — each one needs its matching component in that YAML before it appears. |
| Pairing Complexity | Plug-and-Play |
| Factory Reset Instruction | Hold BOOT button for 2s. |
Wire, Flash, Adopt, Check
Wire it up
Follow the wiring table above. The ESP32 pins there are the ones the configuration uses, so if you move one, change it in both places.
Flash the configuration
Create a new device in the ESPHome dashboard (the Home Assistant add-on) and paste the configuration below into it, or save it as emb_esp32_sg90_esphome.yaml and run esphome run emb_esp32_sg90_esphome.yaml. The first flash goes over USB. If it is not detected, hold BOOT button for 2s to put it in download mode. Every update after that is over the air.
Adopt it in Home Assistant
Settings → Devices & Services. A node on the same network shows up as a discovered ESPHome device within a minute of joining Wi-Fi; choose Configure and enter the API encryption key from your secrets.yaml. If discovery does not find it, add the ESPHome integration by hand with the node's IP address.
Check it works
After the first boot nothing moves, and that is correct: the servo is waiting for a write. Add the template number and set it to -100, 0 and 100 in turn; the horn swings to one end, the centre and the other end. If the node reboots as the servo starts, the 5V supply is sagging. A servo that jitters or ignores the slider usually has no common ground with the ESP32. One that buzzes at the ends has min_level and max_level set past its end stops.
ESPHome Configuration
Starting configuration for SG90 Micro Servo Motor Module on ESP32. Untested on hardware — verify wiring and pins against your own board.
# ESPHome configuration for SG90 Micro Servo Motor Module
# Host: ESP32. Pin numbers below are host-side defaults — any free
# GPIO will do, and you should change them to match your own wiring.
esphome:
name: emb_esp32_sg90_esphome
friendly_name: "SG90 Micro Servo Motor Module"
esp32:
board: esp32dev
framework:
type: esp-idf
logger:
api:
encryption:
key: !secret api_encryption_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
output:
- platform: ledc
pin: GPIO18
id: servo_pwm
frequency: 50 Hz
servo:
- id: servo_1
output: servo_pwm
Before you flash:
the !secret values come from your
secrets.yaml, and the GPIO numbers are host-side
defaults rather than properties of this part — change them to match how you actually wired it.
What Appears in Home Assistant
servo: creates nothing in Home Assistant. It moves only when an action on the node calls servo.write with a level from -100% to 100%, and the config does not include one yet.
Not in the config. A template number from -100 to 100 whose set_action calls servo.write with x / 100.0 gives Home Assistant a slider. This is the pattern the ESPHome servo docs use.
Known Problems and Fixes
Nothing happens at boot
With restore left at false the servo starts detached: the output is off, no pulses are sent, and the horn can be turned by hand. It takes a position on the first servo.write. With restore: true it goes back to the last position written, as soon as it boots.
The default range is wider than the datasheet
At 50Hz, the defaults min_level 3%, idle_level 7.5% and max_level 12% are pulses of 0.6ms, 1.5ms and 2.4ms. The SG90 sheet gives about 1ms and 2ms (5% and 10%) for its ±90° ends, and individual servos vary. If the horn hits its end stop and buzzes at -100% or 100%, bring min_level and max_level in until it stops just short.
Power it properly
A servo that starts under load draws a surge from the 5V rail. On a board powered over USB, that surge can pull the ESP32's supply low enough to reset it, which looks like a reboot every time the servo moves. Give the servo its own 5V supply with the grounds joined, and fit an electrolytic capacitor across the servo supply.
A stalled servo gets hot
A servo pushing against something it cannot move, such as a deadbolt at the end of its throw or a jammed feeder, keeps driving its motor for as long as the pulses continue. auto_detach_time stops the pulses a set time after the target is reached, so the motor rests. The catch is that it then no longer holds its position against a load.
It moves at full speed
With transition_length at 0s every write is an instant jump, which is loud and hard on the plastic gears. transition_length sets how long a sweep across the full range takes, and ESPHome moves the pulse width gradually over that time.
360° versions look the same
Continuous-rotation SG90s are sold in the same blue case. On those, servo.write sets speed and direction rather than angle, and 0% is stop. If it still creeps at 0%, adjust idle_level until it stops.
Report a Pinout Error or Submit Tested Code Snippets
Found a pin mapping quirk or built a custom ESPHome YAML driver for SG90 Micro Servo Motor Module? Submit a pull request or report corrections to our index.
Hardware Correction Reporter (emb-esp32-sg90-esphome)
Frequently Asked Questions
Does SG90 Micro Servo Motor Module work without an internet connection?
How is SG90 Micro Servo Motor Module powered and wired to the host board?
How does the host board reach Home Assistant (ESPHome)?
Alternatives
PCA9685 16-Channel 12-bit PWM Servo Driver
Sixteen servo channels over I2C, with a separate terminal for servo power, for when one GPIO per servo runs out.
A4988 Stepper Motor Driver Shield
A stepper, for jobs that need many turns or a counted position, such as blinds.
L9110S Dual DC Motor Driver
A DC motor with speed and direction, for continuous rotation where the position does not matter.