Instructables

Step 6: Stepper Motor

Picture of Stepper Motor
5B.jpg
5C.jpg
5D.jpg
5A.jpg
There are a number of different types of stepper motors, but in this tutorial we will specifically be addressing bipolar stepper motors. Bipolar stepper motors typically have 4 pins, which correspond to two coils. To use a stepper, you need to power these two coils in phase with alternating polarity.

To figure out which two pins make up a single coil, insert an LED into any two pins on its socket and rotate the motor shaft. If the LED lights up, you found one coil. The other two pins should make up the other coil.

To make a bipolar motor spin:
  1. Power the first coil.
  2. Next power the second coil with reverse polarity.
  3. Then power the first coil with reverse polarity.
  4. Finally, power the second coil.
To reverse the motor direction of a bipolar stepper, simply reverse the polarity of the second coil.

Here is code to make the stepper spin in one direction:

Here is code to make the stepper spin in the opposite direction:

 
Remove these adsRemove these ads by Signing Up
triumphtotty10 months ago
This is exactly what I was looking for! I need to run a motor from a TIMER so that other code (serial commands) can be processed, so stripping your code down and reworking it into an ISR routine worked like a charm.

Thanks!

tt
thanks it was great for me , it works boss
does this also work for a solenoid? I need it to spin in each direction.
Why can't I see my pictures on my post?
Hi, I have the same Arduino and same motor shield. I uploaded the sketch, but I can't make it do anything, and I mean anything. Do I have to change the serial port which is five now?

thanks.......
thedanger1 year ago
Great info, I have been wanting to do something with arduino, anything really. I ended up getting an uno and motor shield. But I'm new to all of this, and there is very little on the motorshield as far as....lets say , make it do something. I followed your instructable and got this stepper up and running first try. One question though, how can i control the rpms/speed, and can i just tell it to take "x" amount of steps and then reverse the same number back?
For the stepper motor code, what is the difference between the two versions that makes them spin the motor in opposite directions? The two code sets look the same to me, but since I am just starting with this, I can easily be overlooking the critical difference. And is "delaylegnth" supposed to be "delaylength" (as I said, just starting, so I am not familiar with the syntax quirks). Thanks!
randofo (author)  firephotoputer2 years ago
delaylegnth is a variable, so it was defined (misspelled) by me. If you correct one instance of the spelling, just be sure to correct all of them in the code.

The difference between the two is the direction of Channel B in each of the codes. Look at the difference of sequence for: digitalWrite(13, HIGH); //Sets direction of CH B
Now that you have pointed it out, the difference between the versions is obvious. Thank you!