Controlling a Stepper Motor with an Arduino

arduino316As one one of my first projects with my new Arduino I thought I would try to hook up a stepper motor. I had a few laying around from old computer hardware I had taken apart and now I finally have the resources to hook them up.

I have a couple of bipolar motors, but I started with this unipolar since it requires fewer components to hook up. since I didn’t have a driver chip I used some 3904 transistors to provide more current to the coils.

Arduino Controlling a Stepper Motor

Arduino Controlling a Stepper Motor

Each line has an LED to show the sequence of which coils are being activated. There is also a diod on each one to drop the feedback from each coil when it is turned off.

And here’s the video:

I have it running a program that picks a random number of steps and either forward or backwards then moves in that direction. There is a library included with the Arduino software that makes using stepper motors pretty easy once you get them wired up. You can check out more here:

Update: Here is a better illustration of what’s going on. This is missing the LEDs I added as a visual aid, but it has everything you need to make it work. I’m using 2n3904 NPN transistors and I added some diodes (1n4000 series) to prevent kickback from the motor.

Arduino Stepper bb

Here is a simple sketch to see if your stepper motor is working: random_stepper2.pde

9 replies on “Controlling a Stepper Motor with an Arduino”

  1. […] a Stepper Motor with an Arduino Part 2 This is an update to my first post about connecting a stepper motor to an Arduino or other […]

  2. Gabriel says:

    Great tutorial thanks!

    I’ve managed to successfully control a stepper motor with the circuit in part one.

    The stepper motor I’m currently using is smallish like yours. I have several larger stepper motors and was wondering if it was possible to add a separate power supply and larger transistors to this circuit for the larger stepper motors.

    I’ve tried a few things, but I don’t know a whole lot about electronics, so maybe you could point me in the right direction. Just a single word that I can type into a search engine could make all the difference.

    Many Thanks!

  3. […] Posted by Preecha thank,but i control with Arduino AVR .Can i applied that Controlling a Stepper Motor with an Arduino | Azega Reply With Quote   + Reply to Thread « Previous Thread | – […]

  4. nik says:

    a bit off topic, but how did you make the schematic picture? is there some free software to draw out your projects? That would be of great help for me :-)

  5. Thomas says:

    the schematic picture looks like generated with fritzing. fritzing is open-source –>

  6. Carlos says:

    I am a complete ignorant trying to find his way. I loved your tutorial but I have a big doubt.
    I have two stepper motors but they only have 4 wires. Since yours has 5 I don’t know wht to do…

    Would someone help me please?



  7. frank says:

    Hi. Can you please explain how the diodes
    are working in this? Flyback diodea from what i see make the current go in a loop around the inductance, but i dont see how it would do that here. Pls clearly explain the diode. Also, why are there 2 paths from the +5 volts to the transistor? 1 goes threw a resistor and 1 threw the coil. Why do you need both paths?

  8. games says:

    this nice but what about 12 volt stepper motor? i want to control it from arduino

  9. Henry Berg says:

    Hi – thanks for putting up this very helpful circuit! Have you ever run into a stepper that wants really nonsense inputs and/or may be really picky about the delay timing computed in the Arduino library’s Stepper::setSpeed method?

    I just hooked up a stepper from Radio Shack (I know, I just wanted batteries but it was right there and all shiny). The motor claims to be 4 phase with the following to say about step angle (I’ll quote because it’s weird): “Step angle:5.625/64; reduction ratio: 1:64” I assume they did not *literally* mean the step angle is 5.625/64, or 0.087890625. I tried running the arduino example stepper_oneRevolution (which should just rotate the motor one full revolution and back) with a stepsPerRevolution of 64 but that only resulted in about an about an eighth of a rotation. So I multiplied my stepsPerRevolution by 8 to 512 and the motor just made a buzzing noise. Guessing it was unhappy about the delay timing, I dropped the RPM down to 30 and the motor would turn but this time only about a quarter of a revolution. I pumped the steps per turn up to 2048, got a motor buzz again, then pulled the RPMs down till the motor would function which turned out to be 8 RPM.

    So, to recap those numbers, it seems to take a stepsPerRevolution of 2048 with an RPM around 8 to drive this stepper motor to one complete revolution. This seems totally nuts to me. Ever seen anything like this?

    For the record, I’m *pretty* sure I have the motor wired correctly. This *did* come from Radio Shack so naturally there’s no pinout diagram but the pin arrangement I settled on was the only one that resulted in any movement at all.


Leave a Reply

Your email address will not be published. Required fields are marked *