If you are building a robotic arm, a pan-tilt camera mount, or a remote-controlled vehicle, understanding how to control an Arduino servo motor is one of the most important skills you can develop. Servo motors are compact, precise actuators that can rotate to an exact angle — making them ideal for countless projects. In this guide, we compare the two most popular servo motors used with Arduino: the SG90 and the MG996R, and walk you through everything from wiring to code.
Table of Contents
How Servo Motors Work
A servo motor is a closed-loop control device consisting of a DC motor, a gearbox, a potentiometer, and a control circuit — all packed into a small housing. Unlike a regular DC motor that just spins continuously, a servo motor moves to a specific angular position and holds it.
The control signal is a PWM (Pulse Width Modulation) signal sent from the Arduino. The width of the pulse tells the servo which angle to go to:
- ~0.5ms pulse → 0 degrees
- ~1.5ms pulse → 90 degrees (centre)
- ~2.5ms pulse → 180 degrees
This pulse is sent at roughly 50Hz (every 20ms). The internal control circuit reads the pulse width, compares it to the potentiometer reading, and drives the motor until the shaft reaches the correct position. This feedback loop is what makes servos so precise.
SG90 Micro Servo: Specs & Use Cases
The SG90 is probably the most commonly used servo motor in beginner electronics projects worldwide. It is tiny, lightweight, and affordable — and works perfectly for projects that do not require heavy loads.
SG90 Specifications:
- Weight: 9g
- Torque: 1.8 kg/cm (at 4.8V)
- Operating Voltage: 4.8V – 6V
- Operating Speed: 0.1s/60° (at 4.8V)
- Rotation Range: 0° – 180°
- Gear Type: Plastic gears
- Connector: Standard 3-pin (Signal, VCC, GND)
Best use cases for SG90:
- Pan-tilt camera mounts for small cameras
- Robotic fingers and hands (lightweight)
- Small RC aircraft control surfaces
- Miniature robotic arms
- Educational projects and prototyping
- Animatronic faces and puppets
The SG90 can be powered directly from the Arduino 5V pin when only one or two servos are used at low load. However, for sustained use, an external power supply is always recommended.
MG996R High Torque Servo: Specs & Use Cases
The MG996R is the go-to choice when you need more torque and durability. It uses metal gears instead of plastic, making it significantly more robust under load. This is the servo used in serious robotic arms, hexapod robots, and large RC vehicles.
MG996R Specifications:
- Weight: 55g
- Torque: 9.4 kg/cm (at 4.8V), up to 11 kg/cm (at 6V)
- Operating Voltage: 4.8V – 7.2V
- Operating Speed: 0.17s/60° (at 4.8V)
- Rotation Range: 0° – 180°
- Gear Type: All-metal gears
- Connector: Standard 3-pin (Signal, VCC, GND)
- Current Draw: Up to 2.5A under stall
Best use cases for MG996R:
- Robotic arms (shoulder, elbow joints)
- Hexapod robot legs
- RC car steering with heavy loads
- Industrial automation prototypes
- Antenna tracking mounts
- Heavy-load pan-tilt systems
SG90 vs MG996R Comparison Table
| Feature | SG90 | MG996R |
|---|---|---|
| Weight | 9g | 55g |
| Torque | 1.8 kg/cm | 9.4–11 kg/cm |
| Gear Material | Plastic | Metal |
| Operating Voltage | 4.8V – 6V | 4.8V – 7.2V |
| Current Draw (stall) | ~700mA | ~2.5A |
| Price (approx. India) | Rs 60–100 | Rs 200–350 |
| Durability | Moderate | High |
| Best For | Light loads, prototyping | Heavy loads, robotics |
Wiring Servo Motors to Arduino
Both the SG90 and MG996R have the same 3-wire connector:
- Orange/Yellow wire → Signal (PWM pin on Arduino)
- Red wire → VCC (5V or external supply)
- Brown/Black wire → GND
For a single SG90 in a light-duty application:
- Signal → Arduino Pin 9 (or any PWM pin)
- Red → Arduino 5V
- Brown → Arduino GND
For an MG996R or multiple servos, always use an external 5V–6V power supply (see the Power section below). Connect the external supply GND to Arduino GND to create a common ground.
Arduino Servo Library & Code Examples
Arduino comes with the built-in Servo library that makes controlling servo motors extremely simple. You do not need to generate PWM signals manually.
Basic Servo Control (Move to a Fixed Angle)
#include <Servo.h>
Servo myServo; // Create servo object
void setup() {
myServo.attach(9); // Attach servo to pin 9
myServo.write(0); // Move to 0 degrees
delay(1000);
myServo.write(90); // Move to centre
delay(1000);
myServo.write(180); // Move to max
delay(1000);
}
void loop() {
// Servo stays at last position
}
Servo Sweep Example
This classic example sweeps the servo back and forth continuously — great for testing and for applications like radar sweeps or wipers.
#include <Servo.h>
Servo myServo;
int angle = 0;
void setup() {
myServo.attach(9);
}
void loop() {
// Sweep from 0 to 180
for (angle = 0; angle <= 180; angle++) {
myServo.write(angle);
delay(10); // 10ms per degree = ~1.8s for full sweep
}
// Sweep back from 180 to 0
for (angle = 180; angle >= 0; angle--) {
myServo.write(angle);
delay(10);
}
}
Potentiometer-Controlled Servo
Use a potentiometer (or joystick) to manually control the servo angle — great for robotic arm control.
#include <Servo.h>
Servo myServo;
int potPin = A0; // Potentiometer on analog pin A0
int potValue = 0;
int angle = 0;
void setup() {
myServo.attach(9);
Serial.begin(9600);
}
void loop() {
potValue = analogRead(potPin); // Read 0-1023
angle = map(potValue, 0, 1023, 0, 180); // Map to 0-180
myServo.write(angle);
Serial.print("Angle: ");
Serial.println(angle);
delay(15);
}
Controlling Multiple Servos
The Arduino Servo library supports up to 12 servos on most boards. Each servo needs its own Servo object and is attached to a separate pin. For a robotic arm with 4 servos:
#include <Servo.h>
Servo base; // Base rotation
Servo shoulder; // Shoulder joint
Servo elbow; // Elbow joint
Servo gripper; // Gripper
void setup() {
base.attach(3);
shoulder.attach(5);
elbow.attach(6);
gripper.attach(9);
// Move all to start position
base.write(90);
shoulder.write(90);
elbow.write(90);
gripper.write(0); // Gripper open
delay(1000);
}
void loop() {
// Example: Pick and place sequence
shoulder.write(45); // Lower arm
delay(500);
gripper.write(90); // Close gripper
delay(500);
shoulder.write(90); // Raise arm
delay(500);
base.write(180); // Rotate base
delay(500);
shoulder.write(45); // Lower arm again
delay(500);
gripper.write(0); // Open gripper - release
delay(500);
shoulder.write(90);
base.write(90);
delay(1000);
}
Powering Servos Properly (External Power Supply)
This is the most overlooked aspect of servo projects. The Arduino 5V pin can only supply about 500mA total. A single SG90 at load can draw 300–700mA, and an MG996R can draw up to 2.5A at stall. Drawing this from the Arduino will cause brown-outs, erratic behaviour, or permanent damage to your board.
The correct approach:
- Use a dedicated 5V–6V power supply or 4x AA batteries (6V) for servos
- Connect the servo VCC (red wire) to the external supply positive
- Connect the servo GND (black/brown wire) to the external supply negative AND to Arduino GND (common ground)
- Connect the signal wire to the Arduino PWM pin only — do NOT power the servo from Arduino 5V
- Add a 100µF capacitor across the servo power rails to smooth voltage spikes
For MG996R robots with 4–6 servos, a 5V 5A or 6V 3A regulated power supply is recommended.
Project Ideas Using Servo Motors
- Pan-Tilt Camera Mount: Two SG90 servos for X and Y axis control of a camera
- Robotic Arm: 4–6 MG996R servos for a desktop robotic arm
- Automatic Plant Watering: One servo to open/close a water valve
- RC Boat Steering: SG90 to steer a rudder, controlled via RF module
- Smart Door Lock: MG996R to turn a deadbolt lock mechanism
- Animatronic Eyes: Two SG90s for realistic eye movement
Frequently Asked Questions
Q: Can I use a servo motor with any Arduino pin?
You should use PWM-capable pins (marked with ~ on the Arduino Uno: pins 3, 5, 6, 9, 10, 11). The Servo library technically works on any pin by bit-banging, but PWM pins give the cleanest signal.
Q: Why does my servo jitter or vibrate when stationary?
Jitter is usually caused by insufficient power supply, a noisy power rail, or a poorly written delay in the code. Add a 100µF capacitor across the servo power rails and ensure you are using an external supply for the MG996R.
Q: What is the difference between analog and digital servos?
Analog servos update their position at 50Hz. Digital servos (like the MG996R) update at up to 300Hz, giving faster response, higher holding torque, and better precision. For Arduino projects, both work fine.
Q: Can the SG90 rotate 360 degrees?
Standard SG90 servos rotate 0–180 degrees only. Continuous rotation servos (a modified version) spin continuously and are used for wheels or conveyor belts — not for positional control.
Q: How many servos can Arduino Uno control?
The Arduino Servo library supports up to 12 servos on the Uno. However, power budget is the real limit. Always use an external supply and add a PCA9685 servo driver board if you need more than 6 servos.
Start Building Today!
Shop Arduino boards, servo motors, and robotics components at Zbotic.in — India’s trusted electronics store.
Add comment