SG90 Servo Motor with Arduino: Wiring, Sweep Code and Jitter Fix

Cartoon of a bright translucent blue SG90 micro servo with a masking tape flag on its shaft sweeping through a half circle, and its brown, red and orange lead ending in a black three-way socket

Quick answer: an SG90 micro servo has three wires: brown = GND, red = 5V, orange = signal.

  1. Push male-to-male jumpers into the servo’s socket. Connect brown to Uno GND, red to Uno 5V and orange to pin 9.
  2. Upload the sweep sketch below (Servo library). The shaft swings back and forth.
  3. If it jitters, or the Uno resets or disconnects, move the red wire to a separate 4.8 to 6V supply such as a 4xAA battery holder, and join the battery’s black wire to Uno GND.

Never connect the battery’s red wire to the Uno 5V pin.

SG90 pinout: brown, red and orange

The Tower Pro SG90’s lead is a flat three-wire ribbon about 25 cm long (Tower Pro’s SG90 page), ending in one black 3-way socket.

Wire Job Connects to What it carries
Brown Ground (GND) Uno GND The return path for the motor current and for the signal
Red (middle) Power, 4.8 to 6V (Luxorparts SG90 data sheet) Uno 5V for a first test, then a separate supply Motor current: typically about 10 mA idle and 100 to 250 mA moving, with 360 mA measured at stall (ProtoSupplies’ figures). The Luxorparts sheet gives the maximum as under 600 mA
Orange Signal A digital pin (pin 9 in this guide) A timing pulse only, with almost no current

Signal and power are separate jobs. The orange wire carries one short pulse every 20 ms, and the width of the pulse is the message: about 1 ms for one end of the travel, 1.5 ms for the middle, about 2 ms for the other end (SG90 data sheet).

Inside the case, a potentiometer on the shaft reports its position. A small control chip compares that with the pulse width and runs the motor until they match. The orange wire only feeds that chip’s input, which senses a voltage and draws almost no current. All the motor’s current arrives on the red wire.

Cartoon close-up of an SG90 servo's black three-way socket with brown, red and orange wires, each linked to an icon: a ground symbol, a lightning bolt for power and a square pulse for signal
Brown is ground, red (in the middle) is motor power and orange is the timing signal. The red wire does the heavy work.

Parts you need

Parts list

ItemPriceQty
SG90 MG90 Tower Pro Micro Servo Motor 9g 180 360 Servo Motor for Arduino Robotic - MG90- 180°SG90 MG90 Tower Pro Micro Servo Motor 9g 180 360 Servo Motor for Arduino Robotic - MG90- 180°MG90180RM11.55
SG90 MG90 Tower Pro Micro Servo Motor 9g 180 360 Servo Motor for Arduino Robotic - MG996R- 180°SG90 MG90 Tower Pro Micro Servo Motor 9g 180 360 Servo Motor for Arduino Robotic - MG996R- 180°996R180RM24.95

Step-up servos, only if the SG90 is too weak for your load. The MG90S has the same footprint with metal gears. The MG996R is a much bigger standard-size servo and must never be powered from the Uno 5V pin.

The SG90‘s socket is female and so are the Uno‘s headers, so every connection uses a male-to-male jumper. The breadboard and the 4xAA holder are for Step 3. Bring four AA cells (any kedai runcit sells alkaline ones).

Our servos ship bare, with no horn (the plastic arm), so stick a small flag of masking tape on the shaft to see it turn.

Step 1: Wire the SG90 straight to the Uno

One SG90 with nothing on its shaft can run from the Uno’s 5V pin for a first test. Unplug USB while you wire.

Servo wire Uno pin Where it is on the Uno
Brown GND POWER header, next to 5V
Red 5V POWER header, between 3.3V and GND. Not the 3.3V pin
Orange 9 DIGITAL header, the pin marked ~9

Peel a brown, a red and an orange jumper off the ribbon. Push each one into the socket hole of the same colour, and its other end into the Uno.

Cartoon of a translucent blue SG90 servo joined to a blue Arduino Uno by a brown, a red and an orange jumper wire pushed into the servo's black socket
Step 1: three male-to-male jumpers, colour matched to the servo’s wires. Follow the table for the exact pins.

Step 2: Upload the sweep sketch

The Servo library comes with the Arduino IDE. (If File > Examples > Servo is missing, install “Servo” from Library Manager.) Paste this sketch, choose Arduino Uno and its port, then upload. No port? Install the CH340 USB driver as shown in our Arduino Nano guide (same chip).

// SG90 first sweep: swings the servo shaft slowly between 10 and 170 degrees.
// Wiring: brown to GND, red to 5V (or the battery + rail), orange to pin 9.
#include <Servo.h>

const int SERVO_PIN = 9;       // orange signal wire
const int MIN_ANGLE = 10;      // stop short of the ends: 0 and 180 can push
const int MAX_ANGLE = 170;     // an SG90 against its end stop and make it buzz
const int STEP_DELAY_MS = 15;  // 160 steps x 15 ms = about 2.4 s per pass

Servo myServo;

void setup() {
  myServo.attach(SERVO_PIN);   // starts the pulses on pin 9
  myServo.write(90);           // go to the middle first
  delay(1000);
}

void loop() {
  for (int angle = MIN_ANGLE; angle <= MAX_ANGLE; angle++) {
    myServo.write(angle);
    delay(STEP_DELAY_MS);
  }
  for (int angle = MAX_ANGLE; angle >= MIN_ANGLE; angle--) {
    myServo.write(angle);
    delay(STEP_DELAY_MS);
  }
}

The shaft centres, then swings slowly from side to side.

The sweep stops at 10 and 170. The library spreads 0 to 180 across pulses of 544 to 2400 µs (Servo library reference), wider than the data sheet’s 1 to 2 ms. At the extremes a pulse can ask for a position beyond the end stop, and the motor keeps pushing against it. That is a stalled motor: it buzzes, heats up and draws its highest current. End stops vary between servos, so 10 degrees in is a starting margin. Still buzzing? See the table below.

Why does my SG90 jitter or reset the Arduino?

An SG90 that twitches, or an Uno that restarts when the servo moves, points to power before code. A stalled SG90 pulls about 360 mA, and a big move starts near that figure. A motor at rest has only its coil’s resistance to limit the current until it spins up. On USB, the Uno’s 5V pin is the computer’s USB 5V: at most 500 mA from a USB 2.0 port, through a 500 mA resettable fuse in the Uno design, shared with the board’s own chips.

Each burst of motor current comes down the USB cable and through that fuse. Both have resistance, and voltage lost across resistance grows with current, so the board’s 5V dips for a moment, even though 360 mA is under the limit. A deep dip trips the ATmega328P’s brown-out detector and the sketch restarts, or the USB chip drops out and the PC plays its disconnect sound.

After a restart, setup() sends the servo to 90 again, which causes another dip. That loop is the twitching. Moving the red wire to its own supply fixes it with no code change, because motor current no longer passes through the Uno.

What you see Cause Fix
The Uno resets, the COM port disappears, or the servo twitches on every move The 5V line dips under the motor’s surge Step 3: give the servo its own supply
Random twitching, or no movement, on a separate battery No common ground, so the signal has no return path Add the jumper from Uno GND to the minus rail (Step 3)
Buzzing and warmth at one end of the sweep The pulse asks for a position past the end stop Set MIN_ANGLE to 20 and MAX_ANGLE to 160, or attach with the data-sheet range: myServo.attach(SERVO_PIN, 1000, 2000); (many servos respond to about 700 to 2300 µs, so travel may be well short of 180 degrees)
It hums and stalls under load, or the gears click The load is too heavy for a 9 g servo with plastic gears Shorten the arm, lighten the load or step up (last table). Never force the shaft round by hand: that drives the motor backwards through the gear train and can strip the small plastic teeth
Nothing moves at all A jumper is loose or in the wrong socket hole, or orange is on a different pin from the sketch. On the battery: the holder is switched off, a cell is in backwards, or the wires sit on different rail pairs Go through the Step 1 or Step 3 table again

Step 3: Power the servo from 4 AA batteries, with a common ground

Four AA cells in the 4-slot holder, alkaline or NiMH, give the SG90 its own supply (see AA NiMH vs alkaline).

Unplug USB and leave the cells out while you wire. The holder’s red and black leads end in bare wire: twist the strands tight and push them into the breadboard’s rails. Use the rail pair on one edge only. The other edge’s pair is separate.

From To Why
Holder red wire Plus rail (red line) Battery positive. Four alkaline cells give 6V nominal, the top of the servo’s 4.8 to 6V range (a new set starts slightly above it, then settles with use). Four NiMH rechargeables give 4.8V, the figure TowerPro prints, so they are the gentler choice
Holder black wire Minus rail (blue line) Battery negative
Servo red Plus rail Motor power now comes from the battery
Servo brown Minus rail Motor current returns to the battery
Servo orange Uno pin 9 Signal, same as before
Uno GND Minus rail The common ground
Uno 5V Nothing. Pull out the red jumper from Step 1 The Uno stays on USB power, and the battery must never reach this pin

Never join the battery’s red wire or the plus rail to the Uno 5V pin. That pin is the board’s 5V line itself, with no regulator in between. A new alkaline pack reads about 4 x 1.6 = 6.4V with no load, above the ATmega328P’s 6.0V maximum (datasheet), and it would push current back up the USB cable into your computer.

Cartoon of a black 4xAA battery holder and a translucent blue SG90 servo sharing the rails of a white breadboard, with one highlighted black ground wire linking the rails to a blue Arduino Uno
Step 3: the battery feeds the servo through the breadboard rails. The highlighted wire from Uno GND to the minus rail is the common ground.

The common ground matters because a voltage is always measured between two points. The Uno makes the pulse between pin 9 and its own GND, and the servo reads it between orange and its own brown wire. With brown on the battery only, the two grounds have no link, so the signal has no complete loop and the servo sees noise. The jumper from Uno GND to the minus rail closes that loop. Motor current stays out of the Uno: battery plus, red wire, motor, brown wire, battery minus.

Fit the cells, switch the holder on, then plug USB back in.

SG90 vs MG90S vs MG996R: when to step up

The SG90 is a 9 g servo with plastic (POM) gears, built for light loads. Its torque figure says how light: 1.3 kg/cm means it holds 1.3 kg at 1 cm from the shaft, so on a 5 cm arm the limit is 1.3 ÷ 5 = 0.26 kg. That is the stall figure, where the motor stops, so a moving load has to be lighter.

Servo Size and weight Gears Stall torque Power Use it when
SG90 23 x 12.2 x 29 mm, 9 g Plastic (POM) 1.3 kg/cm at 4.8V 4.8 to 6V. One unloaded servo can be tested from the Uno 5V pin The load is light: a pointer, a flap, a dustbin lid, a small pan-tilt
MG90S 22.8 x 12.2 x 28.5 mm, 13.4 g (TowerPro) Metal 1.8 kg/cm at 4.8V, 2.2 kg/cm at 6.0V Its own 4.8 to 6V supply The SG90 fits but its gears strip, or the load knocks the arm (robot arm joints, steering)
MG996R 40.7 x 19.7 x 42.9 mm, 55 g (TowerPro) Metal 9.4 kg/cm at 4.8V, 11 kg/cm at 6.0V Its own 4.8 to 6.6V supply. TowerPro lists 1,400 mA at stall and an older TowerPro sheet 2.5 A, so allow 2.5 A for each one from a supply rated for it (a 5V 3A adapter, as in the PCA9685 guide). Never the Uno 5V pin The load is heavy: a large arm joint, a barrier gate, steering on a big chassis. It needs standard-size mounting

For 270 degrees or full rotation, see servo 180 vs 270 vs 360. For many servos at once, the PCA9685 16-channel servo driver guide covers the power and wiring. The smart dustbin, a common RBT project, is a good next build with this same SG90.

FAQ

Can I power an SG90 from the Arduino 5V pin?

Yes, for one SG90 with nothing on its shaft. A load or a second servo can dip the 5V enough to reset the Uno, so use a separate 4.8 to 6V supply and a common ground.

Does an SG90 need a PWM pin on the Uno?

No. The Servo library times the pulses with Timer1 and switches the pin in software, so any digital pin works. Timer1 also drives the PWM on pins 9 and 10, so analogWrite() stops working there once a servo is attached (Servo library notes).

How many SG90 servos can an Arduino Uno control?

The Servo library can signal up to 12. Power runs out first: two stalled servos can ask for 2 x 360 = 720 mA, more than a USB port’s 500 mA.

Last updated November 2026. Stuck? Chat with us on WhatsApp.

Leave a Reply

Your email address will not be published. Required fields are marked *