Introduction to Servo Motors and Their Use with Arduino Uno
A servo motor is a special type of motor designed for precise control of position, angle, and speed. Unlike ordinary DC motors that only rotate continuously in one direction, a servo motor can be set to a specific angle (e.g., 0°, 90°, 180°). This makes it ideal for applications such as robotic arms, steering mechanisms, automatic door systems, and model airplanes.
How a Servo Motor Works
A servo motor is made up of:
- A DC motor that generates the rotation,
- A gear system that reduces speed and increases torque,
- A potentiometer that measures the current shaft angle,
- An internal control circuit that compares the desired and actual positions and adjusts the rotation accordingly.
Controlling with Arduino Uno
The Arduino Uno controls a servo motor using a PWM signal (Pulse Width Modulation),
typically generated with the Servo.h library.
The standard control signal has a period of 20 ms (50 Hz), while the pulse width determines the angle:
- 1 ms pulse → approximately 0°
- 1.5 ms pulse → approximately 90° (center position)
- 2 ms pulse → approximately 180°
Power and Electrical Characteristics
Most small servo motors (such as SG90 or MG90S) operate at 5 V and draw about 100 mA when idle, up to 500 mA under load. Therefore, it’s recommended not to power the servo directly from the Arduino’s 5V pin when using multiple servos — instead, use an external power source (for example, a regulated 5V battery or adapter).
Wiring the Servo to Arduino
A servo typically has three wires:
- Red – +5V (power supply)
- Brown or black – GND (ground)
- Yellow or orange – Signal (PWM control from Arduino, usually pin 9)
Example Code
#include <Servo.h>
Servo motor;
void setup() {
motor.attach(9); // pin 9 for PWM signal
}
void loop() {
for (int angle = 0; angle <= 180; angle++) {
motor.write(angle);
delay(15);
}
for (int angle = 180; angle >= 0; angle--) {
motor.write(angle);
delay(15);
}
}
Code Explanation
In this example, the servo slowly moves from 0° to 180° and back again.
The motor.write(angle) command sends a PWM signal corresponding to the specified angle.
The delay(15) function allows enough time for the servo to reach each new position before moving again.
Applications of Servo Motors
Servo motors are widely used in various projects:
- Robotic arms and manipulators
- Smart locking systems
- Model airplanes, cars, and drones
- Automated valves and motion control systems
Thanks to their simplicity and strong support in the Arduino environment, servo motors are an excellent starting point for learning mechatronics and actuator control.
Exercise: Servo Motor Sweep
In this exercise, we will use basic components from the Starter Kit. Although larger servo motors often require external power to provide enough current at startup, here we will use the micro servo motor SG90.
Power will be supplied directly from the 5V pin on the Arduino, and no additional resistors will be needed.
The control signal pin must be connected to a PWM pin, because the servo angle is controlled using a PWM (Pulse Width Modulation) signal. This signal is easily generated using the Servo.h Arduino library.
The goal of this exercise is to rotate the servo motor to specific angles in both directions continuously, as a basic demonstration of how servo positioning works.
SG90 Servo Specifications:
- Operating voltage: 4.8V – 6.0V
- Rotation range: 180°
- Torque: about 1.8 kg·cm at 4.8V
- Current consumption: approx. 100 mA idle, up to 500 mA at startup
The SG90 servo motor uses an internal potentiometer and gear system for precise positioning. Because of its low power and voltage requirements, it is ideal for beginner Arduino projects and does not require additional components.
How the Servo Works
The servo motor has three wires:
- Red – Power (+5V)
- Brown or Black – Ground (GND)
- Orange or Yellow – Signal (PWM)
The Arduino sends a sequence of pulses whose width determines the servo position. A 1 ms pulse usually means 0°, 1.5 ms means 90°, and 2 ms means 180°. The Servo.h library automatically generates these pulses, so the user only needs to specify the desired angle.
In this exercise, the servo will sweep smoothly from 0° to 180°, then back from 180° to 0°, repeating this motion endlessly. This demonstrates the basic concept of position control using PWM signals.
Power and Stability Notes
The SG90 servo can be powered directly from the Arduino board. However, if multiple servos or a larger model are used, it is recommended to use an external 5V power supply. Always connect a common ground (GND) between the Arduino and the external power source.
If the Arduino resets or the servo jitters, the cause is likely a voltage drop due to current spikes at startup. Adding a 100–470 µF capacitor between 5V and GND can help stabilize the power.
Common Problems and Solutions
- Servo does not move: Check PWM pin connection and wiring.
- Servo jitters or twitches: Power supply is unstable, use shorter wires or external 5V.
- Arduino resets when servo starts: Startup current too high; add a capacitor or external supply.
When the program runs, the servo will move smoothly left and right. This simple motion forms the basis for more advanced projects like robotic arms, sensor mounts, and automated mechanisms.
Wiring Diagram
In Figure 1, the wiring diagram is shown. The servo motor component has three connection pins — for power (VCC), ground (GND), and a digital control signal (PWM).
The power pin is connected using a red wire to the 5V pin on the Arduino UNO board, providing the necessary supply voltage for the servo.
The ground pin (usually a black or brown wire) is connected to one of the Arduino GND pins. All GND pins on the Arduino are internally connected, so it doesn’t matter which one you use.
The control (signal) wire, typically orange or yellow,
is connected to the digital pin 9 on the Arduino.
This pin is marked with a ~ symbol, which indicates that it supports
PWM (Pulse Width Modulation).
What is PWM?
PWM stands for Pulse Width Modulation, a technique that simulates analog control using a digital signal. The Arduino sends a series of pulses where the width (duration) of each pulse determines the desired position of the servo motor shaft.
For example, a pulse lasting about 1 millisecond sets the servo to approximately 0°,
1.5 milliseconds to 90°, and 2 milliseconds to 180°.
The Arduino’s Servo.h library automatically generates these pulses,
making it simple to control the servo’s angle with a single command like myservo.write(angle);.
|
Previous
|< Arduino-Ultrasonic Sensor |
Next
Moisture Soil Sensor >| |

