Stepper Motor Quickstart Guide


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.

Stepper

Requirements

Here is a list of recommended items needed to follow along:

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.

alt text

alt text

alt text

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.

alt text

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 15 comments

  • 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

  • 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?

    Have a look there: Jones on Stepping Motors

  • 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?

    • You should only use one motor per easydriver. If you need to drive four motors, you’ll need something like this.

      • Apologies… beginner here. Would it be possible to solder on multiple cables to the 4pin connecter using one of those plastic screw connection terminals instead?

  • I am currently doing a project that requires 4 stepper motors that operate from the arduino uno. Is it possible to use 4 of the easy drivers off of one arduino uno?

  • 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.

  • Besides using pins 2 and 3 on the arduino to hook up the easy driver, can I use pins 6 and 7 and just change the code to suit those pins. Or must it be only on pins 2 and 3?

    Thanx

  • would my motor shield from arduino be the same as the EasyDriver Stepper Motor Driver? sorry new at this.

    thanks

  • 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?

  • Sorry to bring the bad news but Wikipedia link does not work! :(

    • Thanks for the catch! We’ll adjust the link immediately.

      In the meantime - The link is currently set to http://en.wikipedia.org/wiki/Stepper_motor/ which, you are correct, doesn’t work. However, this should.