Hila Research Centre

Computer Engineering Program

Robotics - Servo Motors

Servo motors make excellent motors for constructing experimental robots. Hobby servo motors are used in radio controlled cars, boats and aircraft. This information assumes you have some skills with both electronics and computer programming in Qbasic. Servo motors are available from any hobby shop specializing in RC cars, boats or plane.

Controlling a servo motor with a PC

Three coloured wires connect to each servo motor. The red wire connects to the + (plus) terminal of a 5 volt battery, the black wire connects to the - (minus) terminal of the battery and the ground of the computer (pins 20 to 25 of parallel port). The third wire (often white or yellow) connects to one of the parallel port data lines (pins 2 to 9).

The position of the servo arm is determined by a control pulse from the data line. The pulses occur every 1/100 of a second and vary in width from 1/1000 sec to 2/1000 sec. The width of the pulse determines the position of the servo arm.

In this example the black wire is connected to pin 25 and the control line is connected to pin 5 of the parallel port.

Caution, it is possible to damage your computer if you make a connection error.

To send pulses out on pin 5 of the parallel port turn it off and on using the command OUT 888,8 & OUT 888,0

The width of the pulse is controlled with a"FOR-NEXT" loop (see sample code).

The width of the pulse must be precise, unfortunately computers are regularly "interrupting" the running of programs to do some housekeeping, these interrupts cause the pulse width to vary. To evade interrupts use this code in your program: DO: LOOP UNTIL INP(&H40) > 254 This code also controls the time between each pulse.

Here is a simple Qbasic program that will allow you to test your servo driver.

This code works with the hook up diagram above. You will be prompted for a "Pulse #", this number will determine the width of the control pulse which controls the postion of the servo arm. This number will depend on the speed of the computer - you will have to experiment. If you have a very fast computer the pulse # will be high (>1000), for a slower computer it may vary from 100 to 1000.

To avoid problems with Windows, close it and open Qbasic from DOS. Do not start DOS from Windows.


Important, read this:

This information is designed to support science and technology workshops given by the Hila Research Centre at Hila Science Camp, Turnbull School and schools of the Renfrew County RCSSB. While reasonable care has been taken with respect to the accuracy of the information contained here, we assume no responsibility for errors, omissions or liability for any damage resulting from use of this information.

Back to Projects Menu