Vernier Software and Technology
Vernier Software & Technology
Arduino and Vernier Sensors

Stepper Motors

There are two basic types of small, permanent-magnet stepper motors: bipolar and unipolar. Bipolar stepper motors have four wires that connect to the ends of two motor coils. Unipolar motors have five, six, or eight wires, four of which will connect to the ends of four motor coils. The easiest way to control a stepper motor with an Arduino is to connect it to the DCU, but the tricky part is identifying how to connect the wires.

If you are using a bipolar stepper motor, the first step is to identify which two wires go to the same coil. You can do this either by looking at a wiring diagram on the manufacturer’s website or by measuring the resistance between a pair of wires with a multimeter. The motor coil will have only a few ohms of resistance (often about 20 ohms on small motors), so find the pairs of wires with low resistance between them. When you have identified the two pairs, wire one pair to DCU lines D1 and D2; wire the other pair to DCU lines D3 and D4. Plug the DCU into the Digital 2 port on the Vernier Arduino Interface Shield or a Digital Protoboard Adapter wired to Arduino pins 6, 7, 8, and 9 as explained in the Connecting Vernier Sensors to the Arduino Using a Breadboard section. Connect an external power supply, such as the LabQuest Power Supply, to the DCU.

If you are using a unipolar stepper, you need to identify which four wires are “live.” The “live” wires will go to the four motor coils; the other wires are ground wires. Use a multimeter to measure the resistance between pairs of wires. The resistance between one “live” wire and a ground wire will be small (about 20 ohms), while the resistance between two ground wires will be negligible (zero). When you have identified the four “live” wires, connect them to DCU lines D1, D2, D3, and D4.

The VernierLib library contains a function to control a stepper motor:

Vernier.DCUStep(stepCount, stepDirection, stepDelay);

where stepCount is the number of steps the motor turns, stepDirection specifies whether the motor rotates clockwise or counterclockwise, and stepDelay is the pause between each step measured in milliseconds (the shorter the delay, the faster the motor turns). Note that the number of degrees the motor turns per step is determined by the manufacturer.

The sample sketch, VernierLibTutorialDCUStepper, will make the stepper motor rotate one complete rotation clockwise, stop for one second, and then rotate one complete rotation counterclockwise. Note if your motor does not rotate as expected, try switching the wires in the DCU screw terminal. Finding the correct wiring pattern is basically a trial-and-error situation.

/* VernierLibTutorialDCUStepper (v2017)
 * This sketch will make a stepper motor rotate one complete
 * rotation clockwise, stop for half a second, and then rotate
 * one complete rotation counterclockwise.
 * 
 * Connect the stepper motor to DCU line D1, D2, D3, and D4.
 * Plug the DCU into the Digital 2 port on the Vernier Arduino
 * Interface Shield or into a Digital Protoboard Adapter wired
 * to Arduino pins 6, 7, 8, and 9.
 */

#include "VernierLib.h" //include Vernier functions in this sketch
VernierLib Vernier; //create an instance of the VernierLib library

int stepCount=48; //create global variable for number of steps; modify if not making one complete rotation
int stepDirection=0;//create global variable for direction 0 = CW, 1 = CCW
int stepDelay=30; //create global variable for step time in ms; modify to change the speed of rotation

void setup() {
}

void loop() {
  Vernier.DCUStep(stepCount,stepDirection, stepDelay); //rotate the motor
  Vernier.DCU(0); //turn off all DCU lines
  delay(500); //wait half second
  stepDirection ++; //increment the step direction
  if (stepDirection > 1) stepDirection=0; //if finished CCW, reset to CW
}

Previous

Servo Motors

Contents

Introduction

Vernier Engineering Contest

Vernier recognizes instructors for creative uses of Vernier sensors to introduce engineering concepts and/or practices. Vernier Engineering Award »

Go to top