What is a Servo Motor?
- Understanding the basics of Servo
Motor Working
What is a Servo Motor?
A servo motor is a type of motor that can rotate with great precision. Normally this type
of motor consists of a control circuit that provides feedback on the current position of the
motor shaft, this feedback allows the servo motors to rotate with great precision. If you
want to rotate an object at some specific angles or distance, then you use a servo motor. It
is just made up of a simple motor which runs through a servo mechanism. If motor is
powered by a DC power supply then it is called DC servo motor, and if it is AC-powered
motor then it is called AC servo motor. For this tutorial, we will be discussing only about
the DC servo motor working. Apart from these major classifications, there are many
other types of servo motors based on the type of gear arrangement and operating
characteristics. A servo motor usually comes with a gear arrangement that allows us to
get a very high torque servo motor in small and lightweight packages. Due to these
features, they are being used in many applications like toy car, RC helicopters and planes,
Robotics, etc.
What is a Servo Motor?
A servo motor is a type of motor that can rotate with great precision. Normally this type
of motor consists of a control circuit that provides feedback on the current position of the
motor shaft, this feedback allows the servo motors to rotate with great precision. If you
want to rotate an object at some specific angles or distance, then you use a servo motor. It
is just made up of a simple motor which runs through a servo mechanism. If motor is
powered by a DC power supply then it is called DC servo motor, and if it is AC-powered
motor then it is called AC servo motor. For this tutorial, we will be discussing only about
the DC servo motor working. Apart from these major classifications, there are many
other types of servo motors based on the type of gear arrangement and operating
characteristics. A servo motor usually comes with a gear arrangement that allows us to
get a very high torque servo motor in small and lightweight packages. Due to these
features, they are being used in many applications like toy car, RC helicopters and planes,
Robotics, etc.
Servo motors are rated in kg/cm (kilogram per centimeter) most hobby servo motors are
rated at 3kg/cm or 6kg/cm or 12kg/cm. This kg/cm tells you how much weight your servo
motor can lift at a particular distance. For example: A 6kg/cm Servo motor should be able
to lift 6kg if the load is suspended 1cm away from the motors shaft, the greater the
distance the lesser the weight carrying capacity. The position of a servo motor is decided
by electrical pulse and its circuitry is placed beside the motor.
Servo Motor Working Mechanism
It consists of three parts:
1. Controlled device
2. Output sensor
3. Feedback system
It is a closed-loop system where it uses a positive feedback system to control motion and
the final position of the shaft. Here the device is controlled by a feedback signal
generated by comparing output signal and reference input signal.
Here reference input signal is compared to the reference output signal and the third signal
is produced by the feedback system. And this third signal acts as an input signal to the
control the device. This signal is present as long as the feedback signal is generated or
there is a difference between the reference input signal and reference output signal. So the
main task of servomechanism is to maintain the output of a system at the desired value at
presence of noises.
Servo Motor Working Principle
A servo consists of a Motor (DC or AC), a potentiometer, gear assembly, and a
controlling circuit. First of all, we use gear assembly to reduce RPM and to increase
torque of the motor. Say at initial position of servo motor shaft, the position of the
potentiometer knob is such that there is no electrical signal generated at the output port of
the potentiometer. Now an electrical signal is given to another input terminal of the error
detector amplifier. Now the difference between these two signals, one comes from the
potentiometer and another comes from other sources, will be processed in a feedback
mechanism and output will be provided in terms of error signal. This error signal acts as
the input for motor and motor starts rotating. Now motor shaft is connected with the
potentiometer and as the motor rotates so the potentiometer and it will generate a signal.
So as the potentiometer’s angular position changes, its output feedback signal changes.
After sometime the position of potentiometer reaches at a position that the output of
potentiometer is same as external signal provided. At this condition, there will be no
output signal from the amplifier to the motor input as there is no difference between
external applied signal and the signal generated at potentiometer, and in this situation
motor stops rotating.
Interfacing Servo Motors with Microcontrollers:
Interfacing hobby Servo motors like s90 servo motor with MCU is very easy. Servos
have three wires coming out of them. Out of which two will be used for Supply
(positive and negative) and one will be used for the signal that is to be sent from
the MCU. An MG995 Metal Gear Servo Motor which is most commonly used for RC
cars humanoid bots etc. The picture of MG995 is shown below:
The color coding of your servo motor might differ hence check for your respective
datasheet.
All servo motors work directly with your +5V supply rails but we have to be careful on
the amount of current the motor would consume if you are planning to use more than two
servo motors a proper servo shield should be designed.
Controlling Servo Motor:
All motors have three wires coming out of them. Out of which two will be used for
Supply (positive and negative) and one will be used for the signal that is to be sent from
the MCU.
Servo motor is controlled by PWM (Pulse with Modulation) which is provided by the
control wires. There is a minimum pulse, a maximum pulse and a repetition rate. Servo
motor can turn 90 degree from either direction form its neutral position. The servo motor
expects to see a pulse every 20 milliseconds (ms) and the length of the pulse will
determine how far the motor turns. For example, a 1.5ms pulse will make the motor turn
to the 90° position, such as if pulse is shorter than 1.5ms shaft moves to 0° and if it is
longer than 1.5ms than it will turn the servo to 180°.
Servo motor works on PWM (Pulse width modulation) principle, means its angle of
rotation is controlled by the duration of applied pulse to its Control PIN. Basically servo
motor is made up of DC motor which is controlled by a variable resistor
(potentiometer) and some gears. High speed force of DC motor is converted into torque
by Gears. We know that WORK= FORCE X DISTANCE, in DC motor Force is less and
distance (speed) is high and in Servo, force is High and distance is less. The
potentiometer is connected to the output shaft of the Servo, to calculate the angle and stop
the DC motor on the required angle.
Servo motor can be rotated from 0 to 180 degrees, but it can go up to 210 degrees,
depending on the manufacturing. This degree of rotation can be controlled by applying
the Electrical Pulse of proper width, to its Control pin. Servo checks the pulse in every
20 milliseconds. The pulse of 1 ms (1 millisecond) width can rotate the servo to 0
degrees, 1.5ms can rotate to 90 degrees (neutral position) and 2 ms pulse can rotate it to
180 degree.
All servo motors work directly with your +5V supply rails but we have to be careful
about the amount of current the motor would consume if you are planning to use more
than two servo motors a proper servo shield should be designed.
To learn more about servo motor working principle and practical uses, please check
below applications where controlling of servo motor is explained with the examples:
Arduino Servo Motor Control
Servo motor tester circuit
Servo motor interfacing with 8051 microcontroller
Servo motor control using Arduino
Servo control with Arduino Due
Servo Control with Flex Sensor
Raspberry Pi Servo Motor Tutorial
1. How to Control Servo Motor using Arduino
In the world of electronics and robotics, servo motors play a crucial role in controlling
mechanical movements precisely. In this blog post, we'll delve into the basics of
interfacing a servo motor with an Arduino board. Whether you're a beginner or an
experienced enthusiast, this step-by-step guide will help you understand the fundamentals
of servo motor control and how to integrate it with an Arduino for your projects. After
you have learned the basics you can try other Arduino servo motor projects like
this robotic arm using servo motor.
You can also find other such Arduino tutorials and projects on our website.
The components which we will require for this project are
1. Arduino Uno
2. USB cable
3. Servo Motor SG90
4. Potentiometer 10k ohm
5. Jumper wires
What is a Servo motor?
A servo motor is a type of motor used in various applications to precisely control the
position, speed, and angular rotation of mechanical systems. It's designed to provide
accurate control of its output shaft, allowing for precise angular position control.
Servo motors typically consist of a small DC motor, a gear train, a control circuit, and a
feedback system. The feedback system, often a potentiometer or an encoder, continuously
sends information about the motor's current position back to the control circuit. This
feedback allows the control circuit to adjust the motor's movement and ensure it reaches
and maintains the desired position.
Types of Servo Motors
Servo Motors are divided into two main types
1. AC Servo Motor
2. DC Servo Motor
AC Servo motors use an AC power source, these motors use encoders for feedback. They
are known for their high-speed and high-torque capabilities, making them suitable for
industrial machinery and CNC equipment.
DC Servo motors use a DC power source and are often equipped with encoders for
feedback. They offer precise control and are commonly used in robotics and small-scale
automation.
In this tutorial, we are going to use a DC Servo Motor. If you want to learn more about
different types of DC motors in general, You can do that and come back here again.
DC Servo Motors are classified into two types
1. Standard rotation Servo which moves from 0 to 180 degrees
2. Continuous rotation Servo which moves 360 degrees
We will be using a “Tower pro-Micro Servo sg90 motor” which is a type of DC standard
rotation servo motor.
What is Tower Pro SG90 Servo Motor?
The Tower Pro SG90 is a popular and widely used micro servo motor known for its
compact size, lightweight design, and affordability. It's commonly utilized in various
hobbyist projects, robotics, remote-controlled vehicles, and small-scale applications that
require precise control of angular motion.
Specifications of Tower Pro SG90 Servo Motor
Here are the specifications of a standard SG90 Servo we should know before getting/
using a servo motor for your project:
Operating Voltage 4.8 V - 6 V
Stall Torque 1.6 kg-cm
Stall Current 650 mA
Weight 9g
Operating temperature -30 to +60 degree celsius
Operating Voltage: This servo motor operates within a voltage range of 4.8V to
6V. Ensure the power supply falls within this range to prevent damage or
inefficient operation.
Stall Torque: This indicates the maximum torque output of the motor when it's
unable to rotate further. It's the force the motor can exert at a given voltage, crucial
for applications that require the motor to overcome resistance or hold positions
against external forces.
Stall Current: Stall current refers to the amount of current drawn by a motor when
it's operating at stall or maximum load condition, and the shaft is prevented from
rotating. It signifies the maximum current which the motor can draw.
Weight: The weight of the servo motor is essential in applications where size and
weight constraints are critical, such as in drones, small robotic arms, or RC
vehicles.
Operating Temperature:Operating temperature refers to the range of temperatures
within which a device or component can safely and effectively operate without
risking damage or performance degradation
SG90 Servo Motor Pinout
GND Ground (Brown Wire) – This is the ground pin.
VCC +5V (Red Wire) – Voltage is supplied to the servo motor through this Pin.
Control (Orange Wire) – Through this wire, Position control signals are received
via PWM.
Servo Motor Working
A servo motor receives PWM (Pulse Width Modulation) signals to determine its angle of
rotation. The PWM signal is a square wave with a variable duty cycle, where the width or
duration of the high signal (the "on" time) corresponds to a specific angle. This signal is
usually generated by a microcontroller, such as an Arduino.
When the PWM signal is fed to the servo motor's control input (usually the orange or
yellow wire), the motor's control circuit interprets it as a command to move to a particular
angle. The control circuit measures the duration of the high part of the PWM signal,
which corresponds to the desired angle. This duration is typically in the range of 1 to 2
milliseconds.
The control circuit then compares this measured duration with the center position
(typically 1.5 milliseconds) and adjusts the motor's shaft to move towards the desired
angle. If the duration of the high part of the PWM signal is shorter than the center
position, the motor turns in one direction; if it's longer, the motor turns in the opposite
direction.
The servo motor continuously adjusts its position to match the incoming PWM signal. As
the duty cycle of the PWM changes, the motor's shaft rotates accordingly. This closed-
loop control mechanism ensures that the motor accurately follows the input signal,
allowing for precise and repeatable angular positioning. In essence, the servo motor's
responsiveness to PWM signals enables it to execute controlled movements in various
applications, from opening and closing doors to steering remote-controlled vehicles.
In addition to using the microcontroller itself, The Servo Motor can be controlled in
various other ways.
Servo Shield: A servo shield is used primarily to simplify and streamline the process of
controlling multiple servo motors, particularly when working with microcontroller
platforms like Arduino. Here’s how a Servo Shield looks like
Servomotor driver: The Servo drivers or Arduino Servo controller boards are
commonly used to control multiple servo motors in various projects, especially in
robotics, automation, and lighting systems.The PCA9685 is a popular 16-channel, 12-bit
PWM (Pulse Width Modulation) servo driver. We will also learn a proper
implementation of controlling multiple servo using PCA9685 later in this blog.
Servo tester: A servo tester is a simple device used to manually test, calibrate, and
control servo motors without the need for a microcontroller or complex programming. It's
a standalone tool that allows users to directly interface a servo motor with.
Commonly asked questions about Servo Motors
How does a servo motor differ from a regular DC motor?
Unlike a regular DC motor, a servo motor features a closed-loop control system with
feedback mechanisms like potentiometers or encoders. This enables precise position
control and makes it stop at a specific angle, whereas a regular DC motor doesn't
inherently have this level of precision.
Why is my servo jittering or not moving smoothly?
Jittering or erratic movement might be due to power issues, noise in the signal, or
mechanical restrictions. Ensure a stable power supply, use proper wiring, and ensure the
servo isn't mechanically constrained.
Can I modify a servo motor for continuous rotation?
Yes, some servo models can be modified for continuous rotation by disconnecting the
internal feedback mechanism and adjusting the control circuitry. This essentially turns the
servo into a geared DC motor with position control disabled.
Circuit Diagram of Interfacing Arduino with Servo Motors and
Potentiometer
The below circuit diagram shows how a arduino servo motor control can be done using
a potentiometer.
Connect the red wire (VCC) of the servo motor to the 5V pin on the Arduino.
Connect the brown or black wire (GND) of the servo motor to the GND pin on the
Arduino.
Connect the orange or yellow wire (Signal) of the servo motor to a digital PWM
pin on the Arduino.
Connect the positive end of potentiometer to 3.3V pin of Arduino
Connect the GND end to the GND pin of Arduino
Connect the signal pin to A0 pin(or any analog input pin)
Here’s a pinout of the potentiometer for reference
Servo Motor Arduino Code
The Arduino Servo Library is a software library that simplifies the control of servo
motors using Arduino boards. It provides an easy-to-use interface for managing servo
motors' movement and position without the need for intricate programming or handling
complex timing functions manually.
To include the Servo Library in your code, you add “#include <Servo.h>” to your code.
There are two important example codes which are used for testing the Servo Motor.
Arduino Servo Sweep Code
This test code rotates the servo from 0 degree to 180 degree and then rotates back from
180 to 0 degree without the need of any input from the user side.
#include <Servo.h>
This line includes the Servo library, which provides functions and features for controlling
servo motors in an Arduino sketch.
Servo myservo;
Here, a servo object named myservo is created using the Servo library. This object will
be used to control a servo motor connected to the Arduino. The comment indicates that
on most Arduino boards, you can create up to twelve servo objects.
int pos = 0;
An integer variable pos is declared and initialized to store the position of the servo motor.
Servo myservo;
Here, a servo object named myservo is created using the Servo library. This object will
be used to control a servo motor connected to the Arduino. The comment indicates that
on most Arduino boards, you can create up to twelve servo objects.
int pos = 0;
An integer variable pos is declared and initialized to store the position of the servo motor.
void setup() { myservo.attach(9);
Within the setup() function, myservo.attach(9); is used to attach the servo object myservo
to pin 9 of the Arduino. This line informs the Arduino that the servo is connected to pin 9
and that pin will be used to send control signals to the servo.
void loop() { for (pos = 0; pos <= 180; pos += 1) {
myservo.write(pos);
delay(15);
}
The loop() function contains a for loop that increments the pos variable from 0 to 180
degrees in steps of 1 degree using pos += 1. Inside the loop:
myservo.write(pos);
sends the current position value stored in the pos variable to the servo, commanding it to
move to that position.
delay(15); pauses the program execution for 15 milliseconds to allow the servo time to
reach the specified position.
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
Following the completion of the first loop, another for loop is used to decrement the pos
variable from 180 to 0 degrees in steps of 1 degree using pos -= 1. Inside this loop, the
servo is commanded to move to the position specified by the pos variable, and another
delay of 15 milliseconds is added between movements.
Here’s how the servo motor tinkercad simulation will look like.