Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.

SG90 servo with Arduino Uno — wiring and sweep code

Connect an SG90 micro servo to an Arduino Uno on D9 with the built-in Servo library, and learn which PWM pins the library takes over.

Arduino C++Verified — core avr 1.8.8, Servo 1.3.0, 3 Nov 2026Compile-only

Community draft — report a mistake

The SG90 is the standard 9-gram hobby servo: send it a 1–2 ms pulse every 20 ms and it turns to an angle between 0° and 180°. The Uno’s built-in Servo library does all the timing.

The sketch sweeps in 30° steps. Once your servo moves something real, give it its own 5 V supply.

Wiring

Arduino Uno R3Only the pins used are shown · 5 V logicSG90 micro servo (9 g)5VGNDD9SIGVCCGND
Every connection
Arduino Uno R3SG90 micro servo (9 g)WireNotes
D9SIGorange
5VVCCredFine for one unloaded SG90 from USB. With load, use a separate 5 V 1 A supply and join its GND to the Uno GND.
GNDGNDbrown

4.8–6 V (several hundred mA while moving or stalled) part, 5 V board. The signal input is happy with 3.3 V logic, so ESP32 and Pico drive it directly. On ESP32 use the ESP32Servo library — the standard Servo library is for AVR and RP2040.

Board quirks

  • The Servo library uses Timer1, so analogWrite() PWM stops working on D9 and D10 while a servo is attached.
  • Servos draw up to several hundred mA when stalled; the Uno’s USB 5 V can sag and reset the board.
  • Any digital pin can carry the servo signal — D9 is just the conventional choice.

Code

servo-uno.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// SG90 micro servo on an Arduino Uno R3.
// Signal (orange) → D9, red → 5V, brown → GND.
#include <Servo.h>

const uint8_t SERVO_PIN = 9;
Servo servo;

void setup() {
  Serial.begin(9600);
  servo.attach(SERVO_PIN, 500, 2400);  // SG90 pulse range in µs
  Serial.println(F("Sweeping 0 <-> 180 degrees"));
}

void loop() {
  for (int angle = 0; angle <= 180; angle += 30) {
    servo.write(angle);
    Serial.print(F("Angle "));
    Serial.println(angle);
    delay(500);
  }
  for (int angle = 180; angle >= 0; angle -= 30) {
    servo.write(angle);
    Serial.print(F("Angle "));
    Serial.println(angle);
    delay(500);
  }
}

Library: Servo (Arduino) — compiled with Servo 1.3.0.

Expected serial output

Serial Monitor · 9600Output
Sweeping 0 <-> 180 degrees
Angle 0
Angle 30
Angle 60

Common errors

Servo hums but doesn’t move

Not enough current. Power it from a separate 5 V supply with a shared ground.

LED on D10 stopped dimming

The Servo library took over Timer1; move the LED to D3, D5 or D6.

↑↓ to move · Enter to open