28BYJ-48 5-Volt Stepper

Hey sbright33,

I've been following your tracks and posts for the last 3 hours and think that your work will help me like....a LOT. :slight_smile:

I'm trying to build an old school split-flap display, like the ones that we used to see in train stations...

I bought five 28BYJ-48 12 Volt from adafruit (those : Small Reduction Stepper Motor - 12VDC 32-Step 1/16 Gearing : ID 918 : $4.95 : Adafruit Industries, Unique & fun DIY electronics and kits) and ULN2003 cards to control them (ULN2003 Stepper Motor Driver Board – ElectroDragon) and trying to control all of these with an arduino mega.

Got lot's of problem wiring everything since specs on both of those equipements sucks (inversed wired, no further explanation to use the 5V/12V jumper on the board...etc) but I think everything is ok now regarding hardware...

I tried the "classic" stepper library but I'm getting serious issues with it :

  • my stepper doesn't seem to respond the same way clockwise and counterclockwise with the same "step" entered...
  • my steppers are getting hot very fast
  • the specs of my motor give me 768 steps but it seems to approximately correspond to 1,5 rotation, can't understand why...etc etc

I also tried the AccelStepper library but as your hardware is closer to mine (except my motors are 12V) I'll jump in your code and see where it leads me...

If someone already got back to you on modifications needed on your code with the 12V model of the 28BY J-48 I'll be happy to have their comments... XD

Anyway, I'll get back to you in few days with questions (many, many questions...) and maybe the biggest THANKS that you ever had for this code !!

Welcome! You don't need to modify my code to use it with 12v motors. If your power supply is 12v then the temperature will be the same as running a 5v motor with 5v PS. A 12v motor will of course have more torque and speed. With my "cool" functions you can use your 12v motor with a 18-24v power supply. Otherwise you will not need the "cool" functions. They are designed for running a 5v motor at 12v or a 12v motor at 24v.

sbright33:
Thanks it is great to feel appreciated! But I'm still in doubt about the number of users. I know my code is not perfect. I know it is confusing at times. Doesn't anyone have suggestions for improvements? Bugs? I'm really not that good. It's been a year now. Maybe there are many users who used my simple functions, and have not advanced to detecting torque or non-blocking code. Don't be scared to try them!

OK, now that the stress of Christmas is almost over, I'm going to get back to this! So, are you saying that you are happy with the functional state of your library, but you'd just like someone to suggest ways of making it more clean and readable for newbies (like me!)

For example, you have:

const int mp4a = 13;	// 13 is not PWM should use 6 todo later

Is that actually OK to go ahead on rely on?

No, it's a horrible idea to use pin 13 for PWM, since it's not supported. You should use pin 6 instead?
It works with pin 13 as written in my code. I used it because it's convenient to connect the wires.
I deserve to be shot for keeping that in the code... But it works! It was originally a mistake.
Thanks for pointing it out, and reminding me. That's what comments are for in my code.
It was a test to see if you're paying attention? Somebody is actually using that function?

Hi Sbright33

I am trying to use your code to experiment with a 28BYJ-48 and uln driver board
and a arduino mega 2560
I compile your sketch and upload it successfully (ts rx lights flash)

then nothing happens

Probably a dumb Question, what digital pins are you using ( 4. 5. 6. 7. ) ?

Is the anything i have to do with the sketch for it to run

Be patient I am new at this.

cheer Owen

Hello Sbright33

I also trying to use your code.
I have copied it from Stepper library for 28BYJ-48 · GitHub and paste to Arduino IDE
compiled and nothing happens..
I have tried uncomment two lines in loop

void loop(){
calloften(); delay(500);
off();while(1); //halt
}

but in not helps..
I have arduino nano + 28BYJ-48 + uln2003 driver board - all connected in proper way to 4,5,6,7 pin on arduino..

all other examples for stepper motor are working ok..
please advise.

Hello,
I am trying to run 2-28BYJ-48 steppers using the Accelstepper library by Mike McCauley on an Uno R3. If I run the base multistepper example, stepper one does not reverse and stepper two will turn and stop. I found Celem's modification "accellstepper 28BYJ-48" for a single stepper, which I tried to adapt and I can get stepper 2 to reverse, but stepper 1 continues in the same clockwise direction. Any advice would be helpful.
Thanks

// MultiStepper.pde
// -*- mode: C++ -*-
//
// Shows how to multiple simultaneous steppers
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Runs other steppers at the same time
//
// Copyright (C) 2009 Mike McCauley
// $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $

#include <AccelStepper.h>

// Define some steppers and the pins the will use
AccelStepper stepper1; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);


void setup()
{  
    stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(50.0);
  stepper1.setSpeed(200);
  stepper1.moveTo(2048);  
    
    stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}

void loop()
{
    // Change direction at the limits
    if (stepper1.distanceToGo() == 0)
	stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0)
	stepper2.moveTo(-stepper2.currentPosition());
    stepper1.run();
    stepper2.run();
    
}

actually, this is the code that will reverse stepper 2, but stepper one continues without reversing

// accellsteppertest.ino
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Derived from example code by Mike McCauley
// Set for 28BYJ-48 stepper

#include <AccelStepper.h>

#define FULLSTEP 4
#define HALFSTEP 8

//declare variables for the motor pins
int motorPin1 = 6;	// Blue   - 28BYJ48 pin 1
int motorPin2 = 7;	// Pink   - 28BYJ48 pin 2
int motorPin3 = 8;	// Yellow - 28BYJ48 pin 3
int motorPin4 = 9;	// Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)

// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper1; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper stepper2(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);

void setup()
{ 
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(50.0);
  stepper1.setSpeed(200);
  stepper1.moveTo(2048);   
  
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}

void loop()
{
  //Change direction at the limits
  if (stepper1.distanceToGo() == 0) 
    stepper1.moveTo(-stepper1.currentPosition());
    
  //Change direction at the limits
  if (stepper2.distanceToGo() == 0) 
    stepper2.moveTo(-stepper2.currentPosition());
  
  stepper1.run();
  stepper2.run();
}

OK, got it. probably had to do with the pin definition

// accellsteppertest.ino
// Runs two steppers forwards and backwards, accelerating and decelerating
// at the limits. Derived from example code by Mike McCauley
// modified by Celem for single stepper
// Set for two 28BYJ-48 stepper motors

#include <AccelStepper.h>

#define FULLSTEP 4
#define HALFSTEP 8

//declare variables for the motor pins
int motorPin1 = 4;	// Blue   - 28BYJ48 pin 1
int motorPin2 = 5;	// Pink   - 28BYJ48 pin 2
int motorPin3 = 6;	// Yellow - 28BYJ48 pin 3
int motorPin4 = 7;	// Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)
int motorPin5 = 8;	// Blue   - 28BYJ48 pin 1
int motorPin6 = 9;	// Pink   - 28BYJ48 pin 2
int motorPin7 = 10;	// Yellow - 28BYJ48 pin 3
int motorPin8 = 11;	// Orange - 28BYJ48 pin 4
                        // Red    - 28BYJ48 pin 5 (VCC)
// The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
AccelStepper stepper2(HALFSTEP, motorPin5, motorPin7, motorPin6, motorPin8);

void setup()
{ 
  stepper1.setMaxSpeed(1000.0);
  stepper1.setAcceleration(50.0);
  stepper1.setSpeed(200);
  stepper1.moveTo(2048);   
  
  stepper2.setMaxSpeed(1000.0);
  stepper2.setAcceleration(50.0);
  stepper2.setSpeed(200);
  stepper2.moveTo(2048);
}

void loop()
{
  //Change direction at the limits
  if (stepper1.distanceToGo() == 0) 
    stepper1.moveTo(-stepper1.currentPosition());
    if (stepper2.distanceToGo() == 0) 
    stepper2.moveTo(-stepper2.currentPosition());
  
  stepper1.run();
  stepper2.run();
}

Hi,

I'm a fresh beginner.
Could someone post pictures of the built circuit so I can learn how to read the diagram ?

Thanks!

sharonf
pls check the first page of this thread.

Doom, I mean a "real" picture of the arduino and the wires, not the circuit sketch

Sharonf, you can see a video of a "real" functioning 28BYJ-48 5-Volt Stepper circuit on YouTube - at Stepper driven by Arduino Mini Pro - YouTube

If you pause the video you'll be able to see the wiring. It is using an Arduino NANO

celem:
Sharonf, you can see a video of a "real" functioning 28BYJ-48 5-Volt Stepper circuit on YouTube - at Stepper driven by Arduino Mini Pro - YouTube

If you pause the video you'll be able to see the wiring. It is using an Arduino NANO

Thanks,
What is the additional board at the end of the prototype bread board?

A breadboard power supply. The stepper draws too much current to run from the USB port. The power supply was purchased over eBay and is similar to these:

Is there Anybody out there... there... there...

Yes, I am out here, and I am a newbie reading every little bit of information like a new born puppie having its first drink of milk from its mommies nipple. That is about the best way I have of describing my experience with Arduino.
I have the Arduino Uno, the 2003 driver board and the 28BYJ-48-5 motor. I have played with the Uno board and have suceeded in getting the "Blink" command to work. I have tried a previous set up to get the motor to do its thing but so far a "Fail"..
I have just received a second new motor and 2003 board, and I am about to go to my basement work area and start a new fresh approach to the problem.
My aim to have the Uno control a stepper motor to drive a dividing head for my Unimat lathe. I would like to direct you to a "YouTube" video by Chuck Fellows : Infra Red Remote Controlled Arduino Dividing Head - YouTube is what I am aiming to do.
I will be back. I just wanted you to know I was taking in all the good information.
Harvey,
in Kelowna, BC.

Maybe you could upload a picture of the wiring you did for the stepper + arduino, and the code you used?
I got it to work with some effort

I had Chuck look at the wiring. He thought I had one set of wires backwards. I have taken that set up apart and I am starting all over. I'll see how far I get tonight.

Note reference to: "Celem" December 31, 2011, 11:46:27 AM »

I have copied and pasted the code from your messgae. Thanks very much. Now, I am new, new, new,to Arduino and the "codes" ..I am using the 28BYJ-48-5VDC Gear Stepper Motor with ULN2003 Driver Board. So just to let you know why I put in three new's my first project was to download the "BLINK" code, and completed that succesfully. Now I have set up the Arduino Uno, with this little motor and driver, downloaded the code from your posting, and woopy it also works. So now Grampa has two attempts that have worked.

I sort of understand the concept of the clockwise and the C/clockwise, but I have no clue as to where to go into the code to edit it. My motor is turning at just under 1 rpm. Where do I go to adjust the speed, and direction. Thanks for your help.
Harvey
in Kelowna BC.

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.