I’m dedicating this entire week to documenting how to set up stepper motors. Last summer I had to experiment with many different ways of setting up stepper motors for my Maker Faire project: Miniature Motorized Mechanical Circus. I didn’t use a motor driver because I was using four different switches; I used four Arduinos to control four motors instead.
To set up a bipolar stepper motor, you will need:
Below are a diagram and the schematic that correspond to a bipolar stepper motor setup using an H bridge. I’m using an L293D H bridge and this stepper motor from Adafruit industries (available at the NYU Computer Store).
If the Fritzing diagram doesn’t do it for you, below is a schematic from the Arduino website. It’s basically the same thing: in the diagram above I’m showing you how I set up the wires in relation to the breadboard and the motor; in the picture below, you can see the schematic I followed, which details which pins of the H bridge go to the motor.
Step 1: Plug your H bridge into a breadboard. Connect power and ground on both sides of the breadboard.
Step 2: Using wire cutters and wire strippers, make four red and four black wires to connect power and ground from the H bridge to the breadboard. You can also use jumper wired, but it can get really messy really fast if you don’t use custom-made wires in your circuits.
The resulting circuit should look like a spider with red and black legs.
Step 3: To control the stepper motor using the H bridge, you want to connect four digital pins from the Arduino to the four input pins on the H bridge (labeled 1in, 2in, 3in, 4in in the schematic, starting from the top left corner and going counter-clockwise). These are the pins that will receive the instructions from the Arduino.
Step 4: Next, you want to connect the four output pins of the H bridge to the motor. As you can see from the diagram, I am using digital pins 2, 3, 4, and 5 to drive the motor, but you can use whichever digital pins you want (just make sure you update the example code I included below). The reason you need to use 4 pins is because there are 4 coils in the motor. See this article about how stepper motors work or check out Wikipedia if you need a more detailed explanation.
Step 5: Upload code to Arduino
In this example, I used the stepper library (included in the latest version of Arduino) to create an instance of a stepper called “stepper1″.
/* Stepper Test
Bipolar Stepper Motor
In this example, you are turning the motor 500 steps
in each direction using an H bridge.
Connect digital pins 2, 3, 4, 5 to the H bridge.
#define STEPS 200
Stepper stepper1(STEPS, 2, 3, 4, 5);
Here are some pictures of the circuit with a Freeduino instead of an Arduino.