Stepper Motor Demonstration

Here is a quick run through of the stepper motor demonstration that I showed yesterday. Here’s a photo of the setup:

Stepper Motor Demo

The components are these (from the bottom of the photo to the top):

  • Arduino (using the AccelStepper library)
  • Parallel port “breakout” board (the black board in the photo)
  • Stepper motor driver (large red board)
  • Bench power supply
  • Stepper motor (connected to a belt)

The Arduino is connected to the parallel breakout board using four wires:

  • Ground (Black): ensures that all of the electronics has the same ground, i.e., reference point for measuring voltages.
  • Enable (White): allows the Arduino to control whether or not the motors are enabled (or active), switching the signal on this wire allows all of the motors to be shut down immediately.
  • X Direction (Yellow): controls the direction of turning (clockwise or counter-clockwise) that the motor connected to the X-Axis (labelled “A” on the driver board).
  • X Step (Orange): tells the driver board to perform a single step – this is sometimes called the “clock”.

Stepper Motor Demo: Arduino Wiring Detail

The motor is connected to the driver board using four wires. The stepper motor is a NEMA 17 bipolar stepper motor, the “17” refers to the size of the motor (i.e. it has a 1.7 inch front plate) and “bipolar” refers to the way the coils inside the motor are driven, which means that this motor has four wires. There are also “unipolar” stepper motors and these have size wires, but most driver boards are designed to work with bipolar stepper motors, if you end up getting a unipolar stepper motor, however, you can join two pairs of wires together so that you can wire it up as if it were a bipolar stepper motor.

Most bipolar motors like this one come with the wires coloured black, green, red and blue. This is great, because the wires need to be connected to the driver board in a particular order and if a motor has these colours it is likely to be exactly this order, i.e., black, green, red, blue, when reading from left to right across the connector. The wiring then looks like this:

Stepper Motor Demo: Motor Wiring Detail

Finally, after everything else has been wired up, connect the power supply. Lab bench power supplies, like the one I used here, aren’t cheap (this one from Jaycar costs $149) but they are great because they allow you to vary the voltage over a wide range. When using a driver like this one we can safely use a much higher voltage than the voltage value written on the motor, often called the “nominal voltage”, because the driver board will use a system like PWM to control the voltage given to the motor, in fact, because of the way the stepper driver works, a much higher voltage, e.g. I set my power supply to 24V, is preferable because it allows the driver board to do the PWM-like switching very fast, which makes the motor work better. The most important thing is to check that the positive (red) output of the power supply is connected to the positive (marked with a “+”) input of the stepper driver board, and that the ground is also properly connected. If you can’t see a difference between the wires connected the positive and ground wires it’s worth doing a check connectivity test with a multimeter before switching on the power.

The code running on the Arduino is relatively simple:

// Load the AccelStepper library

// Construct an instance of the stepper motor
// setting the type of control to "DRIVER" and
// the direction and step pins for controlling
// the motor through the driver board
AccelStepper stepper(AccelStepper::DRIVER, 3, 4);

void setup() {
  // Set the enable pin for the stepper motor
  // Tell the library that the direction and enable
  // pins are "inverted", i.e., HIGH == off
  stepper.setPinsInverted(false, true, true);
  // Enable the stepper motor
  // Set the maximum speed in steps per second
  // Set the maximum acceleration in steps per second per second
  // Set the target position we want to move to

void loop() {
  // Check is the motor has reached its target position
  if (stepper.distanceToGo() == 0) {
    // If so, then move to the next target
  // Get the stepper library to make the necessary steps
  // NOTE: This MUST be called regularly, e.g., every loop();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s