Components · 3 min read

What Is a Servo Motor? Controlling Servos with Arduino

What is a servo motor, how does it work and how do you connect it to Arduino? SG90 vs MG90S vs MG996R, the Servo library, powering servos and common mistakes.

A servo motor is a small motor whose shaft turns to a set angle and stays there. A regular DC motor keeps spinning; a servo goes exactly to 90 degrees when you ask for 90 degrees and holds the load there. Robot arms, pan-tilt camera mounts, automatic door locks and the control surfaces of model planes are all moved by servos.

SG90
SG90
MG90S
MG90S
MG996R
MG996R

How does a servo motor work?

Inside a servo there are four parts: a small DC motor, a gearbox that lowers the speed and raises the torque, a potentiometer that measures the shaft position, and a control circuit that manages them. The control circuit constantly compares the requested angle with the angle read by the potentiometer and turns the motor until the difference is zero. Thanks to this closed loop, the servo holds its position even under load.

The angle is sent to the servo as a PWM signal: a pulse arrives every 20 ms (50 Hz) and the pulse width sets the angle. About 1 ms means 0°, 1.5 ms means 90° and 2 ms means 180°. Most servos accept a 0.5–2.5 ms range; the exact values vary a little between models.

Servo wires and wiring

Wire colorFunctionWhere it goes on the Arduino
Brown / blackGND (ground)GND
RedPower (+4.8–6 V)5V or an external 5–6 V supply
Orange / yellow / whiteSignal (PWM)Any digital pin (e.g. 9)
Don't power several servos, or a strong servo like the MG996R, from the Arduino's 5V pin. A servo under strain can draw more than 1 A; the board resets and the USB port can be damaged. Use an external 5–6 V supply and always connect its GND to the Arduino's GND.

Which servo should I choose?

FS90R
ModelTorque (approx.)GearsGood for
SG901.8 kg·cmPlasticLight jobs, first experiments, pan-tilt
MG90S2.2 kg·cmMetalSame size as the SG90, more durable
MG996R9–11 kg·cmMetalRobot arms, heavy lids and mechanisms
FS90R1.5 kg·cmPlasticContinuous rotation: small wheeled robots
Continuous rotation servos like the FS90R don't go to an angle; the signal sets speed and direction (90 stops, 0 is full speed one way, 180 full speed the other). If you want position control, choose a standard servo.

Controlling a servo with Arduino: setting the angle with a potentiometer

Potentiometer
Potentiometer
Arduino Uno
Arduino Uno
  1. Connect the servo's brown wire to GND and its red wire to 5V (for a single SG90).
  2. Connect the orange signal wire to digital pin 9.
  3. Connect the outer legs of the potentiometer to 5V and GND and its middle leg to A0.
  4. Upload the code below; the servo should turn between 0 and 180° as you turn the potentiometer.
C++ (Arduino IDE)
1#include <Servo.h>
2
3Servo servo;                       // servo nesnesi / servo object
4const int POT_PIN = A0;            // potansiyometre / potentiometer
5
6void setup() {
7  servo.attach(9);                 // sinyal 9. pinde / signal on pin 9
8}
9
10void loop() {
11  int value = analogRead(POT_PIN);         // 0–1023 oku / read 0–1023
12  int angle = map(value, 0, 1023, 0, 180); // açıya çevir / convert to angle
13  servo.write(angle);                      // servoyu döndür / move the servo
14  delay(15);                               // servo yetişsin / let the servo settle
15}

servo.write(angle) takes an angle from 0 to 180. For finer control, use servo.writeMicroseconds(1500) to set the pulse width directly in microseconds. You can see which of your board's pins are PWM and digital in the pinout tool.

Servos with ESP32 and Raspberry Pi Pico

  • ESP32: the standard Servo library doesn't work; install the ESP32Servo library in the Arduino IDE. It's used the same way. A 3.3 V signal is enough for most servos.
  • Raspberry Pi Pico (MicroPython): set the PWM to 50 Hz and give the pulse width with duty_ns(): 1,000,000 ns ≈ 0°, 1,500,000 ns ≈ 90°, 2,000,000 ns ≈ 180°.
  • On both boards, don't power the servo from the board's 3.3 V pin; use the 5 V line or an external supply.

The most common servo mistakes

  • Jitter and random movement: usually caused by insufficient power. Use an external supply and add a 470–1000 µF capacitor across the servo's supply.
  • Forgetting the common GND: a servo powered from an external supply can't understand the signal unless the grounds are joined.
  • Forcing the servo to its limit: a servo pushing against its mechanical stop buzzes and heats up. If needed, limit the range to 10–170°.
  • Expecting PWM on pins 9 and 10: on the Uno the Servo library uses Timer1, so analogWrite doesn't work on these pins while a servo is attached.
  • Expecting an angle from a continuous rotation servo: models like the FS90R don't know their position; only speed and direction can be controlled.

To see what you can build with servos, check out the robot and motor projects on BlueGrays. If you're new to Arduino, read What Is Arduino? first, and What Is a Breadboard? to build the circuit on a board.

Frequently asked questions

How many degrees does a servo motor turn?

Standard servos turn about 180°; some models are 90° or 270°. Continuous rotation servos turn without limit but don't hold an angle.

Can I power a servo from the Arduino's 5V pin?

You can power a single SG90 with a light load for testing. For several servos, strong models like the MG996R or projects under load, use an external 5–6 V supply and join the grounds.

How many servos can one Arduino control?

The Servo library supports up to 12 servos on the Arduino Uno and 48 on the Mega. For many servos, 16-channel I2C driver boards like the PCA9685 are more practical.

Why is my servo jittering?

The most common causes are insufficient power, a missing common ground and long signal wires. Use a strong supply, add a capacitor to the servo's power and keep the wires short.

What's the difference between a servo motor and a stepper motor?

A servo uses feedback to go to a specific angle and stay there, and it's usually limited to 180°. A stepper turns step by step without limit; it needs a driver board for precise positioning and doesn't measure its own position.

See all projects
Using a Servo Motor
AR-35Beginner
Premium

Using a Servo Motor

The arm of a small servo motor turns to three positions in turn: all the way to the start, right to the middle and all the way to the end, waiting two seconds at each stop.

4.7(49)
69
Servo Motor Operation with Potentiometer
AR-36Beginner
Premium

Servo Motor Operation with Potentiometer

As you turn the potentiometer knob, the servo motor's arm turns right along with it: one end of the knob means zero degrees, the other end means half a turn.

4.6(37)
54
Servo Control with Joystick
AR-60Intermediate
Premium

Servo Control with Joystick

Steer two motors with a joystick, just like turning a security camera. Push the stick left or right and the bottom servo motor slowly turns, push it up or down and the top servo tilts up and down…

4.7(42)
58
360-Degree Servo from a Stepper Motor
AR-68Intermediate
Premium

360-Degree Servo from a Stepper Motor

Teach an ordinary stepper motor to go to any angle you want, all the way around the circle.

4.5(22)
33
ESP32 Servo Motor (Potentiometer Control)
ES-16Intermediate
Premium

ESP32 Servo Motor (Potentiometer Control)

In this project, we control an SG90 servo motor using a potentiometer. We adjust the servo angle by mapping the analog value read from the potentiometer to the 0–180-degree range. The ESP32Servo library generates servo signals on suitable output-capable GPIO pins of the ESP32; this project uses GPIO 18. This is a fundamental control method for robotic arms, camera gimbals, and automatic door mechanisms.

4.3(30)
42
ESP32 RFID Door Lock (RC522 + Servo + OLED + Buzzer + LED)
ES-35Advanced
Premium

ESP32 RFID Door Lock (RC522 + Servo + OLED + Buzzer + LED)

We build a smart door lock with an ESP32, an RC522 RFID module, an SG90 servo, an SSD1306 OLED display, an active buzzer and 2 LEDs. When a card is scanned, its UID is checked against the authorized cards defined in the code; if it matches, the servo unlocks (green LED + 2 short beeps) and locks again after 5 seconds. An unknown card lights the red LED, gives 3 quick beeps and shows its UID on the OLED.

4.8(9)
16
Servo Circle Choreography - Animated Patterns with 32 Servos
AR-97Advanced
Premium

Servo Circle Choreography - Animated Patterns with 32 Servos

A visual animation project driven by 32 servo motors arranged in a circle on an Arduino Mega. The servos are managed in a single array, connected to the Mega's pins 22–53, and perform four motion sequences: a chaotic jitter at random angles, a synchronized sweep, a wave travelling around the circle and a compass needle swinging left and right.

4.5(40)
62