How to connect an SG90 servo to Arduino

Signal on D9, separate 5 V supply, common ground.

Wiring diagram

Open in the builder

Connections

StepFromToColor
1USB-C 6P GNDSG90 GNDblack
2Arduino Uno GNDUSB-C 6P GNDblack
3USB-C 6P VBUSSG90 VCCred
4Arduino Uno ~9SG90 PWMPWM, lime

Power and wiring check

  • The schematic check, the same as in the builder, found no errors: pin voltages match, ground is common, buses are fully connected.
  • SG90 draws up to 650 mA (about 200 typically) from the VBUS pin of USB-C 6P, the pin supplies about 1500 mA: USB-C with 5.1 kΩ resistors: charger up to 1.5–3 A, computer port 500–900 mA.

Current of the whole circuit and how long it runs on a battery: power budget. Where to plug what: breadboard layout.

Example code

Arduino IDE, Servo 1.2 (bundled with the Arduino IDE).

#include <Servo.h>

Servo servo;

void setup() {
  servo.attach(9);
}

void loop() {
  servo.write(0);
  delay(1000);
  servo.write(90);
  delay(1000);
  servo.write(180);
  delay(1000);
}

Part pinouts

Next steps for this circuit

How it is connected

The SG90 signal (orange wire) goes to D9: the Servo library outputs a 1-2 ms pulse every 20 ms. Power (red) and ground (brown) in the schematic come from a separate USB-C board with a 5 V supply, and its ground is connected to the Arduino's GND. Without a common ground the servo twitches or stands still.

An SG90 draws 100-250 mA while moving and up to 650 mA at stall. The Uno's 5V pin from USB gives about 400 mA, so when the servo is powered from it the circuit check raises a warning: at stall the board resets, and the USB port may disconnect.

FAQ

Why does the servo twitch and the Arduino reset?
At start and at stall the servo draws more than the 5V pin can give, and the voltage sags. Power the servo separately from a 5 V source rated 1-2 A and connect the grounds.
Can I connect an SG90 to an ESP32?
Yes. An SG90 usually understands a 3.3 V signal, power it with 5 V separately, and tie the grounds together. The library for the ESP32 is ESP32Servo.
How many servos can an Arduino handle?
There are enough signal pins for 12 servos on an Uno with the Servo library, but they must be powered from a separate supply. For 16 servos, a PCA9685 board over I2C is more convenient.

You might also need