Stepper Motors


Stepper motors enable precise positioning without needing sensors to measure motor position. Each pulse to a stepper motor turns its shaft one step which for many steppers is 3.6 degrees. Other common step sizes are 1.8 and 7.5 degrees. Thus, 100 pulses will turn a 3.6 degree stepper exactly one revolution.

The disadvantage of steppers is that they are more complex to control and can consume precious battery current even when not moving. The purpose of this tech note is to guide you through selecting and obtaining stepper motors, interfacing them to a Stamp, and controlling their motion in code.

Background reading

Before you go further in this document, read these two technotes from Parallax which give a good background to steppers.

Experiment #26: Stepper Motor Control (From the Parallax Stampworks manual)

Application Note #6: A Serial Stepper Controller (From the Parallax BASIC Stamp I Application Notes)

Finding a stepper motor

Stepper motors are available new, from surplus houses, or can be pulled from old electronic equipment such as floppy drives. Jameco has a nice selection, also Ax-Man typically has a variety. Parallax sells a stepper (PN # 27964), a little pricey, but comes with excellent application notes.

Look for "unipolar" or "4-coil" or "4-phase" motor (they all mean the same thing) with 5 or 6 or 8 wires. Avoid "bipolar" motors because they require an entirely different control scheme. However, if you find a good 4-wire bipolar stepper motor from a printer, here is a good reference source: Interfacing a bipolar stepper to the Stamp

Key specs are operating voltage (12V is convenient for robotics projects), and either coil current or coil resistance (given one spec you can get the other from V=IR). Look for motors with a coil current of 250 mA or less (coil resistance of 48 ohms or more for a 12V motor). Higher currents do give higher torque, but will also drain your battery faster. Another key spec is the holding torque which is how much torque the motor can resist when energized.

If you are pulling a motor from an old floppy drive, look for a flat motor with five or six leads.

Identifying stepper motors

If you are staring at a pile of stepper motors in a surplus shop, or have pulled one out of used equipment, here's how you can determine what you have.

First, check for the number of wires coming out. If 5 or 6 or 8, that's good because you have a unipolar stepper. If 4, that's bad because you have a bipolar stepper and should put it back. If 2, you have a regular DC motor. Confirm you have a stepper motor by turning the shaft. You should feel the little detents indicating each step.

Next, read the label on the side. If you are lucky, it will have the voltage and step size printed, or will be in a bin with the voltage marked. Look for 12V steppers. If you have a 5V stepper, and it is large, the currents will probably be too large for easy control. Small 5V steppers are OK. If you have no way of telling the voltage, it is probably best to look for another stepper.

Next, get out your digital ohmmeter and start reading resistances between the leads. You will get different values depending on which pair of leads you measure. The lowest resistance you find is the coil resistance. Use I=V/R to compute the coil current. If 250 mA or less, you are in good shape.

Look at the output shaft and determine if it is something you can handle. Common steppers have plain shafts with 0.125, 0.196 or 0.250 diameter. Gears press fit onto the shaft may be useful to you or can be removed.

Consider the size and weight of the stepper. Very large or very heavy steppers will most likely require more current than you can control. Many steppers come in standard NEMA (National Electrical Manufacturer's Assocation) sizes. NEMA size 14, 15, or 16 are typically cubic in shape with the front mounting flange 1.38 to 1.65 inches on a size, and are great for robotics. NEMA size 23 are cylindrical with a square mounting flange 2.22 inches on a side. Size 23 motors may require too much current so check the specs carefully. Another common shape are stacked cans with a diamond-shaped mounting flange. Smaller sizes are also good for robotics.

Here are some pictures of steppers.

And here is some data for common steppers

Identifying the leads of unipolar steppers

Unipolar stepper motors have four coils and either five, six or eight wires. No matter how many wires, unipolar stepper motors are interfaced in the same way. Five wires will go to the controller circuit. To identify wires, you need a resistance meter.

Here are some schematics of stepper coil configurations.

If you can find identifying marks on the stepper, you might get lucky and find the data sheet on the web, which will have the lead wire colors. Or if you are lucky, your stepper is listed in our data for common steppers section. If not, you'll need to do dectective work as described below.

First, identify the common lead. For the six and eight wire versions, some wires are twisted together to form the common lead and reduce the lead count to five. The common lead is connected to the positive of your battery or power supply.

Now, proceed to identify individual coils in order of sequence.

Interfacing to the BASIC Stamp

The simplest way of interfacing a unipolar stepper to the Stamp is to connect the common to the positive of the battery or power supply and have the Stamp drive coils 1-4 to ground in the proper sequence. The simplest way to do this is using a ULN2003A integrated circuit chip. The ULN2003A contains seven darlington transistor drivers and is somewhat like having seven TIP120 transistors all in one package. The ULN2003A can pass up to 500 mA per channel and has an internal voltage drop of about 1V when on. It also contains internal clamp diodes to dissipate voltage spikes when driving inductive loads. The ULN2003A is available from Jameco and from the ME2011 robot store. Here is a data sheet.

For higher current torque motors, or if you don't have a ULN2003A, you can control the coils with four TIP120 darlington transistors. The advantage is that the TIP120's can pass more current (especially if you add a heat sink). The disadvantages are that more wiring is required, the TIP120 has a larger voltage drop leaving less for the motor, and the four TIP120's take up more room.

Here are some schematics showing how to interface a unipolar stepper motor to four Stamp pins using a ULN2003A, and showing how to interface using four TIP120's.

Stamp software

The software is responsible for pulsing the coils in the proper sequence. There are two ways of driving the coil. The first is by turning on one coil at a time. This gives a smooth rotation, but has low torque. The second is by turning on two coils at a time. This results in high torque, but consumes twice the battery power. For either case, keep in mind that the motor will consume power even when still unless you explicitly turn off all four coils via the Stamp.

At the end of this technote is some demo code that will drive a stepper. The core are the two subroutines, one that turns the motor forward, the other that turns the motor in reverse. You set the speed and number of steps variables, then call the subroutine. As shown, the software executes high torque, high current stepping. To implement low torque, low current stepping, switch the LOOKUP command lines that are commented in the subroutine. The sample code assumes that the stepper is being controlled by Stamp pins 4, 5, 6, and 7.

If you don't understand any of the Stamp commands, look them up in the BASIC Stamp User's Manual

Cut and paste the demo code into your stamp program, or download the text version.

' stepper motor demo
   ' coils 1,2,3,4 in pins 4,5,6,7
'----required variables
   coils var outb 'stepper in pins 4-7
   sval var byte 'keeps track of sequence
   js var word 'subr index
   speed var word 'speed of rotation
   nsteps var word 'number of steps to take
'----variables for demo code
   i var byte
   '----code starts here
   pause 1000 'prevents startup jump
dirb = %1111 'set stepper pins to outputs
'----demo 1: two turns forward, two back
   speed = 5
   nsteps = 200
   gosub step_for
   pause 500
   gosub step_rev
   pause 500
'----demo 2: wave
   nsteps = 25
   for i = 1 to 5
   gosub step_for
   gosub step_rev
   pause 500
'----demo3: varible speed wave
   for i = 1 to 10
   speed = 11 - i
   gosub step_for
   gosub step_rev
'----turn coils off to save battery
   coils = 0
'----end required to avoid subroutines
'----forward rotate nsteps steps
   ' for lower torque, lower current, switch
   ' comment lines on lookup statements
   for js = 1 to nsteps
   sval = sval + 1 //4
   'lookup sval, [%0001,%0010,%0100,%1000],coils
   lookup sval, [%0011,%0110,%1100,%1001],coils 'read (step1+stepval),coils
   pause speed
'----reverse rotate nsteps steps
   for js = 1 to nsteps
   sval = sval + 3 //4
   'lookup sval, [%0001,%0010,%0100,%1000],coils
   lookup sval, [%0011,%0110,%1100,%1001],coils 'read (step1+stepval),coils
   pause speed


Additional stepper motor links

(please notify author if a link is broken or if you have a link to add)