W. Durfee, Last update:
The software in this tech note is for the Basic STAMP microcontroller. The
concepts and circuit diagram hold for the Arduino microcontroller. After reading
through this note, consult these additional resources for the Arduino
Arduino servo motor software library:
Example showing how to sweep the motor shaft back and forth:
Example of using a potentiometer to control the motor shaft position:
A servo is a special type of gear motor whose angular position is controlled by supplying its control line with a 5V pulse between 1.0 and 2.0 ms wide, updated about 50 times each second. The output position range is typically 90 degrees. Servos are used in RC model aircraft and cars to change steering and control surfaces.
Because the servo needs a continuous stream of pulses to hold its position, the Stamp is limited in what it can do while controlling a servo, although it is not difficult to control several servos simultaneously while monitoring inputs or performing other activities that only take a single line of code.
The stamp PULSOUT instruction is ideal for commanding the servo. PULSOUT x,y generates a 5V pulse on Stamp pin x with a width of y*2 microseconds. If the control line to the servo is connected to Stamp pin 4, the command PULSOUT 4,500 will bring the servo to one end of its range while PULSOUT 4,1000 will bring it to the other end.
Here is a program that moves the servo to its mid position for 1 second then shuts off.
pulsout 4 750
Here is a program that moves the servo back and forth through its full range 4 times. The "low servo" line is required to ensure that the servo is at the low state before pulsing.
servo con 4
i var word
j var byte
for j = 1 to 4
for i = 500 to 1000 step 5
for i = 1000 to 500 step -5
A servo has 3 wires: power, ground and control. Most servos require a 4.8V to 6V power supply. The servo ground connects both to the power supply ground and to the Stamp ground (Vss). The 5V voltage regulator on the Stamp Homework board is limited to 50mA so the Homework Board Vdd line cannot be used to power the servo. (Other versions of Stamp boards, for example, the Board of Education, do have sufficient on-board power for servos.)
Servos do fine with a 6V power supply. An easy way to get 6V is four AA (or C or D for a longer run) batteries wired in series using a 4-battery holder (e.g. Radio Shack PN 270-413 or PN 270-389).
All servos have three wires. Black (or brown) is for ground, red is for power (4.8 V to 6 V) and white (or yellow or orange) is the signal.
Modifying a servo to act as a plain, continuous-rotation gear motor is commonly done by robot hobby people. A quick google search will bring up instructions. For example: "How to modify a servo for continuous rotation" (Acroname), and "Modifying the Hitech HS-322HD for continuous rotation." (Arconame).
New servos can range in price from $6 to $150 with most around $15. The higher priced servos produce more torque and have precision, low noise gears. As always, e-Bay is a good source for used or bargain servos. Hobby stores also carry servos.
Many of the inexpensive servos described in robot projects are made by Hitec (www.hitecrcd.com). For example, the Hitec HS300 series is common and widely available in the new and surplus market.
Servos available on robot supply web sites include the following. Most sites have servos other than the ones listed here, so explore.
Servo City, PN 31311S (Hitec HS-311), $8.99, www.servocity.com (Note: this site has wide selection and good prices)
Parallax, PN 900-00005, $12.95, www.parallax.com (good app. notes)
Hobby Enginering, 1709 or 2218 or 1978, $11.99, ww.hobbyengineering.com
Robot Marketplace, Hitec HS-322HD, $9.99, www.robotmarketplace.com
Acroname, R276-S03N-SERVO, $10.90, www.acroname.com
Robotstore, 358635 (Hitec HS-311), $16.95, www.robotstore.com
Parallax Basic Stamp 1 Application Notes, #4