Jim's Weird Wired World
Home My Electronics Projects My Programming Projects Lyrics Page Misc.
Electronics/Stepper Motor Controller

Stepper Motor Controller

This is a simple project to allow a stepper motor to be controlled from an IBM-compatible PC's parallel port. The parallel port is an excellent interfacing mechanism, allowing all sorts of devices to be connected to and controlled by a PC. Please note, however, that it can be easily damaged, so exercise caution while using the parallel port to perform any sort of I/O operations. Do not hold me responsible for frying the insides of your computer due to your mistakes! If you're not sure of what you're doing, get help before proceeding.


The parallel port has several I/O lines, which can be partitioned into two, the data lines and the control lines. The data lines are unidirectional (OK, OK, stop howling, I know about ECP/EPP, I'm trying to keep it simple here!) and data flows out from the PC. These are used in the circuit.
Parallel Port
The IBM PC Parallel Port
Pin 1 can be identified by looking at the connector plastic. Good quality connectors have Pin 1 marked in some way. Usually, all pins are labelled. The pin assignments are as follows:
Pin No.Pin NameDirectionDescription
1StrobeINOUTPulled low by PC for each transfer done
2-9D0-D7OUTThe eight Data bits.
10AckINPulled low by the device after getting byte
11BusyINDevice indicates it is busy by pulling high
12Paper OutINFor printers
13SelectINDevice indicates it is ready by pulling high
15ErrorINIndicates an error
18-25GroundGNDSome pins are power ground, some signal and some chassis.
Pin Assignments
The stepper motor is obtained from an old 5.25" disk drive, model no FD-55GFR from Teac. This was bought for Rs. 200 from a local market (Thanks, Uday!) I extracted a small stepper motor, with a five-pin input, which had me stumped for a while. Most textbooks talk about bifilar-wound stepper motors, which have 6-pin input. Some also describe 4-pin steppers, which omit the center tap (and require bipolar drive circuitry). Lots of searching on the net gave me the answer: the motor is similar to 6-pin steppers, but have the center-tap of the two windings connected together. Hence, it's not possible to drive these using bipolar methods, reducing the mechanical power output. For more details on stepper motors, try visiting HowStuffWorks.com and searching for stepper motors.
Extracting the motor from the drive is easy, only a few screws need to be removed. The shaft has a thin metal tape screwed on to it, be careful not to cut your hands while removing it. First, verify that the motor works. The easiest way to do this is to short together all the wires coming out, and turn the shaft. You should feel a strong resistance. You may also use a multimeter to check the windings for continuity. The common pin is marked with a stripe. The stepper motor pins can be then be identified by the following process:
  1. Connect a 12V supply to the common pin (marked by a stripe on the wire) and the next pin you see. The motor should turn by a small amount. Label this Pin 1.
  2. Leaving these two wires in place, connect the other pins successively to the 12V supply. Note that two of the pins make the motor turn by small amounts, in opposite directions. Label one of them Pin 2, the other as Pin 4.
  3. The last remaining pin should cause no movement. Label this Pin 3.
The driver makes use of the ULN2003 driver IC, which contains an array of 7 power-darlingtons, each capable of driving 500mA of current. The device has base resistors, allowing direct connection to any common logic family. All the emitters are tied together and brought out to a seperate terminal. Output protection diodes are included, hence the device can drive inductive loads with minimum extra components. Only four of these darlingtons are actually used here.
Stepper Motor Driver
Stepper Motor Driver
Please note that the first pin (identified in the procedure shown above) is connected to D0 of the parallel port (through the ULN2003, of course). Each successive pin of the stepper motor is connected to successive data lines on the parallel port. If this order is not correct, the motor will not rotate, but will wiggle around from side to side. The clamp circuit shown does not connect the clamp directly to the supply voltage. Instead, it uses a zener diode. This ensures that the decaying current in the coils are not abruptly cut off, which produces a lot of heat. The software written for this project is simple, it involves setting the bits on the port on and off in a specific sequence. The sequence is given below:
Step No.D0D1D2D3
Full Step
Step No.D0D1D2D3
Half Step
The difference between half step and full step is that for the same step rate, half-step gives you half the speed, twice the resolution, and roughly twice the power consumption. It also gives you twice the torque. To reverse the direction of the motor, send the sequence in reverse order. A short example program for TurboC, running in MSDOS, drives the motor in full-step, forward direction.

#include <conio.h>

void main () {
 unsigned char v = 0x11;

 while (!kbhit ()) {
   delay (10);
   outportb (0x378, v);
   asm {
    mov al, v
    rol al, 1
    mov v, al
A more complete program is this one, written in MFC, with a nice GUI you can play with. It can drive half step, full step, forward and reverse, with a single-step and auto-step capability. You can also turn on and off individual windings.
Improvements: Not much. I wanted to try to figure out ways to control the motor, that's why I did this. My ultimate goal is to use a microcontroller to do this work. Stay tuned...