Motors 3

How a four pole stepping motor works and how to drive it from your Arduino. A stepping motor works not with continuous motion, but in small precise increments.



Small DC motors as covered in Motors 1 & 2 are all very well at making things move but there is little precision about it. The only control you have over the movement they produce is to control the on and off time. However, there is another way of getting a motor to move, not continuously but in small precise increments, these are know as stepping motors. Although this is not the only way of generating movement on demand, it does have many advantages.

You probably already own a couple. There is one in your disc drive and two in most printers, in fact scrap computer equipment is an excellent way of getting hold of them.


A normal motor starts to rotate when you apply a voltage to it, and slows down and stops when that voltage is removed. If you want to control its speed you usually have to resort to gears.

Although there are various electronic methods of motor speed control these are usually used to make small adjustments, while it is gears that get the speed in the right order of magnitude.

The problem is that for a conventional motor to run efficiently it has to run at around 300 rpm.

The amount of turning power, or torque as it is known, is the way a motor's power is measured. With gears, as the speed is reduced the torque is increased - a very happy state of affairs.

However, most electronic motor control reduces the speed as well as the torque.

When it comes to controlling a conventional motor with a computer the motor takes some time to get up to its final speed. So it is difficult for the computer to "know" how many revolutions it has turned through. It is normal therefore to include some form of feedback arrangement so the computer can sense the motor's position. Such and arrangement of motor, feedback and control is known as a servo motor and is widely used in model aircraft but is not covered here. However, a servo feedback system is not needed with stepping motors, which is why they are such a natural for use with processors like the Arduino.

A stepping motors as its name implies, works not by continuously rotating but by moving in a series of small steps. Each time the motor receives a pulse it moves through a fixed angle. The size of this angle depends mainly on the design of the motor. There are two basic types of stepping motor, one with four coils, known as four pole or four phase motors and the other with two coils, known as two phase or wave motors. This page looks at four pole motors, the Motors 4 page looks at two phase motors. What ever the type the motors are usually classified by how many steps are taken to complete one  revolution - these can range from 4 to 200 steps per revolution. Another way of expressing this is to quote the size of angle of each step.


Let's see what makes a stepping motor tick. If you have a coil and pass a current through it you will generate a magnetic field. This will behave just like any other magnet and will attract other magnetic material to it. Suppose we have a permanent magnet suspended above four coils. If we pass current through two of the coils the magnet will be attracted towards both and will settle somewhere between the two. This is shown in here in figure 1a:-

We have an arrangement, which will l be explained later, to prevent the magnet getting too close to the coils. Now supposing we remove the current from coil 1 and turn on coil 3, as l in Figure Ib.

The magnet will move towards the two coils that are exerting a magnetic force and will come to rest between coils 2 and 3, as in Figure Ic. We can repeat the process with coil 2 going off and coil 4 coming on, as shown in Figures Id and Ie.

If we look what has happened to our magnet, we will see that it has moved in a straight line in response to our switching currents in the coils. This is the principle of the stepping motor, only instead of movement in a straight line we have a circular movement. This is obtained by having several coils, each wired as one of four circuits, distributed in a circle. We call this the stator of a motor because it does not move. In the centre of the circle we have a drum bearing a number of small magnets. The drum is known as the rotor - it's the part that rotates. The magnets are not actually separate magnets but are bumps or poles on a large central magnet. As the rotor is on bearings and the poles are distributed evenly around it, the poles can never come in contact with the coils. Figure II shows a small section of a stepping motor.

Only coil 1 is shown wired up, for clarity, but you can see that every fourth coil is connected together. You can also see that the number of coils in the stator is four times the number of poles on the rotor, and this number determines the angle of each step. A stepping motor can therefore be precisely controlled by switching the currents in each of its four coils. So a four phase stepping motor has five wires coming out of it, one for each of the coils and one as a common connection.

The coils take far more current than can be produced by the Arduino. This means we have to build something to convert our logic voltage output to the currents needed.

The simplest way to do this is to use four VMOS power FETs, most N-channel FETs are suitable. Figure III shows the general arrangement with the VN10K FET.

You can see from this that the stepping motor usually requires more than the normal 5 volts, and this is applied to the motor through the common coil connector. Most motors will operate with between 12 and 24 volts, although some can use 120 or even 240 volts. The FETs shown will happily switch voltages of up to 60 volts. Each of the FETs is controlled by one bit of the Arduino, these are labelled 0 to 3 but in most cases you want to avoid using the Arduino pins 0 & 1 as these are used for the serial communications. However, any of the other output pins can be used, by putting a logic l on the output, using digitalWrite(pin, HIGH); we can switch any coil on. By outputting the correct sequence of logic levels, that is highs and lows we can make the motor rotate.

Getting it to move

If we refer back to Figure I and write a logic 1 for each coil that is on and a logic zero for each coil that is off, we get the sequence of numbers to present to our motor. If each coil represents a binary bit then a way of describing the sequence of on and off can be written as a sequence of numbers 3, 6, 12, 9. That is:-

3 is made up from:- Coil 4 = off or zero, Coil 3 = off or zero, Coil 2 = on or one, Coil 1 = on or one


6 is made up from:- Coil 4 = off or zero, Coil 3 = on or one, Coil 2 = on or one, Coil 1 = off or zero

12 is made up from:- Coil 4 = on or one, Coil 3 = on or one, Coil 2 = off or zero, Coil 1 = off or zero

9 is made up from:- Coil 4 = on or one, Coil 3 = off or zero, Coil 2 = off or zero, Coil 1 = on or one

Note the last coil pattern is not shown in Figure I, but it is needed to wrap round smoothly to the start of the sequence again. Before we see how this can be generated by the Arduino let's look at another possible sequence of pulses that we can use to drive our motor. Consider Figure IVa.

This shows the motor in the same position as Figure Ia.

Now if we leave only one coil on, the magnet (pole) will go directly over it. This is shown in Figure IVb.

If we now switch on coil 3, the magnet will move between the two (see Figure IVc).

If we extend this sequence we will find that it takes twice as many steps as the first sequence. This results in the motor moving through only half the angle for each step - known as half stepping the motor.

In a similar way we defined the full stepping sequence, this half stepping sequence can be defined as:- 1, 3, 2, 6, 4, 12, 8, 9

The degree of precision is greater, but as you might expect, there is a price to pay, the motor's torque is reduced. As there is one coil on for half the time, you are putting less power into the motor. Therefore you get less power out.

With the full step sequence there are two coils on all the time. However in some circumstances it is a useful trick to know.

Any software must present the correct sequence to the motor’s coils. The easiest way to do this is to hold the sequence in an array and set up a counter to keep track of the next element in the array to be outputted.


If you want to see how to produce the full stepping sequence then you can get an example of an Arduino sketch to do this here:- Stepping.pde. Can you extend this to give a half step sequence? Note that to reverse the direction of the motor you simple reverse the sequence of the coils switching on and off.


Note top speed is something that is very variable, depending on the motor and load. We have seen that torque is the pulling power of a motor. In a stepping motor the torque is inversely proportional to speed. That means the slower it, goes the more power it has. In fact it has maximum torque when it is stopped. You can test this by trying to force the motor to turn by hand. You will find this harder to do when it is stopped but still has two coils on than when it is running fast. If we try to make it go too fast the motor will not have enough torque to turn itself, let alone a load, and so will stall. When you approach stalling speed you will notice the motor start to miss steps and make a stuttering sound. This maximum speed of the motor from a standing start is called the "pull-in" speed. If the motor is running it can be accelerated to a speed faster than the pull-in speed. The actual speed achievable depends on the power of the motor and the load it is trying to turn. So if you want to run stepping motors at full tilt you have to start them relatively slowly. One way to achieve more torque, and thus a greater speed, is to increase the current through the coils. This means increasing the voltage used to drive it. At some point you will reach a limit imposed by the DC current rating of the coil, which is usually dependent on a combination of heat and wire thickness.

Getting it to move faster

In fact you can go even faster than this top speed by employing a little trick. When you switch a coil on, initially there is no current flow as the change in current in the windings induces a magnetic field. This field then induces a voltage back in the coil, but in a direction to oppose the current flow. If this process was 100 per cent efficient you could never get any current to flow in a coil, but fortunately it is not. The result is that when the coil is switched on it takes a time for the current to build up. If you are stepping the motor fast, the current will not have built up to its full amount before the coil is switched off again. This accounts for the strange fact that a stepping motor takes more current when it is stopped than when it is moving. The trick in getting a faster rise time of current is to increase the voltage even more. However, this will exceed the maximum DC current through the winding when the motor is at rest and so a resistor should be inserted in each coil line to limit the current. When calculating the value of the resistor make sure to allow enough wattage as the resistor will get warm. The inductive part of the resistor/coil combination is thus proportionally smaller and so there will be a faster rise time of current in the coil, allowing a faster speed to be achieved.

Using less software but more hardware

The only snag with the type of control I have described so far is that it requires four Arduino output bits to drive the motor. We can make a saving in this number if we generate the sequence, not with software, but with hardware. Then we need only two bits to control our motor - one to specify direction and one to tell it to step. You can generate the required sequence with two JK flip-flops and a data select IC. This can be fed to the same power FET drives as shown previously.

However there is an IC which will do the whole job for you - and it is cheaper than individual components. There are many different types of driver chip available circuit diagram is shown in below uses just one type but they are all fairly similar.

The SAA1027 works with high level logic and therefore the logic levels out of the Arduino have to be boosted by the transistors T1 and T2. This IC can be connected directly to the stepping motor's coils with any supply between 9.5 and 18 volts. To drive this all you have to do is to set the logic level for the required direction and give a pulse to the step line. The time between the pulses controls the speed of movement, the shorter the time the faster it runs.

Trouble shooting

Most of the problems you are likely to have concern the motor making a chattering noise but not moving. This is almost certainly due to the fact that you have miss identified the coils and so you are putting the wrong sequence to the coils. Another common error is that you have underestimated how much current is being drawn and your power supply can’t handle it. If your motor has no markings then assume it is a low voltage coil and work your way up. Some motors are only 1.5 or 3V so start small, a variable voltage bench supply is very useful here.


Motors 3