Introduction: Stepper Motor Easy Driver

In this instructable I will provide a code sample and layout to connect a Nema 17 form factor stepper motor to an Easy Driver motor controller board then control the motor with an Arduino Uno.

Step 1: Required Components:

  1. Nema 17 form factor stepper motor
  2. Sparkfun Easy Driver Motor controller board
  3. Arduino Uno microcontroller.
  4. Power source for Stepper Motor (5 - 24 volts)
  5. Soldering Iron (or station) and solder
  6. Colored patch wire for connections

Step 2: Layout:

Notice in the picture of the stepper motor this motor has six wire locations but only 4 are used. The six wire configuration is for a "UniPolar" motor interface. This instructable is for a "BiPolar" motor configuration.

The Nema steppers can generally be used for either. There are many articles online about the difference between UniPolar and BiPolar stepper motor configurations. The location of the wires coming out of the motor also line up with the easy driver "A" and "B" wire connection points.

The wires on your motor may be different colors but the layout will probably be the same as the picture above.

Step 3: Code:

/*
 Stepper Motor Control - one rev back and forth
 This program is for the SparkFun Easy motor driver board.
 This program drives a bipolar stepper motor.
 The motor is attached to ground plus digital pins 8 and 9 of the Arduino.
 The motor should revolve one revolution in one direction, then
 one revolution in the other direction at a speed determined by 
 the milliseconds in the microSecDelay variable.
 Created by Bill Harper, Feb. 10 2014
 
 */
#include <Stepper.h>
int oneway;                      // counter for steps
int onerev = 6400;               // number of steps each direction (edit this 
                                    for your particular motor)
int microSecDelay = 30;          // delay between steps and speed of the motor 
                                    (about as fast as the system can react,
                                    higher number = slower)
int dirPin = 8;                  // output pin for stepper motor direction
int stepPin = 9;                 // output pin for the pin used to step the motor
void setup() {                
  pinMode(dirPin, OUTPUT);       // Assign output mode to pin for direction
  pinMode(stepPin, OUTPUT);      // Assign output mode to pin for setp
  digitalWrite(dirPin, LOW);     // Initialize dir pin 
  digitalWrite(stepPin, LOW);    // Initialize step pin
  oneway = 1;
}
void loop() {
  if (oneway < onerev + 1)            // Still in first revolution?
    {
      digitalWrite(dirPin, LOW);      // Keep direction pin low
    }
  else
    {
      digitalWrite(dirPin, HIGH);    // If not in first revolution change 
                                        direction pin to High
    }
  digitalWrite(stepPin, HIGH);       // Step motor
  delayMicroseconds(microSecDelay);  // Wait microseconds
  digitalWrite(stepPin, LOW);        // Step motor
  delayMicroseconds(microSecDelay);  // Wait microseconds
  oneway += 1;                       // Increment direction counter
  if (oneway > onerev * 2)           // If we have exceeded two revolutions
    { oneway = 1; }                  // Reset counter to start over again
  
}                                    // EOF