You are on page 1of 2

Computer Control of a Stepper Motor

There are several methods of controlling a stepper motor from a computer. The simplest method is to use a direct connection to the parallel port, as shown in the schematic to the right. Each of the four lines from the parallel port (pins 2, 3, 4 and 5) are used to switch an NPN power transistor that controls a coil in the motor. The transistors are protected from excessive current flow by the 1k resistors, and they are protected from the coils' backlash current by the shorting diodes. All the parts needed to build this simple circuit are available at Radio Shack, but be aware that Radio Shack's prices for components are literally quadruple that of other electronics stores. Part Type Qty. R.S. # NPN pwr. transistor 10W 4 4 x 276-2017 Diode 1A 4 2 x 276-1102 Resistor 1k 4 271-1321 Male connector DB-25 1 276-1547

The following BASIC program demonstrates how to drive the motor from the computer. It will run a stepper motor at any speed in either direction.
10 REM Stepper Motor Controller 20 PORT = &H3BC 30 STATE = STATE + DIRECTION

40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190

IF STATE > 4 THEN STATE = 1 IF STATE < 1 THEN STATE = 4 PRINT STATE, IF STATE = 1 THEN OUT PORT, 3: REM 1100 IF STATE = 2 THEN OUT PORT, 6: REM 0110 IF STATE = 3 THEN OUT PORT, 12: REM 0011 IF STATE = 4 THEN OUT PORT, 9: REM 1001 FOR W = 1 TO DELAY: NEXT W X$ = INKEY$ IF X$ = "<" THEN DIRECTION = -1: REM Backwards IF X$ = ">" THEN DIRECTION = 1: REM Forwards IF X$ = "?" THEN DIRECTION = 0: REM Stop-locked IF X$ = "-" THEN DELAY = DELAY + 100: REM Slow down IF X$ = "+" THEN DELAY = DELAY - 100: REM Speed up IF X$ <> CHR$(27) THEN GOTO 30 OUT PORT, 0: REM 0000 (Stop-free)

Up to three stepper motors may be attached to one parallel port in this manner. The second motor would be connected to the other half of the data register (pins 6, 7, 8 and 9). The third motor would use the parallel port's control register (pins 1, 14, 16 and 17).

You might also like