SG90 Servo Motor Basics: What You Need to Know

A servo motor is a closed-loop system that uses position feedback to control its motion and final position. The SG90 Servo Motor is a popular, compact, and lightweight servo motor widely used in electronics, robotics, and DIY projects. It is known for its low cost and ease of use, especially with microcontrollers like Arduino, Raspberry Pi, and ESP boards.

SG90 Servo Motor

SG90 Servo Motor

Internal Components

Servo motor internal structure by Circuit Basics

DC Motor – Provides rotational motion.

Gearbox – Reduces the high-speed, low-torque output of the DC motor to a low-speed, high-torque rotation.

Potentiometer (Position Sensor) – Detects the shaft angle and provides feedback on the current position of the output shaft.

Control Circuit – Compares the desired position, received via PWM signal, with the actual position detected by the potentiometer, and drives the motor to correct any difference.

Control Pins

Servo motors typically have three pins: VCC, GND, and Signal. The Signal pin is used to transmit control signals from the microcontroller to the servo, enabling it to rotate to a specific angle.

  • VCC (Red): Connect to the Arduino’s 5V pin for power.
  • SIG (Yellow/Orange): Connect to the Arduino digital PWM pin.
  • GND (Black/Brown): Connect to the Arduino’s GND pin.

Working Principle

The SG90 servo motor operates using Pulse Width Modulation (PWM) within a closed-loop control system. As an analog micro servo, it adjusts its angular position based on variable pulse widths and continuously corrects itself to maintain the target angle.

Servo Motor Work Principle

Servo Motors, how do they work? by The Engineering Mindset

1. PWM Signal

A microcontroller or other control device sends a PWM signal to the servo’s signal pin. PWM determines the target angle.

2. Position Control

The SG90 servo motor positions its shaft based on a PWM signal, with the pulse width determining the angle. For example,

  • 1 ms pulse: 0°
  • 1.5 ms pulse: 90°
  • 2 ms pulse: 180°
3. Control Circuit

The control circuit interprets the incoming PWM signal.

4. DC Motor Control

The control circuit drives a DC motor to rotate the output shaft to the corresponding angle.

5. Gear System

The DC motor is geared down to provide higher torque for controlling the servo arm’s position.

6. Feedback System

As the motor rotates, the potentiometer provides real-time position feedback.

7. Position Correction

The servo continuously monitors the signal. If a discrepancy exists between the desired and actual positions, the control circuit activates the DC motor to adjust the output shaft accordingly. The motor stops once the shaft reaches the target angle.

Key Features and Characteristics

  • Size: Compact and lightweight, making it ideal for a wide range of applications.
  • Torque: Provides moderate torque.
  • Rotation: Capable of rotating up to 180 degrees.
  • Control: Operated via a PWM signal, which sets the servo’s target position.
  • Applications: Commonly found in robotics, RC vehicles, and DIY electronics.
  • Cost: Affordable and widely available
  • Low Power Consumption: Suitable for battery-powered applications.

Built-in Library

  • Library Name: Servo
  • Included with Arduino IDE: Yes
  • Supports: SG90 and other standard hobby servo motors
#include <Servo.h>

Servo myServo;  // create servo object

void setup() {
  myServo.attach(9);  // attach to digital pin 9
}

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);
}

      Rotate the servo to an angle we desire: pass the desired angle as an argument into the servo.write() function.

      Pin Wiring

      SG90 Servo Motor Wiring