The Maker Show: Episode 8 - Driving Your Stepper Motor with an Arduino

Sign in to queue

The Discussion

  • User profile image
    Noman Aslam

    Best tutorial about stepper i have ever seen... Thank you Sir.

  • User profile image
    BretStateham

    @Noman Aslam:Thanks!

  • User profile image
    Vlad

    Hello,
    My name is Vlad ( vladpine@gmail.com )
    I saw your video and i am trying now to make a dog feeder and i need some help:

    1. How i can say that i want everytime i press a button from x or y pin to move a certain ammount of deggres? ex: i press button x and the stepper move 45^ (or i can put x steps.
    2. What are speedlimits ?

    Thank you for the tutorial and i wish you my best :) sorry for my english

  • User profile image
    Ron SanAgustin

    Hi Bret. Thank you for a most definitive tutorial. It's exactly what I need for my project. I built a 5ft camera slider for timelapse with a 360 servo/timing belt pulling the camera carriage and a separate standard micro servo clicking the camera remote mechanically, with the slide servo providing the master clock on when to move on a "move shoot move scheme" Those 2 servos are working flawlessly with the pan platform on a lazy susan roller driven by another 360 servo. This pan servo is too fast at its slowest speed and does not have the resolution I need to consistently drive the pan platform. I tried a 28BYJ-48 which worked somewhat except the torque wasn't enough so I went with 0.9 angle Nema17 bipolar and Big Easy driver and eventually a SeedStudio motor shield and one of them was defective and I couldn't make them work. Shipped them back to amazon and I went back to the 360 servo after I learned about "delayMicroseconds" which gave me smaller steps but still falling short of my ideal pan movement(90degrees or less in 5 feet of travel). After watching your tutorial I revisited my 28BYJ-48 stepper with it's accompanying driver and I've made it work better than my first attempt armed with my new knowledge of full and half stepping. I want to use more torque this time with a Nema 17 1.8 degree unipolar. My question is, is there anything different I should do different? Can I use the same accompanying driver with 28BYJ-48 to drive the nema 17 unipolar, 6 wires vs 5 wires? How would I make the Nema 17 follow the carriage servo timing? I would really appreciate your input. Thank you :)

  • User profile image
    BretStateham

    @Vlad:

    For "degrees", if you watch my overview video (https://youtu.be/B86nqDRskVU?t=19m3s)  you can see that the step angle (after accounting for the gear mechanism inside the motor) is as follows:

    Wave Drive & Full Stepping Step Angle: .18° / step
    Half Stepping Step Angle: .09° / step

    So using that you can divide the total desired angle of travel by the step angle of the stepping method (full stepping or half stepping) you are using to get the target number of steps you need to travel.  In this video I show you how to have the motor travel only a target number of steps as well as controlling the clockwise or counterclockwise direction. 

    So the last piece would simply be to control the target position and direction based on a button press.

    Hope that helps. 

    Bret

     

     

     

  • User profile image
    BretStateham

    @Ron SanAgustin:

    Haven't tried any other motors than the 28BYJ.  However.  A Unipolar Motor should work fine as long as you can drive it with 5-12v (remember that is the voltage range supported by the ULN2003 driver board).

    Since it is a six wire unipolar motor, you need to figure out which leads are the ends of each coil, and which leads are your two center taps.  Then, connect the two center taps together and you have the same 5 wire pinout as the 28BYJ.

    As for syncing with the servo, not sure. 

    Bret

     

  • User profile image
    Sameer

    Hi Bret,
    I love this tutorial. Only problem is that my stepper motor is vibrating when I use the full stepping with arrays code. I checked the wiring everything seems to be in the right color order. Is it supposed to vibrate when we use Full stepping. It works smoothly when I run the brute force wave code.

    Thanks,
    Sameer

  • User profile image
    Kim Holland

    Greetings Bret,
    this is the clearest tutorial I've seen on Arduino and related items. I went back to the first as suggested and can now follow what the code does, so thank you indeed. I have the code downloaded and will try it very soon. It's years since I played with any code [Commodore 64 basic] so finding my way, but your explanations make it so much clearer for me. Thanks again, I'm certain to seek out more from you here. The mystery of steppers explained.
    Aye, Kim

  • User profile image
    BretStateham

    @Sameer:Not sure.  The only times I've had vibration from my motors are when I either have the coils wired wrong,or I was running them really slow (it kind of clunks from step to step when running slow).  It's been a couple of days since you posted your comment, did you get it figured out?  If not, do you have another motor you can try? I haven't really had any faulty motors myself, but they are pretty cheap so it is to be expected. 

    Bret

  • User profile image
    BretStateham

    @Kim Holland:Thanks Kim, these motors are a lot of fun and really get the mind going on stuff you can do with them.  Enjoy! 

  • User profile image
    BretStateham

    @BretStateham:Actually, you might be trying to drive it too fast too.  Try playing with the "delay(x)" statement at the bottom.  Smaller delay values mean faster motor speed.  Higher delay values mean slower motor speeds. 

  • User profile image
    Ron SanAgustin

    Hello again, Bret. Happy to report, I got it working with all your examples. Thank you. You gave me a clearer understanding of the coding process. This is the closest I've gotten to my ideal. But my pan stepper is till traveling too big an angle per loop even if I half-step a 1.8 deg stepper to .9 deg. I have to change to a planetary gear reduction stepper to bring it down to 0.35 deg. or at least a .9 motor half-stepped to .45 deg. Due to availability/shipping issues I'm forced to look at bipolar gear reduction steppers. Will your unipolar code work with bipolar steppers as well as other non-ULN2003-based driver/shield like the Big Easy and Seed Studio Motor Shield? Thanks again for your unselfish sharing of information.

  • User profile image
    BretStateham

    @Ron SanAgustin:Boards like the Big Easy Driver help to simplify driving steppers by taking care of firing the proper coils for you.  For example with the big easy driver, you just set a direction pin to indicate clockwise or counter clock wise, and then just toggle a step pin each time you want it to step.  In addition, boards like the Big Easy driver can do "Micro Stepping" which gives you even finer resolution than half stepping.

    SparkFun has a hookup guide for the Big Easy driver board that you can read up on before buying it here: https://learn.sparkfun.com/tutorials/big-easy-driver-hookup-guide

  • User profile image
    john

    Hi
    Thanks so much for the great tutorial.
    I have tried the ACCustepper code and some of there examples. Do you know if there is a counterclockwise function or something. I just want to run a motor at a constant speed, which I have got going, but I can only get it going clockwise.
    Thanks John

  • User profile image
    hoony

    hi. Bret.
    thank you so much your tutorial.
    but how to control 3 - stepper motor at the time??

  • User profile image
    Rizal

    Hello,It's a good tutorial, I'm interested in your idea, I want to know how if from analog to motor, for example using LDR sensor (A0), the motor will go right if sensor ldr to light, if dark motor will reverse direction, how is the arduino code? thank you

  • User profile image
    Btoom

    How do we stop the rotation?

  • User profile image
    Sherry

    Hi Sir,
    I was wondering if this can also work with a servo motor or a direct current (DC) motor.

    Thanks,
    Sherry

  • User profile image
    Neil Moffatt

    Brilliant. You strike the perfect balance between assuming nothing and avoiding patronising the audience, whilst stepping incrementally. Better than most teachers at school.

  • User profile image
    Nicolas

    I loved the tutorial!!! Really useful stuff here, very well explained and with good sense of humour.

  • User profile image
    PedroEugenio

    Really good tutorial! Nice intro into stepper motors and very simple, but effective, arduino code.

    Tanks!

  • User profile image
    Kathia Coronado

    Great video I love the explanation! I just have one question, I am trying to operate an 8 wire 4 phase Stepper motor. However, can I use the ULN2003 driver board with the 8 wire motor if I wire it in series ? or should I purchase the ULN2003A? What is the benefit of the ULN2003 driver board over the ULN2003A or ULN2004A? Any suggestion or recommendations you may have would be greatly appreciated.

  • User profile image
    jericsynergy

    REALLY nice, totally clear.  Thanks for ff'ding thru repetitive stuff.  As an animator, kudos on the motion graphics.

    Really, exceptionally good.  THANKS.

  • User profile image
    prichardson​dev

    damn Skippy! That's how tutorials should be done. Great series!

  • User profile image
    amnaj

    To speed up or slow down will have to do? How to write code and how to wiring?

Add Your 2 Cents