# Identifying and using a stepper motor on Arduino

If you buy a new steppermotor for a project there is usually some documentation telling you how to connect it.
However, we do not always buy steppermotors with documentation: sometimes you have an old one, sometimes you pull it out of an old unused device or get it from a surplus store.

I found a steppermotor that I had probably bought 30-35 years ago and never used (over ambitious). It did not offer much info other than: 55SI-25D AWC 7.5 DEG 36 Ohm and that it was from Oct 83 and came from Japan. It had six wires, but other than some handwritten labels mentioning colors and numbers (that were even corrected), it offered no clue on what connection was what. Initially, also the internet offered no help other than some questions about that type of motor (Although I recently found some info [now gone]).

So, how to identify what was what? Well first the number of  connections –6-   (brown, yellow, blue, red, white and white) suggested it was a unipolar steppermotor and I suspected the two white ones to be the common connection. To establish how the rest of the wires where connected it was time for the multimeter and I set up a small table in which I could enter the resistance values I measured:

 white 1 white 2 red blue yellow brown white 1 x ∞ 36Ω ∞ ∞ 36Ω white 2 ∞ x ∞ 36Ω 36Ω ∞ red 36Ω ∞ x ∞ 72Ω blue ∞ 36Ω ∞ x 72Ω ∞ yellow ∞ 36Ω ∞ 72Ω x ∞ brown 36Ω ∞ 72Ω ∞ ∞ x

For those having trouble reading the symbols: ∞ means that there was an infinite resistance (i.e. not connected) and x means that there is no need to measure it as it is the same wire.

If you don’t have a multimeter, it becomes a bit harder but then you can also find which coils belong together: if you short a coil the resistance in manually turning the axis increases

Obviously this was a motor with 4 coils, that each have a white common connector and the table tells us that red and brown are the coils connected to ‘white 1’ and that yellow and blue are the pair with ‘white 2’ as a common connector.

However, with a unipolar stepper the coils need to be driven in a certain sequence, otherwise the motor won’t turn at all, or will have only little power and though from the table we now know what coils belong to a pair, we still do not know what the sequence of the coils is.

In other words take for instance the red and the brown pair. Is red coil 1 and brown coil 2 or is it the other way around?  Well, that is a bit tricky because even the numbering of the coils is not always standard.

There is a way of measuring which coil is which, by applying voltage to one coil and then adding voltage to another coil, while feeling if the shaft turns at all and what way. But that is actually just as much work as connecting it to an arduino and switching a few pairs of wires to test. Once you have established –as we did in the table above-  what pairs are connected. It is really not that much work anymore.

So for now let’s forget about coil numbers and look a bit more at the functions and how to drive the coils.
So, for the time being we will just call them coil 1a,1b, 2a and 2b. we don’t know which one is a and b but we do know that it is the red-brown pair vs the blue yellow pair.

As none of the coils belonging to the same pair should be energized at the same time, the sequence must be either:
red yellow brown blue
or
red blue brown yellow.
As it turns out, it is red-yellow-brown blue to turn the motor clockwise and yellow-red-blue-brown to turn the motor counter clockwise

There are in fact 4 ways of  driving a steppermotor:

• Wave driving (sometimes also called (“one-phase on, full step” ) is the simplest as only one coil is on at any one time. This uses least current but also produces the least amount of torque. The coil activation sequence would be: 1a-2a-2b-1b-1a etc
• Half stepping is done by alternating between activating a single coil and two coils at the same time. Due to the smaller step angle, this mode provides twice the resolution and smoother operation. Half stepping produces roughly 15% less torque than dual phase full stepping. Modified half stepping eliminates this torque decrease by increasing the current applied to the motor when a single phase is energized. The torque fluctuates between utilising a single coil and both coils. the coil activation sequence would be:
1a-1a2a-2a-2a1b-1b-1b2b-2b-2b1a,
• Full stepping (sometimes also called  “two-phase on, full step”) is when two coils are always energised at the same time. This gives the motor maximum torque but will require more current more current. This looks like: 1a2a-2a1b-1b2b-2b1a.
• Microstepping is a technique that increases motor resolution by controlling both the direction and amplitude of current flow in each winding. Current is proportioned in the windings according to sine and cosine functions. Microstepping is at the expense of drastic loss in torque. On the Arduino microstepping can be achieved  with PWM. However, unless you really need it, I wouldnt bother

To drive the motor continuously, we just apply power to the two windings in sequence. Assuming positive logic, where a 1 means turning on the current through a coil, the following two control sequences will each spin the motor clockwise 24 steps:

```  Winding 1a 1000100010001000100010001
Winding 1b 0010001000100010001000100
Winding 2a 0100010001000100010001000
Winding 2b 0001000100010001000100010
time --->

Winding 1a 1100110011001100110011001
Winding 1b 0011001100110011001100110
Winding 2a 0110011001100110011001100
Winding 2b 1001100110011001100110011
time --->```

Note that the two halves of each winding are never energized at the same time. Both sequences shown above will rotate a permanent magnet one step at a time. The top sequence only powers one winding at a time, as illustrated in the figure above; thus, it uses less power. The bottom sequence involves powering two windings at a time and generally produces a torque about 1.4 times greater than the top sequence while using twice as much power.

Anyway, a simple program to test the motor would be:

```int motorPin1 = 8;
int motorPin2 = 11;
int motorPin3 = 10;
int motorPin4 = 9;
int delayTime = 500;

void setup() {
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}

void loop() {
digitalWrite(motorPin4, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin1, HIGH);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin3, HIGH);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin4, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin2, HIGH);
delay(delayTime);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, HIGH);
delay(delayTime);
}```

Now you cannot of course run the motor directly from the arduino ports. You can do this with special Motordrive IC’s like the L298D or with discrete components such as power transistors or FET’s, but a fairly cheap and simple IC that can be used is the ULN2003 darlington driver (or the MC1413).

A note though: with 6 wire unipolar steppermotors you can decide to forget about the  middle connectors (the ‘whites’ in this case) and drive them like a bipolar. That is something you cannot do  with a ULN2003, you need an H- bridge for that

If you do not know the voltage of a motor, then just start with 5 Volts and go up. Many steppers are actually 12 V. The ULN2003 can take 50 Volts and deliver 500mA per gate. As the motor I use has a coil resistance of 36 Ohm and the Voltage is 12Volt, that will be 333mA so that should be OK. Nevertheless, if you plan on using the motor at high speed, some cooling of the ULN2003 might be a good idea. There are DIL heat sinks available but you could also epoxy a piece of copper or aluminium U-tube on it. The ULN2003 is not the most efficient chip and the Darlington has a high voltage drop. The chip therefore dissipates a lot of energy.

Wire it up as follows:

The connections of the header are chosen as above since that was the sequence of the header on the motor (but remember red-brown are a pair and yellow red are a pair).

On using the test program above, the following connections would make the motor step properly:

D8-> red
D11->brown
D10->yellow
D9->blue

This seems as one would expect coz it is the 1a,2a,1b,2b or at least the 1x2x1y2y sequence. Similarly, one would expect that

D8 –>red
D11->blue
D10->yellow
D9->brown

(basically switching ‘1’ and ‘2’)  would make the motor step backwards and it does.

When the motor is used with the ‘Stepper.h’ library from the Arduino (e.g. in the Tom Igoe “Stepper_oneStepAtATime”), we see the same results.

For those interested to try the stronger torque program and try some direct bit manipulation at the same time have a look here:

As the steppermotor takes up 4 of the 7 outputs, you may want to consider using the other 3 to drive relais or a couple of small dc motors. The outputs of the ULN2003 may be parallelled for higher output current. The 3 darlington’s left therefore could drive a 1.5 Amp load.

If you need to drive two steppermotors consider the 2803 as that contains 8 darlington drivers rather than 7.

However, there is something else you can do with the spare gates, Remember the stepping sequence t o drive the motor?

 Steps Coil 1 Coil 2 Coil 3 Coil 4 1 1 0 1 0 2 1 0 0 1 3 0 1 0 1 4 0 1 1 0 1 1 0 1 0

There is a pattern in this table: Coil 1 is always the opposite of Coil 2 and the same goes for Coil 3 and 4. It is therefore possible to cut down on the number of pins from the Arduino (or other microcontroller) to just two, by using additional NOT gates.

The ULN2003 can provide these:

Programming then is very easy by toggling the two pins high and low.

If doing work with the Arduino and a stepper motor, consider AccelStepper as a library. It is more flexible.

Good site here (Spanish) and translated

Driving an Attiny? or here.
here
Steppermotor wiring.

## 4 thoughts on “Identifying and using a stepper motor on Arduino”

1. Benjamin Vis says:

This stepper paper is great, However I do not understand how the last circuit (after the line”The ULN2003 can provide these”) can work. Very interesting having only two signals to run the motor.
Could you, please, give an explanation or a reference ?
Thanks a lot.
Ben

1. Arduino says:

Benjamin, the explanation is actually given in the paragraph above the circuit:
“Coil 1 is always the opposite of Coil 2 and the same goes for Coil 3 and 4.”
That means that you do not need a seperate input signal from yr microcontroller to Coil 2 and Coil 4:
If you send a HIGH to Coil 1 you know you need to send a LOW to coil 2, rather than from a seperate port from the microcontroller, invert it from the signal for Coil1
Since the ULN2003 contains inverters, you can use the spare gates in the chip to provide the inverted signal:
If I send the signal 1010, I make D1 LOW and D2 HIGH. This signal is fed to pin 2 and 3 appears as a LOW on pin 2 and a HIGH on pin 3 which causes a HIGH on pin 14 and a LOW on pin 15. Thus I have the signal x01x. If D2 is HIGH, pin 7 becomes HIGH (via R3), this pin 10 becomes LOW, that steers pin 4 that becomes Low, thus pin 13 becomes LOW which switches on Coil 4 (gives me x010). The HIGH on D1 will make pin 6 HIGH (via R4) and thus pin 11 LOW. Pin 11 will pull pin 1 LOW and thus pin 16 will go HIGH, giving me 1010 on the motorcoils

1. Benjamin Vis says:

D1 -D1 -D2 D2
coil
D1 D2 1 2 3 4
0 0 0 1 1 0
0 1 0 1 0 1
1 0 1 0 1 0
1 1 1 0 0 1
Thanks for the nice reply, I’ve got it.
Somehow I did not find my way through the circuit.
I believe the above table summarizes all, where ‘-D1’ stands for ‘opposite of D!’ (10 and 01)
Benjamin

2. Arduino says:

Yes indeed 🙂

This site uses Akismet to reduce spam. Learn how your comment data is processed.