Arduino stepper motor driver - a tutorial

This tutorial shows how to explore an inexpensive stepper motor and driver board using an Arduino and included stepper library.

The stepper motor and driver board can be purchased on eBay at very low cost, and is an ideal educational project for the budding Arduino practitioner.

Fig 1:

Fig 1 shows the test setup:

The stepper motor and driver module were purchased on eBay for less than $2 including post, but price seems to have crept a bin lately. The motor has a 5.6° step angle and 64:1 gear box, and is a unipolar (five wires). Some of the driver modules being sold do not have the four diagnostic LEDs, but they are worth having.

The motor is powered from +5V with a link on the driver board. The whole thing will run off USB power, but it is probably better to power the Arduino board as is done in this case.

The jumper wires are readily available on eBay and from some robotics shops.

The project uses the stepper library module in Arduino. The algorithms in that module will achieve only 32 steps per turn of the motor shaft, 32*64 per turn of the output shaft. The program code is derived from a sample file provided with Arduino.

Fig 2:

Fig 2 shows the Arduino IDE window. For this exercise, the rotation is set to one eight of a turn for convenience in capture of the drive waveform.

Importantly, note the order that the pins are listed in the statement that creates myStepper. Physically, the wires are connected 2-IN1, 3-IN2, 4-IN3, 5-IN4. Other connections may not work properly.

Fig 3:

Fig 3 shows the input signals to the driver module, captured using a Logic Shrimp and displayed on OLS. The capture includes a clockwise rotation, the 100ms rest time, and then the anti-clockwise rotation.

Fig 4:

Fig 4 zooms in on the clockwise drive waveforms.

The code

Fig 5:
#include "Stepper.h"

const int stepsPerRevolution = 64/2*64;

// initialize the stepper library on pins:
Stepper myStepper(stepsPerRevolution,2,4,3,5); 

void setup() {
// initialize the serial port:

void loop() {
// step one revolution in one direction:
// step one revolution in the other direction:

Above is the example code.



Version Date Description
1.01 24/09/2013 Initial.


© Copyright: Owen Duffy 1995, 2021. All rights reserved. Disclaimer.