This is an update to my first post about connecting a stepper motor to an Arduino or other microcontroller.
Wiring it up
This is a basic transistor circuit set up as a switch. It can also be called an open collector configuration since when it’s on it essentially connects what is on the output to ground. This type of circuit is useful for things like motors or lights where you are simply turning something on or off and need to provide more current than the microcontroller can. When it’s “on” it connects the output to ground and can pass a relatively large current through the transistor. When it’s “off”, the pullup resistor pulls the output high. When pulled high, it cannot provide much current, but since the controlled device is off, it doesn’t need to.

One thing to note on this type of circuit is that it is also an inverter. This means that when you input a high, you get a low output and when you input a low, you get a high output. This will come in handy later.
Since we are going to be driving an inductive load, it is a good idea to use a snubber diode (shown below) to arrest any voltage spikes that occur when you turn off the inductor (coil).

Here is an example of how this transistor switch circuit can be used to control a stepper motor. In this example I’m using four transistors for the four coil taps on the motor. This is a unipolar stepper motor so it has an extra tap that is connected to +5 volts (or whatever voltage you are using for the motor). This makes a unipolar motor easier to use since all you need to do is ground each of the four coils. With a bipolar stepper motor, you need a more advanced circuit called an H-Bridge that can swap the voltages on each end of each coil. (That’s something I may cover in a later post)

As you can see above this design requires four input lines from the Arduino.
Here is another illustration of it:
Making it go
Now that the stepper motor is all hooked up, we need to talk about how to make it move. This is the basic sequence that makes the motor move.
Moving from one step in the sequence to the next makes the motor move one step. If you go forward in the sequence, the motor moves forward one step and if you go back, the motor moves back one step. Stepper motors also have a specific number of steps needed to move one full revolution. For example the motor I’m using has 200 steps in a revolution.
The Arduino software comes with a library that makes it easy to control a stepper motor. Here is some example code to get it going: random_stepper2.pde. One problem with this basic setup is that it requires four wires to control it. An Arduino only has twelve digital pins readily available, so if you have big plans for your Arduino project, you will run out of ports very quickly. Wouldn’t it be nice to only use two wires?
The Two Wire Method
I mentioned earlier that the NPN transistor switch is also an inverter, meaning it outputs the inverse of the output. If you give it a 1, you get a 0 and if you give it a 0, you get a 1.
Now if you look at the stepper sequence you might notice something interesting. Of pins 1a and 1b, they are never the same. They are always the opposite of the other one.
The same is true of the other pair:
So, if we use the output of one transistor switch as the input of another one, we can eliminate one unnecessary input on each side.
So now, our circuit looks more like this:

In the Arduino software sketch, the line to set up the stepper motor looked like this:
Stepper stepper(STEPS, 2, 3, 4, 5);
But with out new two wire system it needs to be changed to this:
Stepper stepper(STEPS, 2, 3);
And that’s all that needs to change as far as the code goes. It functions just the same.
Now go find a stepper motor and start experimenting. I found this motor in an old floppy drive. Old computers are a great place to find parts like motors, fans, lights, and lots of other things.
Let me know below if you found this guide helpful or to share your experience with stepper motors.
Related posts:








Recent Comments