This page will show you how to wire a step/dir type stepper motor driver board to an Arduino. The driver board used in this particular example is available from Avayan Electronics and has thus far proven to be quite superb.
Although commercial driver boards vary in their design, the general method of wiring and controlling them typically remains more or less the same. The one thing to watch out for though is to make sure you buy a stepper motor that is compatible with your driver board.
If you buy a BiPolar stepper motor driver, then you can use basically any stepper motor just by wiring it correctly.
If you buy a UniPolar stepper motor driver, however, stepper motors with four wires (BiPolar) will not work, but all the other stepper motor types will.
If I have a choice, I generally just go with the BiPolar drivers because there are only four wires to keep in order.
Driver Board Stepper Motor Test Code
You can download example stepper motor control code by clicking the link. Stepper Motor Test.zip The code itself is rather simplified, but will be a good, quick test to make sure you have your board wired correctly.
You will notice that I have the code set up to test two stepper motors sense I am using them to control a pan and tilt solar tracker / heliostat. This entire tutorial is slightly biased toward this tracker, but hopefully not so much so that you won’t still find it useful if the tracker is not how you came to this site.
The code is programmed to turn Motor 1 one full revolution forwards and backwards. Next, (if it is set up) motor 2 will do the same thing.
NOTE: A word of wisdom from someone who has learned it the hard way, if you were thinking of using the Stepper.h library to control your stepper motor(s), don’t bother because it’s not for the step / dir type driver board like we’re using here. You might have luck using the AccelStepper library though.
Wiring the Driver Board to the Arduino
For my particular driver board (and possibly yours too), many extra “features” are built into it. These features can be controlled through the various pins if desired, or simply left unused if not needed.
The first thing we’ll address is the VCC and GND pins. Here, the VCC pin on the driver board is wired to the 5v pin on the Arduino and the GND pin just goes to, well, GND on the Arduino.
Next, we’ll take a look at the Step and Dir pins. The Step pin tells the stepper motor when it is time to move one step, and the Dir pin tells it which direction to take that step. It is possible to wire these two pins to most any of the Arduino’s pins, but I typically just use pins 2 and 3 for the first driver board and pins 4 and 5 for the second.
This last pin to address is the Enable (ENBLn) pin. Not all driver boards have this one. It’s purpose, however, is to basically just turn the stepper motor on and off. This can be quite useful if you are trying to save power. In my case, this pin must be written LOW to turn the board on and HIGH to turn it off. It sounds backwards, but that is indeed how it is set up. I have my Enable pin wired to pin 6 on the Arduino.
Pin Recap (Driver Board On Left, Arduino On Right)
VCC –> 5v
GND –> GND
Motor 1 STEP –> Pin 2
Motor 1 DIR –> Pin 3
Motor 2 STEP –> Pin 4
Motor 2 DIR –> Pin 5
Enable –> Pin 6
Note: When using multiple driver boards, it is possible for them to share Arduino pins. For example, 5v, GND, and Pin 6 can all be wired in parallel with multiple boards.
Controlling Step Size
It is oftentimes the case that you can control the step size of the stepper motor by changing settings on the driver board. You should check your driver board’s documentation to see how step size is controlled, but the one I’m using does so through jumpers (shown in the picture below).
A couple of reasons for controlling the stepper motor’s step size is for both increased precision and smoother (quieter) operation. Generally, the best step size for your particular stepper motor(s) can be determined through experimentation.
The various step sizes for my driver board can be seen in the picture below. One of the most important things to realize when changing the step size is that doing so also changes the number of steps required to move your stepper motor(s) a set distance.
For example, if I have a stepper motor which has 200 steps / rev written on the back of it, one would expect it to take 200 steps for the stepper to make one complete revolution. This would be correct if I were to use “full” stepping, but, if my driver board was set on “half” stepping it would actually require 400 steps to make one complete revolution.
If it was on “quad” stepping it would take 800 and if it was on “eight” stepping it would take 1600. You may have noticed that the full, half quad, and eight options are essentially just multipliers. Full stepping essentially just multiplies by 1 which means that it basically does nothing to the number of steps / rev printed on your stepper motor. Half stepping multiplies by 2, quad by 4, and eight multiplies by 8.
Wiring Driver Board to Stepper Motor
Wiring a stepper motor can either be really easy or really confusing. If you buy a stepper motor that has a decent data sheet you can access, and also if your driver board has good documentation, then figuring out how to do it shouldn’t be too overwhelming.
My general recommendation in this department is to just Google it because there is already a ton of information on this subject. Suffice it to say that there are just too many variations to really fit in this tutorial.
I will give you this one warning however, don’t start wiring the stepper motors to the driver board until you have turned off power. The driver board can be damaged if you do so.
For any stepper motor of a decent size, the Arduino itself will not be enough to power it. This is easily remedied by adding DC power supply to the mix. Driver boards can typically accept a range of voltage inputs, so check the documentation for yours to find out what it is. The power supply I’m using was originally for an old HP printer. It has a 18V output and is capable of up to 2.23A.
VREF, if your driver board has the option, essentially allows you to control how much power goes into your stepper motor. Too much power, and your stepper motor will overheat. Too little power, and the thing might not have enough torque to get the job done.
The documentation that comes with your driver board will likely contain formulas which will allow you to calculate the exact optimum VREF setting you should use. I generally go for the less scientific (lazy) approach and just start low and keep increasing until I reach a happy medium of adequate torque without too much heat.
I generally let the motors run for at least half an hour before determining that they aren’t overheating. I also check the driver board chip itself with a temperature probe to make sure that it also isn’t overheating.
A good temperature range for both the stepper motor and the driver chip can be determined by looking it up in their data sheets.
The actual VREF is typically set with a variable resistor. There should also be a place to test the VREF with a multimeter. Black probe goes to ground and red probe goes to the VREF contact point. As the variable resistor is adjusted, the measured voltage should also change. The higher the voltage, the greater the power to the stepper motor.
NOTE: Your driver board, like mine, might need to be hooked up to the Arduino first so that the enable pin can be controlled to turn the board on.
Finally, we have reached the end of everything (relevant at least) that I can think of adding to this page.
If I missed something, leave a comment below.