How to Use The SG90 Servo Motor

The SG90 Servo Motor is an actuator that produces a rotary motion approximately from 0° to 180°. The output shaft is attached to the potentiometer so it only rotates a 180°.
Inside the SG90 Servo Motor, there is a small DC motor, A plastic gears to increase the torque, A potentiometer to give us the current position of the output shaft, And a control circuit at the bottom. You can use the servo motor to control nicely the direction of an RC car, plane, or boat, To make a robotic arm, A spider robot…

3 wires coming out from the Servo
The Red wire is for powering the device with 5v
The Brown wire is the GND
The Yellow wire is for controlling the servo position with the PWM signal

How Does The SG90 Servo Motor Works

This component works in a closed-loop system, Which means it uses the potentiometer as a feedback signal to achieve the desired result.

Closed-Loop-System-SG90-Servo-Motor-Arduino

The control circuit contains an H Bridge to control the direction of the DC motor, A comparator that compares the input PWM signal and the position feedback of the potentiometer will generate an error which is later amplified and sent to the DC motor.

To control the motion of the SG90 Servo Motor we need to apply a PWM signal to the Yellow wire to achieve the desired position.
A 1ms pulse width will correspond to 0°
A 1.5ms pulse width will correspond to 90°
A 2ms pulse width will correspond to 180°

How To Control The Position Of The SG90 Servo Motor With Arduino

We will use the library SERVO that comes by default with the Arduino IDE software to help us write the code easily, We will only write one instruction in the void loop section to send the servo motor arm to the desired position.

To control the position of a servo motor you will only need to include the servo library
#include <servo.h>
Create servo object
Servo jawharino;
In void setup attaches the servo motor to a PWM pin
jawharino.attach(9);
And in void loop write
jawharino.write(90);// here we will send the servo arm to the 90° position

You can go through the example sketches that come with the library, go to File > Examples > Servo > Sweep
upload the sketch to the Arduino and you will see that the servo motor arm moves left and right from 0° to 180°.

The Maximum Weight That Can Be Lifted By The SG90 Servo Motor

The maximum weight that the SG90 Servo Motor can lift with 5V applied is 700 grams while the weight is placed 1cm away from the rotating center.

How To Control The Position Of The SG90 Servo Motor With Potentiometer

Connect one end of the potentiometer pin to GND and the other end to the Arduino 5V pin
Connect the middle pin of the potentiometer to whatever analog pin you would like (a 10k potentiometer is used here).

Go to File > Examples > Servo > Knob and upload the sketch. Now when you change the potentiometer position the servo motor arm will accordingly change its position.

This is all! I hope you learned something, you can also watch the tutorial video of this article down below.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top