Introduction to SG 90 Servos
SG 90 servos are miniature servo motors widely used in robotics, RC vehicles, and various Arduino projects. These small, lightweight, and affordable servos offer precise control and are easy to integrate with microcontrollers like Arduino. In this article, we’ll explore the basics of SG 90 servos, their specifications, and how to control them using Arduino.
What are SG 90 Servos?
SG 90 servos are tiny geared motors that can precisely rotate to a specific angular position based on a control signal. They consist of a DC motor, gears, a potentiometer for position feedback, and a control circuit. The servo’s output shaft is connected to the potentiometer, which allows the control circuit to monitor the current position of the shaft.
SG 90 Servo Specifications
Here are the key specifications of the SG 90 servo:
| Specification | Value |
|---|---|
| Operating Voltage | 4.8V – 6V |
| Torque | 1.8 kg-cm at 4.8V, 2.2 kg-cm at 6V |
| Speed | 0.1 sec/60° at 4.8V, 0.08 sec/60° at 6V |
| Gear Type | Nylon |
| Rotation | 0° – 180° |
| Dimensions | 22.2 x 11.8 x 31 mm |
| Weight | 9 grams |
Controlling SG 90 Servos with Arduino
Arduino Servo Library
Arduino provides a built-in Servo library that simplifies the control of servo motors. This library abstracts the low-level details of generating PWM (Pulse Width Modulation) signals required to control the servos. To use the Servo library, you need to include it at the beginning of your Arduino sketch:
#include <Servo.h>
Connecting SG 90 Servo to Arduino
To connect an SG 90 servo to an Arduino, you need to identify the servo’s three wires:
- Brown or Black: Ground (GND)
- Red: Power (VCC)
- Orange or Yellow: Signal (PWM)
Connect the servo wires to your Arduino as follows:
| Servo Wire | Arduino Pin |
|---|---|
| Ground (Brown or Black) | GND |
| Power (Red) | 5V |
| Signal (Orange or Yellow) | Digital Pin (e.g., 9) |
It’s important to note that servos can draw a significant amount of current, especially when under load. If you’re using multiple servos or other power-hungry components, it’s recommended to use an external power supply to power the servos separately from the Arduino.
Creating a Servo Object
To control a servo using the Arduino Servo library, you need to create a Servo object. Here’s an example of how to create a Servo object and attach it to a specific pin:
Servo myServo;
void setup() {
myServo.attach(9); // Attach the servo to pin 9
}
In this example, we create a Servo object named myServo and attach it to digital pin 9 in the setup() function.
Controlling Servo Position
Once you have created a Servo object and attached it to a pin, you can control the servo’s position using the write() function. The write() function takes an angle value in degrees (0-180) as a parameter and rotates the servo to that position. Here’s an example:
void loop() {
myServo.write(0); // Rotate to 0 degrees
delay(1000);
myServo.write(90); // Rotate to 90 degrees
delay(1000);
myServo.write(180); // Rotate to 180 degrees
delay(1000);
}
In this example, the servo rotates to 0 degrees, waits for 1 second, then rotates to 90 degrees, waits for another second, and finally rotates to 180 degrees before repeating the sequence.
Controlling Servo Speed
By default, the Servo library doesn’t provide direct control over the speed at which the servo rotates. However, you can achieve speed control by incrementally changing the servo position over time. Here’s an example:
void loop() {
for (int pos = 0; pos <= 180; pos += 1) {
myServo.write(pos);
delay(15);
}
for (int pos = 180; pos >= 0; pos -= 1) {
myServo.write(pos);
delay(15);
}
}
In this example, the servo gradually rotates from 0 to 180 degrees and then back to 0 degrees, with a small delay between each incremental position change. By adjusting the delay value, you can control the speed of the servo rotation.
Using Multiple Servos
You can control multiple servos with Arduino by creating multiple Servo objects and attaching each servo to a different digital pin. Here’s an example of controlling two servos:
Servo servo1;
Servo servo2;
void setup() {
servo1.attach(9);
servo2.attach(10);
}
void loop() {
servo1.write(0);
servo2.write(180);
delay(1000);
servo1.write(90);
servo2.write(90);
delay(1000);
}
In this example, we create two Servo objects, servo1 and servo2, and attach them to digital pins 9 and 10, respectively. In the loop() function, we control the positions of both servos independently.
Troubleshooting Common Issues
Jittery or Unresponsive Servo
If your servo is jittery or unresponsive, it could be due to several reasons:
-
Insufficient power supply: Ensure that your servo is receiving enough power. If the servo draws too much current, it can cause the Arduino’s voltage to drop, leading to erratic behavior. Use an external power supply if necessary.
-
Incorrect wiring: Double-check your wiring connections. Make sure the servo wires are connected to the correct pins on the Arduino.
-
Mechanical issues: Check for any mechanical obstructions or damage to the servo gears. If the servo has been subjected to excessive force or shock, it may not function properly.
Servo Not Rotating to the Correct Angle
If your servo is not rotating to the correct angle, consider the following:
-
Calibration: Servos may have slight variations in their range of motion. You can calibrate your servo by adjusting the minimum and maximum pulse widths in the Arduino code.
-
Timing: Ensure that you are providing sufficient delay between servo movements to allow the servo to reach its target position.
-
Servo limitations: Some servos may have a limited range of motion due to physical constraints or manufacturing tolerances. Refer to the servo’s datasheet for its specific rotation range.

Conclusion
SG 90 servos are versatile and easy-to-use miniature servo motors that can add precise motion control to your Arduino projects. By using the Arduino Servo library, you can quickly integrate these servos into your sketches and control their position and speed. Whether you’re building a Robotic Arm, a pan-tilt camera mount, or any other project that requires accurate angular movement, SG 90 servos are a reliable and affordable choice.
FAQ
-
What is the operating voltage range for SG 90 servos?
SG 90 servos can operate with a voltage range of 4.8V to 6V. It’s important to provide a stable power supply within this range to ensure optimal performance and prevent damage to the servo. -
Can I control servos directly from the Arduino’s power pins?
While it is possible to power a servo directly from the Arduino’s power pins, it is not recommended, especially when using multiple servos or other power-demanding components. Servos can draw significant current, which can cause voltage drops and affect the Arduino’s stability. It’s best to use a separate external power supply to power the servos. -
How can I make my servo rotate continuously?
SG 90 servos are designed for angular position control and do not support continuous rotation by default. However, you can modify the servo by removing the position feedback potentiometer and replacing it with fixed resistors. This modification allows the servo to rotate continuously, but it will no longer have position control capabilities. -
What is the resolution of the SG 90 servo?
The resolution of an SG 90 servo refers to the smallest angle increment it can achieve. Typically, SG 90 servos have a resolution of about 1 degree, meaning they can rotate in increments of approximately 1 degree. However, the actual resolution may vary slightly due to mechanical limitations and manufacturing tolerances. -
Can I control servos using PWM signals from other microcontrollers?
Yes, you can control SG 90 servos using PWM signals from other microcontrollers, such as Raspberry Pi, ESP32, or custom circuits. The principle remains the same: generate the appropriate PWM signal with a specific pulse width to control the servo’s position. Refer to the documentation of your specific microcontroller for instructions on generating PWM signals.
