Escolar Documentos
Profissional Documentos
Cultura Documentos
September 2013
Undergraduate Program
Instructors: Waqar Shahid, Matthew N. Dailey
Introduction
In this tutorial, you will learn about servo-motor control using the Arduino.
Servos work well with remote control models of cars, airplanes, and boats, and they are also popular
in building robotic systems, for example, arms, legs, and scanners, etc. The components of servo motors
are packaged in a very compact, low-cost unit. They come in two types: position controlled servos and
continuous rotation servos.
A position controlled servo contains a D.C small motor, a gear box for speed reduction, a sensor (normally
a potentiometer) to measure the position of the output gear, and an electronic circuit that controls the
motor to make the output gear to control, precisely, the speed, mechanical position, and angular movement
of the rotor. The servo system is an automatic system that uses error-sensing negative feedback to correct
performance.
Continuous rotation servos are common in hobby electronics. They present the same interface to the
micro-controller or remote control receiver as a regular (position controlled) servo but control the motors
rotational velocity rather than its absolute position.
All servo-motor units have three wires: power, ground, and the control signal wire. Most position
controlled servos rotate from 0 to 180 degrees, but some may rotate 0360 degrees, and others have no limit.
The circuit helps to decode the output gear position/velocity, amplify the error between the current and
requested position/velocity, and drive the motor to rotate to the precisely.
using pulse width modulation (PWM). Figure 3 shows the servo-motor mechanism block diagram. Figure 4
shows a sample of the PWM output required for the control signal.
The minimum pulse, the maximum pulse, and the repetition rate are important parameters for a servo
motor. When a typical pulse is applied, the servo will move to the position and hold that position or move
at the desired velocity. If an external force is applied in opposite direction to the servo rotor while the servo
is rotating or holding a position, the servo will resist that force. The maximum amount of force the servo
can exert or resist is the torque rating of the servo. It is recommended that pulse be repeated to instruct
the servo to stay in position.
For most servo motors, the minimum pulse is 1ms, the maximum pulse is 2ms, and the repetition
frequency is 50 Hz. A 1ms pulse sent at at a rate of 50 cycle per second will keep the servo at zero degree
or at a velocity of 0, while a 2ms pulse at 50 Hz will make it rotate to 180 degrees and hold the position or
make it rotate clockwise at the maximum velocity.
Another parameter that varies from position servo to position servo is the turn rate. This is the time
taken by the servo to change from one position to another. The worst case turning time is when the servo
is holding at the minimum rotation and it is commanded to go to maximum rotation.
an object of type Servo using the type Servo followed by the object name. You can invoke the following
methods on the Servo object to perform your task:
attach(): attach a pin to a servo.
write(): rotate a servo by giving a desired angle value (writing).
writeMicroseconds(): control servos by pulse-widths in microseconds.
read(): read the current value (angle in degrees) of servos
attached(): check if a pin is attached to a servo.
detach(): detach a pin to a servo
With the library you can control the motor both using the desired angle in degree or by controlling the
PWM pulse length. The functions are write() and writeMicroseconds() respectively.
commands writeMicroseconds
myServo.writeMicroseconds(800)
myServo.writeMicroseconds(1500
myServo.writeMicroseconds(2200)
Action
Servo will rotate CCW with full speed.
Servo will stop.
Servo will rotate CW with full speed.
Hardware required
Arduino board
RC (hobby) servo motor
Potentiometer 10K
Bread board
Connection wires
LED (01), button, resistor 50 , resistor 10K
Experiment-1
The servo will rotate in CCW direction at full speed for 1 second, then it stops for 1 second. It changes
direction to CW and rotate at full speed for 1 second, then stops for 1 second and so on.
Implement the circuit as shown in the diagram of Figures 5, 6.
Right the following program and observe the output.
If your servo is moving at 1.5ms that means it requires manual calibration.
ajust the potentiometer so that your motor does not move at 1.5ms.
#include <Servo.h>
// Create a Servo object to control each servo.
// A maximum of 8 Servo objects can be created.
Servo myServo;
void setup()
{
// Attach the Servo object's control signal to pin 9
myServo.attach(9);
}
void loop()
{
// 0 degrees or maximum counterclockwise velocity
myServo.writeMicroseconds(800);
delay(1000);
// 90 degrees or 0 velocity
myServo.writeMicroseconds(1500);
delay(1000);
// 180 degrees or maximum clockwise velocity
myServo.writeMicroseconds(2200);
delay(1000);
// 90 degrees or 0 velocity
myServo.writeMicroseconds(1500);
delay(1000);
}
Experiment-2
The servo will rotate in CCW with increasing speed. When the speed gets full value, it gradually reduces
till zero. At this point, the direction is changed to CW. The servo then increases speed to full then reduces
to zero and the direction is changed to CCW.
Implement the circuit as shown in the diagram of Figures 5, 6.
Write the code mentioned below for experiment-2.
Observe the output as mentioned above.
Assignment
Problem statement: Assuming the grip provided along with the servo is attached to the line-following
ground robot. Write a program that your grip hold an object lying in front of the robot, picks it up, turn the
object, turn the object back , release the object
Code-Experiment-2
Code-1: Arduino Example program for Servo
#include <Servo.h>
//create servo object to control a servo
//a maximum of eight servo objects can be created
Servo myServo;
int pos = 0;
void setup()
{
myServo.attach(9);
}//attach control signal to pin 9
void loop()
{
//servo goes from not moving (90) to full speed in CCW direction (0)
//decreasing the value by 1 each loop
for(pos = 90; pos > 1; pos -= 1)
{
myServo.write(pos);//tell servo to go to position in variable 'pos'
delay(25);
}//waits 25 ms for the servo
//servo goes from moving full speed in CCW direction (0) to not moving (90)
//increasing the value by 1 each loop
for(pos = 0; pos < 90; pos += 1)
{
myServo.write(pos);// tell servo to go to position in variable 'pos'
delay(25);
}// waits 25 ms for the servo
//change direction to CW
//servo goes from not moving (90) to full speed in CW direction (180)
//decreasing the value by 1 each loop
for(pos = 90; pos < 180; pos += 1)
{
myServo.write(pos);//tell servo to go to position in variable 'pos'
delay(25);
}// waits 25 ms for the servo
//servo goes from moving full speed in CW (180) to not moving (90)
//increasing the value by 1 each loop
for(pos = 180; pos > 90; pos -= 1)
{
myServo.write(pos);//tell servo to go to position in variable 'pos'
delay(25);
}
}// waits 25 ms for the servo
Acknowledgement
Images are taken from Mr. H.H. Manh Handouts for Servo Motors. Thanks to Lab Supervisor Mr.H.H.Manh
from Mechatronics AIT for sharing his handout
References
1. http://en.wikipedia.org/wiki/Proximity_sensor.
2. http://profesores.fi-b.unam.mx/m3615m/datasheet-sen136b5b.pdf.
3. http://www.seeedstudio.com/wiki/Ultra_Sonic_range_measurement_module.
4. http://arduino.cc.
5. Arduino Programming Notebook by - by Brian W. Evans.
6. Beginning Android ADK with Arduino by Mario Bohmer
7. http://arduino.cc/en/uploads/Main/arduino_Uno_Rev3-02-TH.zip.
8. http://arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf.
9. http://arduino.cc/en/Main/ArduinoBoardUno.
10. Computational Principles of Mobile Robotics by from Dudek and Jenkin.