100% found this document useful (1 vote)
137 views12 pages

1-Servo Motor Control Using Arduino

The document discusses using Arduino microcontrollers to control servo motors. Servo motors can precisely position their shaft at specific angles using PWM control signals from Arduino. Arduino provides this signal to tell the servo what angle to turn to. Servo motors have three wires: power, ground, and a control signal wire. The control signal is a PWM pulse whose width corresponds to the desired shaft angle. Copying the servo library allows Arduino boards to control servo motors and position their shafts between 0 and 180 degrees.

Uploaded by

sebas.lopez1202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (1 vote)
137 views12 pages

1-Servo Motor Control Using Arduino

The document discusses using Arduino microcontrollers to control servo motors. Servo motors can precisely position their shaft at specific angles using PWM control signals from Arduino. Arduino provides this signal to tell the servo what angle to turn to. Servo motors have three wires: power, ground, and a control signal wire. The control signal is a PWM pulse whose width corresponds to the desired shaft angle. Copying the servo library allows Arduino boards to control servo motors and position their shafts between 0 and 180 degrees.

Uploaded by

sebas.lopez1202
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 12

Servo control using Arduino Microcontroller:

Harsh Panchal

EMNG 2021: Automation Software Development


Introduction:
Servo Motors are very useful device in Automation. There are many applications of servo
motors. Unlike dc motors, with servo motors you can position the motor shaft at a specific
position (angle) using control signal. Arduino Microcontroller provides PWM signal to control
servo motor. The motor shaft will hold at this position as long as the control signal not changed.
This feature is very useful for controlling robot arms, unmanned airplanes control surface or any
object that you want it to move at certain angle and stay at its new position.

There are many types of servo motors. Servo motors are classified according to size or torque
that it can withstand into mini, standard and giant servos. Usually mini and standard size servo
motors can be powered by Arduino directly with no need to external power supply or driver as
they don’t need more current to drive.

Usually servo motors comes with arms (metals or plastic) that is connected to the object required
to move (see figure below to the right). As per servo definition (www.arduio.cc), a Servo is[1]:

“Servos have integrated gears and a shaft that can be precisely controlled with the control PWM
signal. Standard servos allow the shaft to be positioned at various angles, usually between 0 and
180 degrees. Continuous rotation servos allow the rotation of the shaft to be set to various
speeds.”

Operation:
The servo shaft position is measured by the potentiometer, is continually compared to the
commanded position from the control (i.e., the radio control). Any difference gives rise to
an error signal in the appropriate direction, which drives the electric motor either forwards or
backwards, and moving the output shaft to the commanded position. When the servo reaches this
position, the error signal reduces and then becomes zero, at which point the servo stops moving.
Any changes in servo position that commanded, whether due to command
changes, or mechanically pushed from its set position, the error signal will re-appear and cause
the motor to restore the servo output shaft to the position needed.
Most of all servo motors are proportional servos, where this commanded position can be
anywhere within the range of movement. Early servos, and a precursor device called an
escapement, could only move to a limited number of set positions.

EMNG 2021: Automation Software Development


Working principle of Servo Motor.

Your servo have 3 wires:


Black or Brown wire: GND (ground)
RED wire: +5v
Orange (or Yellow) colored wire: Control signal

Figure 1: Servo wiring layout.

The above Figure 1 shows the pin diagram for servo motor SG90. The orange or yellow wire
accept the control signal which is a pulse-width modulation (PWM) signal produced by Arduino
board. Servo accepts the signal from Arduino Microcontroller which tells it what angle to turn to.
The control signal is fairly simple compared to that of a stepper motor. It is just a pulse of
varying lengths. The length of the pulse corresponds to the angle of the motor turns to.

The pulse width sent to servo ranges as follows following:

Minimum: 1 millisecond ---> Corresponds to 0 rotation angle.


Maximum: 2 millisecond ---> Corresponds to 180 rotation angle.
Any length of pulse in between will rotate the servo shaft to its corresponding
Angle. For example, 1.5 ms pulse corresponds to rotation angle of 90 degree.
Below Figure 2 explain about control of servo with PWM signal.

Figure 2: PWM signal to control servo

EMNG 2021: Automation Software Development


Procedure:
Exercise 1: Control servo using Arduino Mega.
1. Open Arduino Sketch in your computer. If you don’t find software, visit www.arduino.cc
website to download Arduino sketch program. Download software for windows version.
2. Connect the Arduino mega as shown in the below Figure 3.

Figure 3: Connection of servo motor with Arduino controller.

3. Connect the red wire to the power (+5V) and black wire to the ground on the Arduino
Microcontroller on power pins. The control signal is provided through the Arduino Mega
from pin number 9. Check your program and verify your pin number with actual pin
connected on the Arduino.
4. Now connect your Arduino mega through USB wire which is provided with your
Arduino controller.
5. Now open Arduino Sketch program and prepare program which was discussed in class.
6. Download your Arduino sketch program in the Arduino Mega using upload button and
then wait until it finish uploading.
7. Servo motor will make rotation according to angle set in sketch program.
8. Show your sketch program and show your working setup to professor.

EMNG 2021: Automation Software Development


Exercise 2: Control servo using Potentiometer.

1. Connect servo motor according to the wiring diagram given in Figure-4. The signal pin
is typically yellow or orange and should be connected to pin 9 on the Arduino board.
2. The potentiometer should be wired so that its two outer pins are connected to power
(+5V) and ground, and its middle pin is connected to analog input 0 on the Arduino
mega.

EMNG 2021: Automation Software Development


Figure 4: Circuit diagram to connect servo with Arduino controller

3. Now open Arduino sketch program to write program to control servo motor using
potentiometer (10k).
4. Prepare program according to discussed in class. Debug your program to check for error
if any.
5. Upload your program to Arduino Microcontroller using upload button.
6. To check the function of servo, change potentiometer positon to test speed.
7. Show your result to professor for grading purpose.

Use Exercise-2 code to upload to Microcontroller as an example.

EMNG 2021: Automation Software Development


Servo motors have three wires: power, ground, and signal. The servo power wire is typically red,
and should be connected to the 5V pin on the Arduino board. The ground wire is typically black
or brown and should be connected to a ground pin on the Arduino board. The signal pin is
typically yellow, orange or white and should be connected to pin 9 on the Arduino board.

To work with Servo, you need to copy servo library to library folder of Arduino (C:\Program
Files (x86)\Arduino\libraries). This library allows an Arduino board to control RC servo motors.
Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow
the shaft to be positioned at various angles, usually between 0 and 180 degrees. Continuous
rotation servos allow the rotation of the shaft to be set to various speeds.

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino
Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM)
functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to
12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will
disable PWM on pins 11 and 12.

Inside the Servo Motor


Did ever wonder how the servo motors looks from inside? Have a look at the corresponding
picture. A servo motor was taken apart to show the internal parts.
You can see a regular dc motor connected to a gear box and a potentiometer that give the
feedback for angle position. This is represented by the diagram below.

EMNG 2021: Automation Software Development


EMNG 2021: Automation Software Development
What is an RC Servo?
RC servos are very popular model. You can find this servos in a train model, or a car, or a boat,
plane or helicopter, there must be at least one servo hidden somewhere within the constructions.

RC Servos are used to convert electrical signal into polar or linear movement. A simple example
is the steering system of an RC car. When signal is transmitted from the control to the car, this
signal is decoded and sent to a servo. According to this signal, the servo will rotate its drive shaft
for some degrees, and this rotation is translated into wheel steering.

Servos are very handy due to the one reason. The reason is that, it is very easy to drive them
with a simple PWM circuit. They can achieve from low to higher torques, enough to move
almost everything needed in an RC model, they are very compact and reliable, and most of all,
they come with very low prices according to their specifications.

EMNG 2021: Automation Software Development


Servos Parts:
The controller circuit: The control circuit is the "brain" of the Servo. It is responsible to read
the user's input signal (pulses) and translate it into a motor revolution in such a way, that the
drive shaft will be rotated to the desired position.
 The feedback potentiometer: The shaft of the potentiometer is attached to the drive
shaft of the servo. When the drive shaft rotates, which rotates the potentiometer also. In
that way, each and every rotation angle of the drive shaft, corresponds to a different
resistance of the potentiometer. By reading the potentiometers' resistance, the controller
is able to know the exact angle of the drive shaft of the servo.
 The motor: The servos are small power motors. This is usually a small high speed DC
motor controlled by H-bridge circuit attached to the servos' controller.
 The gearbox: The gearbox will drive the motor's revolution to the drive shaft. Also, the
rpm will be significantly reduced and the torque will be increased. The torque is one of
the main characteristics of RC servos.
 The drive shaft: When all of the above operate in perfect harmony, the drive shaft will
be rotated with accuracy to the user's requested angle.

Types of RC Servos

There are many manufacturer for RC servos. The cost will depends on the following important
points.

 Precision: How accurately will the servo translate the input signal into drive shaft
position
 Speed: how fast can this translation be made
 Strength: What torque can achieve during rotation
 Break strength: With how much load can be the servos' drive shaft be loaded without
losing its position
 Motion type: How does the drive shaft moves. it could be circular (like motors) or linear
(like pistons)
 Size and Weight: An important consideration when used in small planes or helicopters.
Typically, smaller servos have lower torque.
 Bearing type: Standard servos have bushings supporting the main shaft, heavy duty
servos typically have one or two ball bearings supporting the main shaft.
 Gearbox type: Most of servo uses nylon gears in the gearbox. For heavy duty servos,
there are also metallic gears. Carbonite gears are rather new to the market and offers
higher strength than nylon gears (5 times stronger or more) and very high durability, but
they are still expensive. The titanium gears are most durable. They are much lighter than
the metallic gears and in some cases they are more durable than them. Thus, they can
achieve higher torques and speeds.
 Motor type: The standard motor is a three pole ferrite motor. For some high speed
servos, five poles core-less motors are used. For heavy duty servos, heavy duty core-less
motors are used.

EMNG 2021: Automation Software Development


According to your application, you should carefully choose the most appropriate servo. For
example, an expensive and heavy metal-geared high torque servo could be inappropriate for
controlling a helicopter's fin, but it could be a one-way solution for the steering system of a
racing car, that the torque loads are very high and a lot of vibrations are sent from the wheels to
the servo.
For the example (in the Arduino IDE), connect the wires to Ground, VCC and PIN9 of the
Arduino

Resolution of the circuit:

When the input voltage is applied to the analog pin, the analog signal appear at the analog pin
specified in the program. The Arduino board contains a 6 channel (8 channels on the Mini and
Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input
voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution
between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and
resolution can be changed using analogReference().

Exercise: 1

#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9
}

void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}

EMNG 2021: Automation Software Development


Exercise: 2
Analog control to control servo motor:
Code
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer


int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value
between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value
between 0 and 180)
myservo.write(val); // sets the servo position according to the
scaled value
delay(15); // waits for the servo to get there
}

References:
1. www.arduino.cc
2. http://en.wikipedia.org/wiki/Servo_(radio_control)
3. http://www.cs.uregina.ca/Links/class-info/207/Lab6/pot_accel.html
4. http://people.interaction-ivrea.it/m.rinott

EMNG 2021: Automation Software Development

You might also like