How to Use a Servo Motor with Arduino: Wiring, 180° and 360°
Description
In this lesson you will learn how a servo motor works with Arduino, which models are commonly used, how to wire one, and how to control both a 180-degree servo and a 360-degree continuous-rotation servo. It is a quick guide for robots, robotic arms, moving sensors and small Arduino projects.
Required components:
- 1x Arduino UNO
- 1x Servo motor (SG90 recommended)
- Jumper wires (and an optional breadboard)
Servo motor with Arduino: how it works and how to control it
What is a servo motor?
A servo motor, usually called a servo, is a compact actuator that combines a motor,
gears and control electronics.
Arduino sends a control signal to the servo and its internal circuit manages the movement automatically.
A positional servo moves to a requested angle, while a continuous-rotation servo uses the same type of control signal to set direction and speed.
Types of servo motors: SG90S, MG90S and MG996R
Servo motors mainly differ in size, torque, gear material and type of movement.
For Arduino projects, the most common choices include small micro servos and larger standard high-torque servos.
SG90S: lightweight micro servo
The SG90S is a small and lightweight micro servo suited to simple mechanisms, moving sensors and compact projects. It is a good choice when low weight matters more than high torque.
MG90S: micro servo with metal gears
The MG90S keeps a compact form factor but uses metal gears. It is generally more durable than a plastic-geared micro servo and works well in small robots and mechanisms that need a little more strength.
MG996R: standard high-torque servo
The MG996R is larger and more powerful and is often used when a project must move heavier loads, such as robotic arms or joints. It draws more current than a micro servo, so a suitable external power supply is recommended.
Wiring: how to connect a servo motor to Arduino
Signal → pin 9 · VCC → 5V · GND → GND
The signal wire controls the servo and is connected to digital pin 9 in this example.
Wire colors can vary between manufacturers, so always check the markings or datasheet for your servo.
For high-current servos such as the MG996R, use a suitable external power supply and connect the supply GND to Arduino GND.
180-degree servo: position control with Arduino
A 180° servo motor is a positional servo: Arduino sends an angle and the servo moves toward that position.
With the Servo library, you can use servo.write() with values approximately between 0 and 180.
The actual mechanical travel can vary slightly between models.
// https://nemiatools.com
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9); // Servo signal pin
}
void loop() {
myServo.write(0); // Move to 0 degrees
delay(1000);
myServo.write(90); // Move to 90 degrees
delay(1000);
myServo.write(180); // Move to 180 degrees
delay(1000);
}
In this example the servo moves between 0°, 90° and 180°. You can replace these values with the angle required by your project.
360-degree servo: direction and speed control with Arduino
A 360° continuous-rotation servo works differently: you cannot command it to move to a precise angle.
The control value sets its rotation direction and speed instead.
On many models, a value close to 90 stops the servo, lower values rotate it in one direction and higher values rotate it in the other.
// https://nemiatools.com
#include <Servo.h>
Servo myServo;
void setup() {
myServo.attach(9); // Servo signal pin
}
void loop() {
myServo.write(0); // Rotate in one direction
delay(2000);
myServo.write(90); // Stop
delay(1000);
myServo.write(180); // Rotate in the opposite direction
delay(2000);
myServo.write(90); // Stop
delay(1000);
}
The stop point of a 360° servo is not always exactly 90.
If the servo slowly moves when it should be stopped, try nearby values such as 89, 90 or 91 until you find the correct neutral point.