28BYJ-48 5-Volt Stepper

If you are using the code in my December 31, 2011 post the variable "motorSpeed" controls the speed since it is used for the "delay" value between steps.
If your goal is to increase speed, remember that this stepper is geared down with a 1:64 ratio - so it will never spin very fast. That said, it can be improved with a different library - see my post of January 17, 2012, 10:14:20 AM - try the AccelStepper library mentioned there. The VIDEO at that post shows the AccelStepper in use - your stepper should turn at least this fast.

The AccelStepper Library has speed() and runSpeedToPosition() functions that may give you what you want. While the AccelStepper Library supports a maximum stepping speed to about 4kHz, the 28YJ-48 supports a maximum no-load step rate of 900pps (less that 1kHz).

The 28BYJ-48 has a step angle of 5.625°/64. Therefore, one full rotation requires 4,096 steps. At 900pps (with simultaneous port writes as mentioned in the post of Reply #19 on: January 14, 2012, 10:17:55 AM) the maximum rotation speed computes to 13rpm (unless my math was wrong) - (900/((360/5.625)*64))*60. However, look back in this thread and you'll see that sbright33 says that he can achieve 35rpm. I don't see how this is possible but that is what he says. Please note, however, that he is running the stepper with 12VDC and he has to de-power it when idle to avoid overheating, so he is driving the stepper very hard.

As to speed, remember that this stepper was designed to move the vents on air conditioners, that are popular in Asia, with a goal of high torque not high speed.

Good luck with your experiments.

What he said. Seriously. My code does support acceleration in many of the functions so you can achieve the results in AccelStepper library without any effort. Even using 5v. 12v is capable of going much faster with the only difficulty that celem mentioned.

sbright33 - re "What he said. Seriously." No offence intended - your library and the empirical research behind it are commendable and it is just that your RPMs exceed the factory specifications and my personal experience. I have never tried running that stepper on 12V nor the resistors and capacitors. Maybe I'll try it when the time is available (if I can dig up a suitable 12V PS). I do have copies of your step1a.pde and step1p1dps.pde. Is there another version that I should try instead?

Here is the newest version for 28BYJ-48.

12v is reliable, you just have to mind the heat. This means you cannot run at full speed for 20 minutes. You can go slow forever using the "cool" functions. Or go full speed then stop to let it cool down.

Reply #74 on: March 13, 2013, 06:13:49 AM

Thanks very much for the information. I have a very big learning process ahead of me. I have bookmarked serveral of your suggestions so I can come back to them as required.

Hello,

I've been doing some tests with this motor and I found that it misses some steps in two situations:

  1. If you use speeds higher than 14 RPM;
  2. If you change the direction frequently.

Case 1 seems normal. It must have a limit when the motor can't rotate fast enough to follow the signals.

Case 2 is something more strange. I created a small sketch where the motor turns an angle based in the value of a potentiometer. The noise in the readings of the potentiometer makes the motor go forward/backward often. When I turn the potentiometer to the limit, it doesn't come back to the initial position. I could get some good precision only if I reduce the speed down to 8 RPM.

Have you noticed this?

izanette - I have never tested for precision. However, I would prefer to see programmatic tests without using a potentiometer. For example, running a securely fastened stepper via test software to a set-point position, mechanically marking the position, then pseudo-randomly run the stepper back and forth and finally return to the set-point position and verify its position to the previous mark.

celem:
izanette - I have never tested for precision. However, I would prefer to see programmatic tests without using a potentiometer. For example, running a securely fastened stepper via test software to a set-point position, mechanically marking the position, then pseudo-randomly run the stepper back and forth and finally return to the set-point position and verify its position to the previous mark.

Hi celem,

Yes, I agree that it is better to have some random movements to make it easier for anyone to reproduce the experiment. So, I created this simple sketch:

/*
 * Brownian motion
 *
 * A stepper motor moves forward by randomically chosen steps.
 *
 */

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 2038

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 10, 9, 11);

// the position of the motor
int pos = 0;

// end of the brownian movement 
boolean finish = false;

void setup()
{
  // set the speed of the motor to 7 RPMs
  // values higher than this leads to lose of steps
  stepper.setSpeed(7);
}

void loop()
{
  if (!finish)
  {
    // choose a value from -5 to 10
    // statistically, it will move forward.
    int movement = random(-5, 10);
    
    stepper.step(movement);

    // saves the position of the motor
    pos += movement;
    
    // finishes when it completes 2 turns
    if (pos > 2 * STEPS)
    {
      finish = true;
      
      // returns to the initial position
      stepper.step(-pos);
    } 
  }
}

Using it, I found out that the speed limit is even lower: 7 RPM. I'm using 4 NiMh batteries to power the motor, they supply about 4.8V. Maybe with a higher voltage it is possible to achieve higher speeds without loosing steps.

That makes sense to me. You can only go 7RPM when you change directions without a delay. You can go 14RPM in one direction. The solution is simple. Go 14RPM, then stop for a short delay before changing directions. It's easy to calculate the delay using 7RPM. It's just twice the delay between steps at 14RPM.

Why not use 12V as in my code? You can change the duty cycle while moving so it never gets warm. Increase it back to 100% for 1 step before and after you change directions. This will give you 30RPM without any delay, even when changing directions. That's 4x faster.

sbright33:
Here is the newest version for 28BYJ-48.

Stepper library for 28BYJ-48 · GitHub

12v is reliable, you just have to mind the heat. This means you cannot run at full speed for 20 minutes. You can go slow forever using the "cool" functions. Or go full speed then stop to let it cool down.

For sure there's something that I didn't understood but, after using, with success, the first sketch on this post, I'm trying the last one without obtaining nothing of good. The four red leds on the PCB stay fixed without blinking.
In the setup there's no declaration of potentiometer to drive the motor. Is there something, due to my ignorance, that I miss? Thank You!

I am having trouble. I found one code that I actually got to work, giving me the 1 RPM. I have to admit I did not save it and cannot find it again for love nor money.. For some of my previous postings you can refer to # 70 area. I Have had several other projects that needed my attention thus the delay in getting back to Stepper Motors.

I am wanting to start out fresh, and see if starting with a clean slate gets me on the right track.

I have some (5 sets) new motors and the 2003 drivers that should be on my door step in the next few days. I also have two of the A4983 driver boards.

My first objective is to load a fresh sketch with code that I know has been proven. I see several within these pages but am confused as I know zero about reading the codes. Your direction again to the correct code for the basic forward reverse operation would be greatly appreciated.

Once I get the new motors and boards, I will try to keep my nose to the grind stone until I get this mastered. Thanks so much for your help.

I don't think my code is compatible with A4983. Try it with ULN2003.

Just download my code from Gist. Try one function call at a time in Loop() until you get the hang of it.

HarrisCreekCentral:

I have a copy of Jack Purdum's Beginning C for the Arduino and would be happy to send it to you. (I pretty much know what's in it now.) I have a junk email account at h656775@yahoo.com if you want to send me your mailing address. On the email subject line write something like "Arduino C Book" so I don't just delete it!

Thanks for your work on this!
I'm new to Arduino, but your code makes sense so far apart from a few things...

My current Loop (test) code is:

  ramp(false, 1200);
  dw(13,HIGH);  
  degrpmslowCool4(false, 3.6, 1200);

I'd expect this to ramp up, then when the LED comes on to do one rotation - I assumed "deg100" is the number of degrees divided by 100. But it spins round more than that (around 2 times ish).

Can you clarify how the values work? My eventual goal for my project is to get the motor rotating at a known speed (doesn't need to be fast, a few RPM is enough, but I do need to know the speed is reasonably accurate; i.e. whatever function to run at a consistent 6rpm would be fine)

EDIT
Actually, just having this command in my loop:

degrpmEZ(false,90,1200);

Will leave the motor just spinning forever- so I guess the "deg100" is not what I think it is. And if my loop only has degrpmslowCool4(false, 3.6, 1200); in it, the motor never even moves..?

Off the top of my head while traveling I don't recognize ramp().
36000 is 360 degrees in my function call.
1200 is 12 RPM.

I wrote some non blocking code (not using the delay function) for these stepper motors a little while ago: Non blocking code for the 28BYJ-48 stepper motor - Bajdi electronics

I have just written some code that controls 4 of these little stepper motors using 2 74HC595 shift registers. So I'm controlling the 4 motors with only 3 pins. Will post it later on my blog.

Nice simple code! I have also included 4 non-blocking functions.

sbright33:
Off the top of my head while traveling I don't recognize ramp().
36000 is 360 degrees in my function call.
1200 is 12 RPM.

Ahh, reverse of what I thought - cheers, i'll keep playing!

2 Stepper motors with drive 28BYJ-48 (Chinese) + lib accellstepper

Hello everyone, I need help. I am wanting to use the lib that accellstepper

control over a stepper motor at the same time, but I can not for the code

using 2 motors running in opposite directions simutaneamente, triggered by buttons

for clockwise and counterclockwise. For lib "Stepper.h" and 2 engines already

get (below).

I thank anyone who can help.

#include <Stepper.h>


//
//
// 2 Motor de passo 5v + 2 botoes
//
//
#include <Stepper.h>  //Biblioteca já disponível na IDE do Arduino



 #define STEPS 150  // max 100
 
const int steps=100;  //Número de passos para o motor
 int buttonState1=0;
 int buttonState2=0;
 Stepper stepper1(STEPS, 0, 2, 1, 3); // Motor 1
 Stepper stepper2(STEPS, 5, 7, 4, 6); // Motor 2

void setup()
 {
 stepper1.setSpeed(200);    //Velocidade da rotação do motor (RPM)
 stepper2.setSpeed(200);    //Velocidade da rotação do motor (RPM)
 pinMode(8,INPUT);   //Botão 1
 pinMode(9,INPUT);   //Botão 2
 pinMode(12,OUTPUT);   //LED

 }

void loop()
 {
 buttonState1=digitalRead(8);
 buttonState2=digitalRead(9);
 if(buttonState1==LOW)   //Gira para um lado
 {
    digitalWrite(12,HIGH);
    stepper1.step(steps);
    stepper2.step(steps);
 }
 else if(buttonState2==LOW)  //Gira para o outro lado
 {
    digitalWrite(12,HIGH);
    stepper1.step(-steps);
    stepper2.step(-steps);
 }
 else   //Fica parado
 {
    digitalWrite(12,LOW);
    stepper1.step(0);
    stepper2.step(0);

 }
 }

Hi guys!

First of all thanks for the useful things in this thread.
The arduino is really new for me, so sorry about my noob questions.
I'd like to create a motorized camera slider, first only with one 28BYJ-48.
I found Sbright33's great library(Stepper library for 28BYJ-48 · GitHub).
But I'm so confused about the wiring. Do I simply connect the 28BYJ-48 motor to the arduino board. In this case how can I get 12V? Eg from the arduino board's Vin pin?
Or do I need to use the ULN2003 board (Connect the 28BYJ-48 motor to the ULN2003 and the ULN2003 to the arduino board)?

Thanks for your answer.

Regards,
Peter