vrijdag 25 oktober 2013

Stepper motor 28BYJ-48

This is the English version of this earlier blogpost.
Also check this blogpost on how to change the motor into a bipolar model with a lot more torque.

This must be the cheapest stepper motor I know. I guess the reason why it's so popular among hobbyists is simple: its price. I don't know many real steppers cheaper than 20€ and if you find one, you still need to take into account that it usually runs at high currents, so driving the thing with a microcontroller takes some high power circuitry which again is way too expensive for my purposes. I just want to have some fun with small projects where torque and speed are not really main issues. Accuracy is, though!

That's why I bought a whole bunch of these on AliExpress.com. If you buy larger quantities (which usually is the only option on that site), these babies only cost $2.5 each.

That's even including this small driver board equipped with a ULN2003 chip. That little thing makes driving the motor with an Arduino real easy and really really really cheap.


I found this datasheet which is actually describing the 12V version of the motor, but I don't see any difference between the two versions, other than its voltage. I prefer my 5V version though because it gives me the opportunity to use the thing in battery operated projects. There's no need for seperate power sources for the motor and the project that it belongs to. I also found this wiki page online with a lot of info on the motor.

Using the driverboard on an Arduino is real easy. All you need is four outputs that connect to four of the seven circuits in the ULN2003 chip on the small board. Actually three inputs of the chip remain unused, you could even drive some extra high power things like a power LED or a relay with the board. The inputs are there (inputs 5,6,7) but accessing the outputs might be a bit more tricky.

Now basically, all you should do is switching on the four outputs you defined in your Arduino program one by one. That's what makes the motor turn in on direction. Reversing the order would change its direction. If you repeat these steps about 500 times, then the motor should do almost one revolution. The word almost is a bit strange when used in this context, I'll try to clear that up a bit further. All this seems pretty straight forward and of course: it is. Too bad that it doesn't work that way. Ik had to search a bit further, because driving a thing like this (a unipolar stepper motor) can be done in a few different manners, as I found out later.

My gut feeling was not wrong. It just doesn't work on this motor. This table shows four different ways of driving a unipolar stepper, and the first one is called wave drive. That's what my initial thougts were, but again: it doesn't work with this motor. I tried it, but most of the time it didn't even start. When it did, there was no torque whatsoever and it made the little thing completely useless.

Half stepping is what it should be according to the manufacturer. That's number three in this table. It's a bit more complicated, but not that big a deal. All you need to do is use 8 steps instead of 4. If you would name the wires A,B,C and D, then the scheme would be the following: first activate wire A, then A and B together, then only B, then B and C together... and so on. So half the time, there's one wire active and the rest of the time there's two wires active. It should give the motor the smoothest movement and that's probably the reason why this is what the datasheet recommends. Well, actually it just says to do it like this. There's no alterative in the sheet. According to this table, there's a better way if you worry about torque, because half stepping only provides about 70% of the maximum torque available.

If you really want the full potential, try the second option called Full stepping. Get back to four steps, but this time always put a voltage on two of the four wires. The scheme would be AB, BC, CD an DA. This gives the motor its full torque.

There's a fourth way to drive a stepper motor, that's using Microstepping. That takes expensive circuitry, so I won't bother about that for this page.

But my first concern was definitely its accuracy and torque. Though moving heavy objects is not really my goal, the worst nightmare when driving stepper motors must be that the thing skips steps due to a heavy load. You probably wouldn't notice this phenomenon at first, but when you want to move an object at an angle of exactly 46,7° in one direction, then this is a major concern. The application that I have in mind for this motor requires this kind of accuracy, and if a part that only costs $2.5 could accomplish that, it would make me one happy camper.

That's why I did the following tests. I made this little Youtube clip which only shows half stepping. I tried measuring the real torque of the motor, because the initial tests using this wave drive method went completely wrong. With half stepping being the prefered method according to the datasheet, this would be my next approach. I want to know what torque to expect in real life, and equally important: at which speed it can do this. This is the result:



First of all, I measured one piece of important information. Its current is about 120mAmps in half stepping. Theoretically, that would take it to 160mAmps in full stepping, but I never measured this.

But again, the major concern was torque and speed. A torque of 300 gcm (0,03 Nm / 4.25 oz inch - nice conversion website here) can be measured by applying 300g weight on a lever of exactly one cm distance away from the center of the rotor. This is not very convenient in real life, so I tried a lever of 10cm with a weight of 30g attached at the end.

300 gcm was no problem, but when I tried 350, the motor hesitated. It was missing steps, as you can see when it returned and pushed away the whole construction. These tests were done at a a speed of 333pps (pulses per second in some datasheets) or 3ms delay between pulses. At this speed, one revolution takes 12.6 seconds.

I tried to speed things up to 500pps (2ms delay between steps), but then the motor also failed the test. The maximum speed without any load was 800 pps (1.2 ms delay or 5.0 seconds for one revolution). At higher pulses, the motor just stopped.

I also tried full stepping when no camera was running, and I found that 380 gcm was its maximum torque at 333 pps (3ms delay). Those numbers produce the absolute max torque this motor can produce (when connected as unipolar with the driver board that's included, check this blogpost to see how I converted this motor into a bipolar model, which increased its torque even more dramatically!!). Why full stepping is not the preferred method is not clear to me, it just says so in the datasheet. I found no downside to this method, the motor does not seem to make more noise or run less fluently than in half stepping.

The number of steps in one revolution is a bit of a mystery to me. I found different numbers online, but all tests I did resulted in 508 or 509 steps for one revolution. 508 doesn't really make a complete turn, and 509 overshoots the 360° a bit.

The truth no doubt lies somewhere between the two. What bothered me was the fact that it's not an integer value. Probably this is due to the fact that these motors are geared internally. Also, there seem to be a few versions of the motor on the market and not all models seem to have the same gearset inside. I found this topic that talks about this strange phenomenon.

Another really major problem is the fact that I measured a lack of almost 6° when the motor changes direction. This problem is huge when I need to be as accurate as I mentionned earlier. There's an easy solution though, and I plan to make a manual correction with the software that drives the motor. My plan is to always move the motor in one direction for accurate positioning. If I do need to move back, I'll overshoot 10° and move back. This keeps the gears always positioned in one exact direction.

I wrote some very simple Arduino code, which you can find here. Four functions define the two methods half stepping and full stepping. You can choose to test one function by uncommenting it in the major loop(). The half stepping functions are called forwards() and backwards(), full stepping is accomplished by uncommenting forwardsFull() or backwardsFull(). It may be a good idea to set all outputs back to LOW afterwards (function motorOff()).

12 opmerkingen:

  1. According to a posting at http://forums.parallax.com/archive/index.php/t-141149.html
    which counted teeth and did the ratios, there are 1650688/405 ~ 4075.7728395061727 half-steps in a full rotation. (Divide by 8 to get your 508-509 number).

    This value seems to be correct for the particular ones I have, but it may vary between manufacturers.

    BeantwoordenVerwijderen
  2. So I was pretty close with my 509 ;)
    Thanks for sharing the link, Viadd.

    BeantwoordenVerwijderen
  3. 28BYJ-48 Stepper Motor Teardown
    http://youtu.be/jRnhjrjtkvI

    A look at what goes inside a 28BYJ-48 Stepper Motor.

    A small geared stepper motor build.

    The Sketch. This example code is in the public domain using a Arduino with a 28BYJ-48 Stepper Motor Stepper and its controller

    Sketch it is buggy and needs work to improve it but it worked OK for this test:

    http://www.acomputerportal.com/arduino/camera_pan_and_tilt_V1/camera_pan_and_tilt_V1.ino

    I tried these with Arduino Stepper Pan and tilt using some junk. DIY motorised Stepper Pan and tilt

    http://youtu.be/GMD4mqVRyKY

    Tilts down OK or without a camera up and down so it suggests that my JVC Camcorder is just too heavy to tilt up very well using the 28BYJ-48 Stepper Motor.

    Arduino Experiments YouTube Playlist about the $9.00 Arduino.
    http://www.youtube.com/playlist?list=PL1N3_q4khW7LvjfbQBRtrvbMknXwYzRae

    BeantwoordenVerwijderen
  4. Reacties
    1. thanx for sharing such useful info about PPS. shaft was not woking and motor was only vibrating bt after this guideline i found that i was using too high PPS.. thanx...

      Verwijderen
  5. Hey, bro, I'm pretty sure that you've mixed up definitions for full- and half-stepping. I look forward to finishing the article. Thanks for posting this!

    BeantwoordenVerwijderen
  6. Deze reactie is verwijderd door de auteur.

    BeantwoordenVerwijderen
  7. Dear Jan i found your blog's articles really interesting.

    I am now working in some projects with th 28byj-48 stepper, and i want
    to ask you about something i read in the article
    http://www.jangeox.be/2013/10/stepper-motor-28byj-48_25.html

    you say.
    "Another really major problem is the fact that I measured a lack of
    almost 6° when the motor changes direction. This problem is huge when
    I need to be as accurate as I mentionned earlier. There's an easy
    solution though, and I plan to make a manual correction with the
    software that drives the motor. My plan is to always move the motor in
    one direction for accurate positioning. If I do need to move back,
    I'll overshoot 10° and move back. This keeps the gears always
    positioned in one exact direction."

    Does this happen in direction changes or in backwards motion?
    i am designing a floor roamer and i happen to have some problems
    turning my bot exactly 90o (one motor forward - one backward).

    you explain that
    If I do need to move back, I'll overshoot 10° and move back. This
    keeps the gears always positioned in one exact direction.

    I cannot quite understand why you have to move 10o instead of 6o
    If you have the time can you please explain me?

    BeantwoordenVerwijderen
    Reacties
    1. Hi Dimitris,
      What I mean with that is: always use one direction to position the motor. That can be forward or backwards, that doesn't matter.
      Suppose you choose forward to do the accurate positioning. You can make an exact movement of 90°, you can see how many steps that takes. If you then move backwards with the same number of steps, you will lose approximatelely 6°, it will not go far enough back. So if you add 10° to that, you are sure to pass that exact point. Then move forward again 10° and he makes the same mistake again in the other direction. The two errors balance each other out, you are exactly where you started.
      You could alse choose to go exactly 6° extra backwards as you suggest. That would work, except you don't exactly know how many degrees it overshoots, 5 - 6 - 7 degrees? My method works very well, I actually used this motor with an extra gear (it did 1500 steps for one turn) to move a small mirror. I pointed a laser in the mirror and checked the dot on a wall 5 meters further away. It returned exactly to that point with my method.

      Verwijderen
    2. Thank you a lot!!!!
      I'll try to adopt that method to see if i can manage to move accuratelly both directions.
      If you can send me bi-directional code also, it would me nice. I'll try no library, accellstepper and stepper.h, with ULN2003, with L298D AND with stepstick to check results.

      Verwijderen
    3. with stepper.h library. In Fullstep mode

      Stepper Motor(32, 2,4,3,5);
      and speed 400
      it takes according to my tests 2048steps for full rotation and almost 12more steps in the opposite direction to complete the turn. (not exaclty, 12-13) but it is acceptable resolution for many applications.

      void setup() {
      MotorL.setSpeed(400);
      MotorL.step(2048);
      delay(2000);
      }
      void loop(){
      MotorL.step(-2060);
      delay(1000);
      MotorL.step(2060);
      delay(1000);
      }

      i am running for 3hrs the test and the stepper is turning almost in the same point. And completes the rotation

      Verwijderen
  8. https://grahamwideman.wikispaces.com/Motors-+28BYJ-48+Stepper+motor+notes

    actually as i found in the above source we are not just talking about a 5v and a 12v version, but even gear ratios different! 7 versions at least!

    that affects a lot projects.

    Jan do you know how to explain those lost steps in altering directions? Why does it happen?

    BeantwoordenVerwijderen