I've had a number of stepper motors sitting in my shop for years. If we really want to do anything fun with our Arduino, we are eventually going to have to run a stepper motor. So, here we go!
A little background on stepper motors and how they are different compared to a typical electric motor. Unlike a conventional electric motor that spins when power is applied, stepper motors incrementally spin (step), allowing control over exactly how far the motor's shaft spins, even to the degree.
Stepper motors have a series of electromagnets that encircle an armature containing a magnet. Think of a compass with a shaft attached to the center of the needle. That needle becomes like the armature of the motor. To spin the armature, electromagnets are turned on and off around the outside of the compass, causing the needle to "step" (or point) from one electromagnet to the next. This picture may help illustrate the movement within a stepper motor.
There are two common types of stepper motors: Bipolar and Unipolar See this article to help explain the differences. I've chosen to use a bipolar stepper motor in this project. It can be somewhat more difficult to use because of the need to reverse polarity on the stepper motor electromagnets to provide the proper stepping. Here's a couple pictures of the motor I used:
A bipolar stepper motor has two electromagnetic winding sets. Because of this, it's necessary to use some circuit to reverse the polarity of the winding. A common way to do this is through the use of an H-Bridge circuit.
A bipolar stepper motor has two electromagnetic winding sets. Because of this, it's necessary to use some circuit to reverse the polarity of the winding. A common way to do this is through the use of an H-Bridge circuit.
I used this circuit to create my H-Bridge controller:
I implemented the circuit on a perf board with a small 6 pin 90 degree header. I also added some LEDs to the circuit, just because everyone likes blinking lights, and I'm no exceptions. After all, that's what got me into this as a child ... blinking lights. Here's a picture of the H-Bridge:
I used the following diagram to pull the whole circuit together. There is an Inferred LED Interrupt sensor in this diagram. I'll talk about that in a subsequent post, so disregard for now.
I loaded the following very simple circuit onto the Arduino. It sets the speed of the motor to 10 RPM. Also, it turns the motor one revolution and then waits 2 seconds before looping.
#include
//create an instance of a stepper motor object
Stepper stepper(96, 8, 9, 10, 11);
void setup()
{
// set the speed of the motor to 10 RPMs
stepper.setSpeed(10);
}
void loop()
{
stepper.step(96); //on revolution
delay(2000); //wait 2 seconds
}
Lastly, here's a video to show this program in action with the whole circuit:
I used the following diagram to pull the whole circuit together. There is an Inferred LED Interrupt sensor in this diagram. I'll talk about that in a subsequent post, so disregard for now.
I loaded the following very simple circuit onto the Arduino. It sets the speed of the motor to 10 RPM. Also, it turns the motor one revolution and then waits 2 seconds before looping.
#include
//create an instance of a stepper motor object
Stepper stepper(96, 8, 9, 10, 11);
void setup()
{
// set the speed of the motor to 10 RPMs
stepper.setSpeed(10);
}
void loop()
{
stepper.step(96); //on revolution
delay(2000); //wait 2 seconds
}
Lastly, here's a video to show this program in action with the whole circuit: