Easiest possible stepper w/ arduino

Posted04/03/2009
  • Easiest possible stepper w/ arduino

    Eureka! I was able to get my mini steppers working (as described here), and boy was it easy! Here’s the arduino code I used. Hopefully I’ll soon figure out how I can drive five of these at once using only one arduino. I’ve got some ideas; we’ll see how that goes.


    /*
    * Blink
    *
    * The basic Arduino example. Turns on an LED on for one second,
    * then off for one second, and so on... We use pin 13 because,
    * depending on your Arduino board, it has either a built-in LED
    * or a built-in resistor so that you need only an LED.
    *
    * http://www.arduino.cc/en/Tutorial/Blink
    */

    int blue = 0; // blue wire on pin 0
    int black = 1;
    int red = 2;
    int yellow = 3;

    void setup() // run once, when the sketch starts
    {
    pinMode(blue, OUTPUT); // sets the digital pin as output
    pinMode(black, OUTPUT);
    pinMode(red, OUTPUT);
    pinMode(yellow, OUTPUT);
    }

    void loop() // run over and over again
    {
    digitalWrite(blue, HIGH); // sets the blue wire on
    delay(5); // waits for a 1/100 of a second
    digitalWrite(blue, LOW); // sets the blue wire off
    digitalWrite(black, HIGH); // sets the black wire on
    delay(5); // waits for a second
    digitalWrite(black, LOW); // sets the blue wire off
    digitalWrite(red, HIGH); // sets the black wire on
    delay(5); // waits for a second
    digitalWrite(red, LOW); // sets the blue wire off
    digitalWrite(yellow, HIGH); // sets the black wire on
    delay(5); // waits for a second
    digitalWrite(yellow, LOW); // sets the blue wire off
    }

    04/03/2009
    Tags: .
    Posted in Blog.
    | 8 Comments

8 Responses to “Easiest possible stepper w/ arduino”

  1. Aksel Says:

    Hello,

    As far as I can tell you are not using the white wire. So however the white wire is connected you are running the motor as a bipolar. Your code indicates that you are using wave drive. If in fact the motor is a unipolar (which I suspect) with the white wire being a common tap (and it may not be so), then you are not getting the most from the motor. In any case you are probably better off using full step. This will give you better torque. See code “Bipolar full step” below.

    Usually microcontrollers have better drain capability than source capability. If your motor is a unipolar then you should run it as a unipolar using the forte of your microcontroller. Try connecting the white wire to positive power supply and then pull the other four wires low in sequence (for wave drive). See also code “Unipolar full step” below.

    As to the question of whether or not your motor is a hybrid – in the ordinary sense of the word when describing stepper motors – it does not really matter to how the windings should be hooked up or what drive mode to use.

    Cheers.

    // Bipolar full step
    void loop()
    {
    // Forward polarize winding A
    digitalWrite(blue, HIGH);
    digitalWrite(red, LOW);

    delay(5);

    // Forward polarize winding B
    digitalWrite(black, HIGH);
    digitalWrite(yellow, LOW);

    delay(5);

    // Reverse polarize winding A
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);

    delay(5);

    // Reverse polarize winding B
    digitalWrite(black, LOW);
    digitalWrite(yellow, HIGH);

    delay(5);
    }

    // Unipolar full step.
    void loop()
    {
    digitalWrite(blue, LOW);
    digitalWrite(red, HIGH);
    delay(5);

    digitalWrite(black, LOW);
    digitalWrite(yellow, HIGH);
    delay(5);

    digitalWrite(red, LOW);
    digitalWrite(blue, HIGH);
    delay(5);

    digitalWrite(yellow, LOW);
    digitalWrite(black, HIGH);
    delay(5);
    }

  2. adam Says:

    Thanks for the great response Aksel!! I really wish I understood this stuff better. I’ll dive in deeper based on your comment and and post what comes of it. Thanks again!

  3. Tom Lynch Says:

    How are you getting on with your split-flap display, I have had a fair bit of interest in mine and have even been in touch with the manufacturer and have had some limited access to see how the old ones worked more closly, I am preparing to go to the laser cutter again to make my next prototype, I am just trying to choose a stepper with the accuracy I need to make this possible.

    Interested to hear your progress, email me or reply here/with a new post!

  4. adam Says:

    Thanks for checking in, Tom! I’ve been in the process of moving, and we won’t be finally settled in our new place until September 4th or so.

    I’ve just been totally swamped with other work lately, but I really want to make this happen! Let me know what you learn, and I’ll definitely let you know when I get back to it!

  5. sara Says:

    several months ago, i bought a ton of those little stepper motors and i was left in complete frustration when i wasn’t able to find anything online about connecting them to the arduino. like you, i had a very hard time reading the schematic. so i am very pleased to have found this blog because i’m finally able to get started with a project that i orginally intended on creating. i am a recent art school grad and i am trying to create a tiny mechanical butterfly with these motors, using the arduino. i have used servo motors in the past and i was unhappy with how loud they were and their overall function. although, if that is the only option i have, i guess i’ll have to deal with it. i want to use these steppers because they are so quiet and smooth. so i noticed that when i uploaded the code, the motor only seems to move in one direction, it’s not stepping back and forth. is this even a possiblity given the way that the wires are connected to the arduino? and why can’t an easy driver be used in this case? any help would be 100% greatly appreciated! thanks :}

  6. adam Says:

    Hi Sara:

    Good luck with your project! Sounds fun. I’ve played with the EasyDriver on other projects, and it works great. The problem? It’s way too expensive! For $15 each, I couldn’t afford more than a couple. You can tweak the code to make it go back and forth without much difficulty, but I’m probably the wrong person to help with that. The Arduino forums would probably yield better results. Basically with this post I was just trying to show the “simplest” possible way, not necessarily the “easiest”. Have fun!

  7. sara Says:

    thanks adam,
    i’ve been playing with the easydriver as well, and you’re right, it is expensive. i’ve tried tweaking the code but i’m really not very good at this yet so the arduino forums have become a close friend. i hope i can figure something out. although, i’m already becoming more fond of servos again :]

  8. adam Says:

    Servos are waaaaay easier, no doubt. In very loose terms, a servo is a stepper with an EasyDriver built-in. I think steppers are amazing, but not for the faint of heart!

Leave a Reply

Tutorials

  • Simple Graphic Trainer

    The last release of this app was a huge step over the first, but this one is by far the best yet. As I get more advanced with Processing and Arduino (mostly the former), this thing’s gonna rock the house!

    New in version 007:

    • bezier curve replaced with more accurate box-plot
    • dynamic target speed allows for sprint-interval training
    • “honorSystem” mode allows user to choose whether or not to reset timer when current speed falls below target
    • average speed for entire workout is now displayed above current speed
    • new, easier-on-the-eyes visuals

    Download the code:

    I’ve got lots more ideas up my sleeve, but the wife is telling me that I have to actually do something productive with the rest of my day :( Laaaaaame.

    Cheers!

    Adam

    03/10/2010
    Posted in Blog.
  • Choosing a 3D Package

    So you’ve decided you want to create digital 3D models.

    You might be an aspiring movie special effects guru, industrial designer, architect, or mechanical engineer. Maybe you’re wanting to create photo-realistic images of product design ideas, or maybe you want to use 3D Computer Aided Design (CAD) to control a Computer Numeric Controlled (CNC) milling machine to bring your ideas into physical reality. You might be hoping to play with rapid prototyping, mechanical simulation, or 3D animation for art, illustration, or demonstration.

    Knowing the right 3D software package(s) will not make you a good designer, a competent engineer, or a film effects creative genius. It will simply be a tool in your belt, there when you need it, making it possible for you to communicate three-dimensional ideas quickly and accurately for virtually any purpose you can imagine.

    But when you look for a specific program into which you’ll invest lots of time and money, the number of options can be daunting. How do you decide which 3D program is right for you?

    There is no magic bullet in the 3D software world; every piece of software that exists on the market has a niche for a specific type of user with a specific combination of needs. In this set of posts, I’ll try to make the pros and cons of all sorts of common 3D applications easily understandable for the newbie, and hopefully even clear up a few things for the seasoned professional.

    In this, the first post in our series, we’ll be looking at the broader landscape of 3D applications, and discussing the basic categories of 3D applications. more »

    03/08/2010
    Posted in Blog.
    | 1 Comment
  • Morris Minor 1000, Part 2

    This is the second part in a series building up a Morris Minor in modo. To start at the beginning, start here. more »

    03/07/2010
    Posted in Tutorials.

Design for everybody, by everybody.

CADJunkie.com is devoted to making in-depth CAD knowledge available to anyone who wants it, free of charge. My sincere hope is that it will be complementary to great projects like Neil Gershenfeld's 'Fab Labs'; Arduino, RepRap, Contraptor, and others. CAD software is the missing link in the open-source hardware movement, and my goal is to make it accessible to everyone.

Enough jibber-jabbin'. Lets make stuff.

--Adam
Adam O'Hern, Industrial Designer