SG90 Servo Motor Interfacing with Arduino: Complete Beginner Guide

SG90 Servo Motor Interfacing with Arduino: Complete Beginner Guide

Servo motors are among the most popular actuators used in Arduino and robotics projects. Whether you're building a robotic arm, pan-tilt camera, smart door lock, RC vehicle, or an automated mechanism, the SG90 Micro Servo Motor is an excellent choice for beginners because it is compact, affordable, lightweight, and easy to control.

Unlike ordinary DC motors that rotate continuously, an SG90 servo motor can move to a precise angle between 0° and 180°, making it ideal for applications requiring accurate positioning.

In this beginner-friendly guide, you'll learn everything about interfacing an SG90 servo motor with an Arduino Uno, including wiring, Arduino code, PWM control, troubleshooting, and practical applications.

What is an SG90 Servo Motor?

The SG90 Micro Servo Motor is a miniature rotary actuator designed for precise angular movement. It contains a small DC motor, reduction gears, a control circuit, and a position feedback potentiometer enclosed in a compact plastic housing.

Unlike a normal DC motor, the SG90 continuously monitors its shaft position and automatically adjusts the motor until the desired angle is reached.

Because of its high precision and low cost, it has become one of the most widely used servo motors for:

  • Arduino projects
  • Robotics
  • IoT systems
  • RC airplanes
  • Smart home automation
  • Educational STEM kits
  • DIY electronics projects

SG90 Servo Motor Specifications

Feature Specification
Operating Voltage 4.8V – 6V DC
Recommended Voltage 5V
Rotation Angle 0° to 180°
Control Signal PWM
Weight Approximately 9g
Stall Torque Around 1.8 kg·cm @ 4.8V
Operating Speed 0.12 sec/60°
Gear Material Plastic
Cable Length Approximately 25cm

The SG90 is designed for lightweight applications and is not suitable for heavy mechanical loads.

SG90 Servo Pinout

The SG90 servo motor has three wires, each with a specific function.

Wire Color Function
Brown Ground (GND)
Red +5V Power Supply
Orange Signal (PWM)

Brown Wire (Ground)

The brown wire connects to the Arduino GND pin and completes the electrical circuit.

Red Wire (Power)

The red wire supplies 5V power to the servo motor.

Orange Wire (Signal)

The orange wire receives PWM (Pulse Width Modulation) signals from the Arduino, allowing the servo to rotate to the desired position.

How Does an SG90 Servo Motor Work?

Unlike ordinary motors that rotate continuously, a servo motor works as a closed-loop control system.

Inside the SG90 servo are:

  • Small DC motor
  • Gear reduction system
  • Position sensor (potentiometer)
  • Electronic controller

When the Arduino sends a PWM signal, the internal controller compares the desired angle with the current shaft position. If the positions do not match, the controller drives the motor until the correct angle is reached.

This continuous feedback system makes servo motors extremely accurate.

PWM Control Explained

The SG90 servo motor does not rotate according to voltage.

Instead, it uses Pulse Width Modulation (PWM) signals.

Typical control pulses are:

Pulse Width Servo Position
1.0 ms
1.5 ms 90°
2.0 ms 180°

Arduino's Servo library automatically generates these PWM pulses, making servo control very simple.

Components Required

To complete this project, you'll need:

  • Arduino Uno R3
  • SG90 Micro Servo Motor
  • Breadboard
  • Jumper Wires
  • USB Cable
  • Arduino IDE installed on your computer

All these components are commonly used in beginner electronics and robotics projects.

Arduino SG90 Wiring Diagram

Connect the SG90 servo motor to the Arduino Uno as follows:

Arduino Uno SG90 Servo
5V Red Wire
GND Brown Wire
Digital Pin 9 Orange Wire (Signal)

This simple three-wire connection is sufficient for basic servo control projects.

Real Hardware Connection

The real hardware setup includes:

  • Arduino Uno
  • SG90 Servo Motor
  • Breadboard
  • Jumper wires
  • USB connection to the computer

Double-check all wiring before uploading the program to avoid incorrect connections or unexpected servo movement.

Programming the SG90 Servo Motor with Arduino

One of the biggest advantages of using the SG90 servo motor is Arduino's built-in Servo Library, which makes servo control extremely simple. Instead of manually generating PWM signals, you only need a few lines of code to rotate the servo to any angle between 0° and 180°.

Installing the Servo Library

The Arduino Servo Library is included with the Arduino IDE by default.

To use it, simply include the following line at the beginning of your sketch:


#include <Servo.h>

No additional downloads or installations are required.

Complete Arduino Code

#include <Servo.h>

Servo myServo;

void setup()
{
    myServo.attach(9);
}

void loop()
{
    myServo.write(0);
    delay(1000);

    myServo.write(90);
    delay(1000);

    myServo.write(180);
    delay(1000);
}

Upload this sketch to your Arduino Uno. The SG90 servo motor will rotate to 0°, then 90°, then 180°, pausing for one second at each position before repeating the cycle.

Code Explanation

Let's understand what each part of the program does.

Include the Servo Library


#include <Servo.h>

This line loads the Arduino Servo Library, which provides built-in functions for controlling servo motors.

Create a Servo Object


Servo myServo;

This creates a servo object named myServo that will be used throughout the program.

Attach the Servo


myServo.attach(9);

This connects the servo object to Digital Pin 9 on the Arduino.

If your signal wire is connected to another PWM-capable pin, simply replace 9 with the appropriate pin number.

Rotate to 0 Degrees


myServo.write(0);

Moves the servo shaft to the starting position.

Wait One Second


delay(1000);

Keeps the servo at its current position for one second.

Rotate to 90 Degrees


myServo.write(90);

Moves the servo to the center position.

Rotate to 180 Degrees


myServo.write(180);

Moves the servo to its maximum rotation angle.

Understanding Servo Rotation

The SG90 servo motor can rotate to different positions depending on the PWM signal received from the Arduino.

Angle Position
Fully Left
90° Center
180° Fully Right

Most standard SG90 servos support approximately 180 degrees of movement. Avoid forcing the servo beyond its mechanical limits, as this may damage the internal gears.

Sweep Motion

The example program performs a simple sweep:


0°

↓

90°

↓

180°

↓

Repeat

This is commonly used to verify that the wiring and code are working correctly before integrating the servo into a larger project.

Why Use the Servo Library?

The Servo Library offers several advantages:

  • Easy-to-understand programming interface
  • Precise angle control
  • Reliable PWM signal generation
  • Supports multiple servo motors
  • Compatible with most Arduino development boards

It allows beginners to focus on building projects instead of dealing with complex timing calculations.

Powering the SG90 Servo Motor

Although the SG90 can operate directly from the Arduino's 5V pin for small demonstration projects, this is not always the best option.

For larger projects or when using multiple servos:

  • Use a regulated 5V external power supply
  • Connect the external power supply ground to the Arduino GND
  • Avoid powering several servos directly from the Arduino board
  • Ensure the power supply can deliver sufficient current during servo movement

A stable power source helps prevent unexpected resets and improves servo performance.

Common Wiring Mistakes

Beginners often encounter issues due to simple wiring errors. Check the following if your servo does not work correctly:

  • Brown wire connected to the wrong pin
  • Red wire not connected to a stable 5V supply
  • Orange signal wire connected to the wrong Arduino pin
  • Loose jumper wire connections
  • Servo powered with insufficient current
  • Code uploaded to the wrong Arduino board or COM port

Verifying these points usually resolves most beginner issues.

Testing Your SG90 Servo

Before using the servo in a robotics project, perform these checks:

  • Servo rotates smoothly to all programmed angles
  • No unusual vibration or clicking sounds
  • Wires remain securely connected
  • Servo returns accurately to each commanded position
  • Arduino uploads the sketch without errors

If all checks pass, your SG90 servo motor is ready for use in practical Arduino projects.

Troubleshooting SG90 Servo Motor

Even with correct wiring and code, beginners may occasionally face issues while using an SG90 servo motor. The following troubleshooting tips can help resolve the most common problems.

Problem Possible Cause Solution
Servo does not move Incorrect wiring Verify the Brown, Red, and Orange wire connections.
Servo vibrates continuously Insufficient power Use a stable 5V power supply.
Servo moves randomly Loose signal wire Check the PWM wire connected to Arduino D9.
Arduino keeps restarting Servo drawing excessive current Use an external regulated 5V power supply and connect the grounds together.
Servo rotates only partially Wrong code or mechanical obstruction Verify the program and ensure nothing is blocking the servo horn.
Servo becomes hot Excessive load Reduce the mechanical load or use a higher-torque servo.

Best Practices

Follow these recommendations for reliable servo operation:

  • Use a regulated 5V power supply.
  • Keep jumper wires short and secure.
  • Never force the servo shaft by hand.
  • Disconnect power before changing wiring.
  • Use quality jumper wires and breadboards.
  • Avoid placing excessive mechanical load on the SG90 servo.
  • Always test with a simple example before integrating into larger projects.

Following these practices improves reliability and extends the lifespan of the servo motor.

Applications of the SG90 Servo Motor

The SG90 Micro Servo Motor is widely used in educational, hobby, and automation projects because of its compact size and precise angular control.

Common applications include:

  • Robotic Arms
  • Pan-Tilt Camera Systems
  • Smart Door Locks
  • Automatic Gates
  • RC Airplanes
  • Robot Cars
  • DIY Electronics Projects
  • Educational Robotics
  • Motion Control Systems
  • Home Automation
  • STEM Learning Kits
  • Sensor Positioning Mechanisms

Because it is inexpensive and beginner-friendly, the SG90 is often the first servo motor used in Arduino and robotics projects.

Frequently Asked Questions (FAQs)

Can I power the SG90 directly from the Arduino?

Yes, for simple demonstration projects. However, if you are using multiple servos or placing the servo under load, an external regulated 5V power supply is recommended.

What is the operating voltage of the SG90?

The SG90 operates between 4.8V and 6V, with 5V being the recommended supply voltage.

Which Arduino pin is used to control the servo?

Any supported digital pin can be used with the Arduino Servo Library. In this tutorial, Digital Pin 9 is used.

Can the SG90 rotate continuously?

No. The standard SG90 servo rotates approximately 180 degrees. Continuous rotation versions are different products and operate differently.

Can I connect multiple SG90 servos to one Arduino?

Yes. The Arduino Servo Library supports multiple servos. For projects with several servos, use an external 5V power supply capable of delivering enough current.

Why does my servo shake or jitter?

Servo jitter is usually caused by:

  • Low supply voltage
  • Loose wiring
  • Electrical noise
  • Insufficient current from the power source

Which programming language is used?

Arduino sketches are written in C/C++ using the Arduino IDE.

Conclusion

The SG90 Micro Servo Motor is one of the best choices for beginners who want to learn motion control with Arduino. Its simple three-wire interface, accurate positioning, and extensive community support make it an essential component for robotics, automation, IoT, and educational projects.

By following this guide, you have learned:

  • What the SG90 Servo Motor is
  • Servo pinout and specifications
  • PWM control
  • Arduino wiring
  • Complete Arduino program
  • Code explanation
  • Servo rotation
  • Troubleshooting techniques
  • Practical applications

Once you are comfortable controlling a single servo motor, you can expand your projects by using multiple servos, wireless control with ESP32, or dedicated servo driver boards.

🌐 Original Article (Chip.pk Knowledge Hub)

Read the complete beginner-friendly guide on the official Chip.pk Knowledge Hub, where you'll find detailed tutorials, product recommendations, wiring diagrams, and electronics learning resources.

📘 GitHub Repository

Access the complete documentation, source code, wiring diagrams, and project resources on GitHub.

🛠 Hackster.io Project

Follow the hands-on project with practical implementation, components, wiring, and code examples.

✍️ Medium Article

Read this tutorial in a clean, distraction-free format on Medium.

💻 DEV Community

Explore the developer-focused version with syntax-highlighted code, wiring diagrams, and implementation details.


📚 Continue Learning & Explore More Resources

Expand your Arduino and robotics knowledge with these beginner-friendly guides from the Chip.pk Knowledge Hub:

Recommended Products

Build your next project

Explore genuine electronics and embedded systems products

Shop Arduino, ESP32, Raspberry Pi, STM32, robotics, sensors, power modules, LED lighting and electronic components from Chip.pk.

Explore Products