Stepping Up to the Challenge

There are a handful of motors to choose from, and sometimes it's unclear as to which one will be best suited for your particular application. In this tutorial, we will discuss one of these motors, the stepper motor, and when it best to choose a stepper motor over the alternatives. We will also discuss how to use this motor with the EasyDriver Stepper Motor Driver board, one of the simplest driver boards around.

How it Works

Stepper motors vary from regular DC motors in that, rather than just spinning in one direction or another, they can spin in very precise increments. Imagine a motor on an RC airplane. The motor spins very fast in on direction or another. You can vary the speed with the amount of power given to the motor, but you cannot tell the propeller to stop at a specific position. Now imagine a printer. There are lots of moving parts inside a printer, including motors. One such motor acts as the paper feed, spinning rollers that move the piece of paper as ink is being printed on it. This motor needs to be able to move the paper an exact distance to be able to print the next line of text or next line of an image. There is another motor attached to a threaded rod that moves the print head back on forth. Again, that threaded rod needs to be moved an exact amount to print one letter after another. This is where stepper motors come in handy.

Stepper motors can move an exact amount of degrees (or steps) when told to do so. This gives you total control over the motor, allowing you to move it to an exact location and hold that position. It does so by powering coils inside the motor for very short periods of time. The trade off is that you have to power the motor all the time to keep it in the position that you desire. We won't go into too much detail here, but you can check out this Wikipedia article on stepper motors for all the nitty-gritty information. All you need to know for now is that, to move a stepper motor, you tell it to move a certain number of steps in one direction or the other, and tell it the speed at which to step in that direction.

There are numerous varieties of stepper motors as well as driver boards with which to control them. The methods described here can be used to infer how to use other motors and drivers not mentioned in this tutorial. However, it is always recommended that you consult the datasheets and guides of the motors and drivers specific to the models you have.

How to Use it

Here we will discuss how to assemble, hook up and control your motor with firmware uploaded to the Arduino.

Assembly

The simplest way to use the EasyDriver is to attach headers to it for easy insertion onto a breadboard. Alternatively, you could solder the wires straight to the board. These instructions will assume you are using the breadboard method.

The first step is to solder straight male headers to the EasyDriver. Very few of the actual pins on the EasyDriver will be used in this example. However, soldering headers on all the broken out pins is recommended to give the board more stability when attached to a breadboard. A simple method for this is to break off the desired amount of headers, place them in the breadboard in the appropriate locations, place the EasyDriver on top, and then solder all the connections.

Hook-up

Once you have all the headers soldered on, it's time to hook up the EasyDriver to your Arduino. Using the picture below, make all the necessary connections.

Note: The small stepper motor looks different than the one pictured. It should have a 4-pin connector on the end. This will be attached to the 4-pin male header facing upward (see picture #3 in Assembly). Because of the nature of this particular stepper, you can hook up the connector in either orientation, i.e. either the black wire on the left or the yellow wire on the left. It will work either way. If you are using a different motor, consult its documentation to find out which wires should go where.

IMPORTANT: Stepper motors require more power than can be supplied by the Arduino. In this example we will be powering the Uno with a 12V external supply. Notice that the power input (M+) on the EasyDriver is attached to the Vin pin on the Arduino. This will allow you to power both the Arduino and the motor with the same power supply.

Firmware

Once you have everything hooked up correctly, you can upload firmware to the Arduino. The following is some very simple example code to get you up and running. There are numerous examples online, as well as a Stepper library included with the Arduino IDE. Feel free to play around with this code, changing values to see what happens, and feel free to explore other code.

/*************************
Joel Bartlett
SparkFun Electronics
December 27, 2012
This code controls a stepper motor with the
EasyDriver board. It spins forwards and backwards
***************************/
int dirpin = 2;
int steppin = 3;
void setup()
{
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}
void loop()
{
int i;
digitalWrite(dirpin, LOW); // Set the direction.
delay(100);
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps.
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(500); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
digitalWrite(dirpin, HIGH); // Change direction.
delay(100);
for (i = 0; i<4000; i++) // Iterate for 4000 microsteps
{
digitalWrite(steppin, LOW); // This LOW to HIGH change is what creates the
digitalWrite(steppin, HIGH); // "Rising Edge" so the easydriver knows to when to step.
delayMicroseconds(500); // This delay time is close to top speed for this
} // particular motor. Any faster the motor stalls.
}

Going further

Now that you've figured out how to operate your stepper motor at the simplest level, it's time to take it to the next level. There is a vast amount of information on the web regarding the Easy Driver and stepper motors in general. The best place to look next would be the EasyDriver website. There is also an great tutoral on the bildr website. Another great resource is the EasyDriver Schematic. If you're curious as to what the other pins on the EasyDriver do, the schematic will give you some insight. Lastly, you can check out one of my projects involving stepper motors, the Arduija. In it, I use stepper motors controlled by EasyDrivers to create an X-Y gantry that moves a Ouija board automatically.

You should be well on your way to adding stepper motors to your next project. If you have any questions, comments or just want to show off your project, drop us a line in the comments below. Happy hacking!

Comments
28 comments

Any stepper motor tutorial that doesn't teach that there are unipolar and bipolar motors is mostly empty. Even more so when you carry both types.

I can understand you want to make a QUICKstart guide. But based on forum threads on stepper motor product pages, I can see most people have problem matching motors and drivers that you distribute. So we need a "selection guide" as much as we need a quickstart guide that explain neither motor types or driving current (or the mismatch between voltage rating of a motor and the voltage actually used to drive it through some driver).

Adding a warning that a stepper driver must not be disconnected while powered would be wise. Do you really expect readers to read the details of the driver if you give them a quickstart guide?

Ok, I am thinking the code is turning the stepper motor back and forth in a loop. Why not show a potentiometer with a schematic turning the motor back and forth or would that be too simple? I would definitely buy one of your stepper motors if I could see it working with a pot. It would be a good tutorial if it showed both approaches.
Thanks
jessey

Hi Jessey, pots don't really lend themselves to the thinking behind stepper motors... however, you could put the pot on an ADC input and then in the loop, change direction / speed based on the value. Would be easy-ish to subtract A0 from 512 and the speed be the distance away from 512 and the direction whether above or below. BUT, still ,there's the issue of number of steps... kinda goes more to a joystick input where up or down changes number of steps and left or right the direction??? :D

ImHO, pots work more for continuous running motors like to vary speed. My application for a stepper is to plot the performance of a throttle position sensor... a potentiometer if you will. Step 1 degree, stop, check voltage on ADC, repeat for ___ degrees or until ADC value doesn't change. :) Chris

Please email techsupport@sparkfun.com explaining what you've done and specifically what isn't working (as well as what you are expecting to see). If possible send a screen shot if you are getting a code error or a picture of your circuit if the code is uploading, but your setup isn't running. I know these things sound basic, but they will help out team weed out any a lot of possible problems (it is amazing what a picture will tell you).

Anybody who may still have trouble with using the easy driver (at least v4.4), and you have tried adjusting the current and double/triple checked your connections I strongly suggest you place a 47uF capacitor connecting the M+ and GND pins. I am using an unregulated 12 Volt 1 amp battery charger as a 12 volt power supply. The capacitor did the trick for me. The driver and motor are behaving very well with a nema 17 style motor.

i am using Arduino Uno 2560 and easy driver A1335 to run a stepper motor (four wire) but its not running. Wire connections are right becasue i checked it through oscilloscope and its generating a pattern according to given program code but the motor is still not running. I am using the same program as given on this page....only the easy driver that i am using is different....is that make any difference...?. Help needed.......

Using the Big Easy driver, 12VDC power supply and Arudino R3 and not getting great success. I'm using the example program and wiring shown in the Big Easy product page. With pot at low nothing happens. I turn it up about half way and the motor will jump a few steps but not rotate. If I turn the pot up higher the motor buzzes and the big easy shuts down for a while. Seems like its overheating. While the program is running and sending pulses the motor is locked tight, so I think it's getting the correct current. Seems like it's a timing issue where the motor is stalling.

Hi, I'm currently looking at a project that requires 4 stepper motors (moving at the same settings, but individually powered with on/off toggle switches). How would i go about connecting the 4 motors to the 1 EasyDriver?

A wonderful guide to start working with Arduino Uno. As you can see I add a link in my article http://www.intorobotics.com/arduino-uno-setup-and-programming-tutorials/ where is an impressive collection of guides and tutorials to start working with Uno.

I have a 6 wire stepper with 12v 0.4A spec (PN 57BYGH207). When it is steps slow it seems to work fine. When stepping faster it just jitters. The Power supply I am using is 12v 1.5A. I have some smaller 4 wire steppers that seem to work fine 12v 0.48A (PN 1-19-4203). Am I missing something?

In 2003, CU student Nate Seidle fried a power supply in his dorm room and, in lieu of a way to order easy replacements, decided to start his own company. Since then, SparkFun has been committed to sustainably helping our world achieve electronics literacy from our headquarters in Boulder, Colorado.

No matter your vision, SparkFun's products and resources are designed to make the world of electronics more accessible. In addition to over 2,000 open source components and widgets, SparkFun offers curriculum, training and online tutorials designed to help demystify the wonderful world of embedded electronics. We're here to help you start something.