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.