28BYJ-48 5-Volt Stepper

Hello everyone,

First please excuse my English because I'm french.

I read the whole topic and above all I try to understand but it's a bit hard for someone who has never programmed in Arduino.

I'll try to explain why I found myself on this forum among you today. For the story, I am an amateur astronomer and I make pictures with my telescope.
To create my images I use a camera equipped with a manual filter wheel. I run a disc with the finger which places the desired color filter on camera.

So I bought a 28BYJ-48 5V stepper motor, a ULN2003 driver and a controller Arduino Nano to automate the placement of the desired filter in front of the camera.

Here is a video that shows the operation of what I want

Would require that the system be able to position itself in the right place when I indicate it a value of 1 to 5 which corresponds to the position of each color filter. Of course it must be perfectly reproducible positioning.
The control will be by a driver Ascom developed in Visual Basic.

I seek someone who can create the sketch and give me the links to the different libraries to use with.

I am aware that it is easy to register on a forum and come ask for a solution but in the present state of things I do not have the necessary capacity to realize this project.
Whether to give financial compensation via paypal to whoever will help me I'm open to suggestions.

Thank's a lot

best regards

Mathieu

Hi, anyone know how many (in cm) does 1 rotation of 28BYJ-48 do? If you were to do it manually. Thanks

Hello,

I'm new on this forum, need some help please.
I'm going to run an astronomical barn door tracker with Arduino nano.
I wrote a sketch, it works so far but I'm not really satisfied with it.
The basic idea is the following:
if powered up, it has to run down (CCW) in parking position. After pushing lower limit switch it has to wait for the START button. If start pressed, it has to turn CW very slow (as it has to follow Earth's turn) until upper limit switch pushed. If pushed, a blinking LED alerts to finish long time exposure.
There is a finetuning included to set +/- the CW speed (it has to be set up while taking long expo photos not to see lines instead of stars due to wrong speed). Speed is saved in Arduino's EEPROM.

My problems:
torque is not enough CW
with this code CCW movement is not fast enough, have to wait too long for reaching parking position

Could somenone help me correcting my code? Thanks a lot! Regards: F. Hollay
(frigyes hollay hu bosch com)

#include <Stepper.h>
#include <EEPROM.h>

const int stepsPerRevolution = 200;
const int buttonPin_UP=5;
int button_state_UP;
const int buttonPin_DOWN=4;
const int buttonPin_START=6;
const int buttonFAST=2;
const int buttonSLOW=3;
int button_state_DOWN;
int ledPin = 13;
int I;
float Sp;

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution,8,10,11,9);

void setup() {
pinMode(buttonPin_UP,INPUT_PULLUP);
pinMode(buttonPin_DOWN,INPUT_PULLUP);
pinMode(ledPin, OUTPUT_PULLUP);
pinMode(buttonFAST,INPUT_PULLUP);
pinMode(buttonSLOW,INPUT_PULLUP);
int I=0;

Sp=EEPROM.get(0,Sp);          // read previously stored speed value
myStepper.setSpeed(Sp);
}

void loop() {
digitalWrite(buttonPin_UP, HIGH);     
digitalWrite(buttonPin_DOWN, HIGH); 
digitalWrite(buttonPin_START, HIGH);  
digitalWrite(buttonSLOW, HIGH);      
digitalWrite(buttonFAST, HIGH);    

while (digitalRead(buttonPin_DOWN) == HIGH){              //rotating in parking position until lower limit switch pushed

myStepper.setSpeed(150);
myStepper.step(-stepsPerRevolution);}



while (digitalRead(buttonPin_START) == HIGH) {          // waiting for the start button being pushed

  }

while (digitalRead(buttonPin_UP) == HIGH){            // running (opening) barn door untill upper limit switch gets pushed

 
  if (digitalRead(buttonFAST) == LOW)                // change speed: increase with 0,1 RPM

    {
      Sp = Sp+0.1; 
     delay(250); // waiting little bit...  
    }          

  if (digitalRead(buttonSLOW) == LOW)                 // change speed: decrease with 0,1 RPM
    {
     Sp = Sp-0.1;
     delay(250); // waiting little bit...  
    }            
 
myStepper.setSpeed(Sp);     //normal run
myStepper.step(stepsPerRevolution);}
delay(250);

for (int I=0; I <= 5; I++){                        // if upper position reached, blinking warn signal 5 times before running back to parking position
    digitalWrite(ledPin, HIGH);   // sets the LED on
    delay(500);                  // waits for a second
    digitalWrite(ledPin, LOW);    // sets the LED off
    delay(500);
   } 

EEPROM.put(0,Sp);                              // writing value of speed variable into EEPROM in order to remember speed fine settings
delay(10); 
}

Hollay, can you edit your post and put your code inside [ c o d e ] [ / c o d e ] tags, it makes it so much easier to read !

Shure, thanks for hint.
Regards: Frigyes

@Hollay,

pls give us a bit more details about:

  • your stepper motor (the same as headline says? I ask because the thread was started in 2011 ..)
  • your stepper driver
  • your power supply

If you are talking about having too less torque CW - it might depend on the speed.
There is a dependency between speed and torque.

As you are running CCW a bit faster than CW (you say, not fast enough - that may indicate driver/power supply/voltage issue) it seems that the motor at CCW speed has enough torque (or at least more than CW at low speed).

If you are operating your motor in a speed range, where torque is low, mightbe you need a gear reduction, so that the motor can run faster, but the resulting movement is still slow enough for your project.

Hi,
thanks for reply&help.

The motor is the same as in the headline. The driver board is a ULN2003 based tiny board (with 4 red leds), got in bundle from dx.com.
The power supply is a 240V AC/12V DC at 2A with stabilizer 7809 for the Nano and 7805 for the motor driver board. I guess it should be enough.

There should be 2 different speed values for the 2 directions.
The project has to have enough torque in the slow motion phase to run smooth with a camera on it and fast enough if parking back after exposure.
The motor is connected with a belt drive to the curved rod in order to avoid backlash btw. gears. The gear on the rod has to turn exactly with 1 RPM.
Just for information how a barn door tracker is looking like, here's an example (not mine): LINK
Thanks and regards:
Frigyes

I am not familiar with your combination of driver and stepper.
What I found in the Internet, and if this information applies to your hardware:
Your motor needs 64 steps to make one 360 degree turn.

The integrated gear has a ration of 64:1, means that you have to send 64 * 64 = 4096 steps to have one full revolution. (Actually: 4076, see link below).

Compare that with your code:

const int stepsPerRevolution = 200;

So exchange the 200 with 4076 and test again.

Read the details in this link.

Hmm, that sounds right.
I will test it on the weekend.
Thanks: Frigyes

pls don't forget to leave a feedback here; EVEN when it works :slight_smile:
Disclosing a successful way to solve a problem will help to avoid repeating same kind of questions all over again and such waste precious free time on already solved issues.

Well, for the first look it seems to be worse. :frowning:
I've set the value for 4076, but same time had to decrease speed (value: Sp). Now the torque is good at the minimum speed (1), but there's no more fine adjustment for speed as it seems not to take floating values (like Sp=0.9), only 1-7 as integer. I don't really understand why.
I've started a trial&error.
E.g. if I set the value for 1024, I have a speed range 1-25, which is way better in sense of fine tuning. Torque at Sp=1 seems to be OK, although highest speed is still not fast enough. If I set it higher, the motor makes only a high freq noise but not a single turn. :confused:
I'm afraid the stepper library couldn't give me more...

As I have no such motors I cannot give it a try myself. Maybe somebody else here has the same configuration available and could give you a helping hand.
Alternative: look at another motor / driver combination which is in the range what you are looking for.

Ask again for help.
Using still the here already attached code I tried to change the small 28BYJ-48 on another unipolar stepper in order to get more torque. The config is the same: a Nano board with ULN2003 driver.

Tried e.g. a 42BYJ-07 (Syntha motor from a HEQ5 telescope mount) geared motor (as this is a 12V stepper, the ULN board gets 12V now).

The stepper is only vibrating, no matter in which sequence the coils are powered. Took an old unipolar motor from a 5,25" FD drive, same vibration W/o a single turn.

Tried another codes, not only stepper.h library but accelstepper too, same result.

What do I wrong? :frowning:

Thanks for any answer.

Hi.

If you need more torque, you need more current.
Is your driver able to supply the current the motors need ?

Do you have some specifications about those motors of yours ?

Hi,

I don't have any specs for those motors, sorry.
However torque is one issue in case of the 28BYJ, as it is just a tiny stepper. But my bigger problem is that the other steppers, like the 42BYJ-07 doesn't even make a single turn, just jumping a coil forward and another back (seems at least), that's I've written "vibrating". As if I would try to use it with a wrong coil sequence in the code. But tried all variations, no success.

If some current limiter kicks in, you might see a similar behaviour.

If you do not know the stall current, it's unlikely you will get it working correctly.

Try measuring voltages and currents, while you have some very slow stepping going on.

Hollay:
I'm going to run an astronomical barn door tracker with Arduino nano.
I wrote a sketch, it works so far but I'm not really satisfied with it.
The basic idea is the following:
if powered up, it has to run down (CCW) in parking position. After pushing lower limit switch it has to wait for the START button. If start pressed, it has to turn CW very slow (as it has to follow Earth's turn) until upper limit switch pushed. If pushed, a blinking LED alerts to finish long time exposure.
There is a finetuning included to set +/- the CW speed (it has to be set up while taking long expo photos not to see lines instead of stars due to wrong speed). Speed is saved in Arduino's EEPROM.

Hi Hollay,

I happen to be on a similar issue with these little steppers. I tried SmallSteppers ans AccelSteppers as well, but both didnt really fit my needs.

The following simple example uses Timer1 with two steppers. Within the timed routine it will run the steppers to the position given by steps_X/Y_goto.

#include <TimerOne.h>

  byte stepper_sequence_clw[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};
  byte stepper_sequence_ccw[8] = {B00001, B00011, B00010, B00110, B00100, B01100, B01000, B01001};
  byte stepperX_spos,stepperY_spos,steps_X_step,steps_Y_step;
 
  byte stepperX_pins[4]={2,3,4,5}; //Stepper X digital pins D2...D5 blue pink yellow orange, ULN2003 1-4
  byte stepperY_pins[4]={6,7,8,9}; //Stepper Y digital pins D6...D9
  
  
  byte stepperX_delay = 0; //X stepper max speed
  byte stepperY_delay = 6; //Y stepper slow but with more torque
  
  long int steps_X_goto = 0;
  long int steps_Y_goto = 0;
  long int steps_X_pos = 0;
  long int steps_Y_pos = 0;

void setup(void) {

  for(int i=0;i<4;i++) pinMode(stepperX_pins[i],OUTPUT);
  for(int i=0;i<4;i++) pinMode(stepperY_pins[i],OUTPUT);
  stepperX_spos=0;
  stepperY_spos=0;
  steps_X_step=0;
  steps_Y_step=0;

  Timer1.initialize(1250) ; //max speed / lowest torque for 28BYJ

  Timer1.attachInterrupt(run_steppers);
  
}

void run_steppers(void){

    doSteps();
    //doBlinkLed or whatever
         
 }


void doSteps(){ //Do not use delay here as well as in the called funcs

    //having an endswitch it might be read here
    //if set, either let goto = pos or set goto = pos = 0
  
     if(steps_X_goto > steps_X_pos) doStepX(1,1);
     if(steps_X_goto < steps_X_pos) doStepX(1,0);  
  
    
     if(steps_Y_goto > steps_Y_pos) doStepY(1,1);
     if(steps_Y_goto < steps_Y_pos) doStepY(1,0);
  
       
  }

void doStepX(byte s_step, byte s_direction){
  if(!s_step) return;
  if(++steps_X_step < stepperX_delay) return;
  
  if(s_direction){
    if(++stepperX_spos>7) stepperX_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperX_pins[i],bitRead(stepper_sequence_ccw[stepperX_spos],i));
    steps_X_pos++;   
    } else {
    if(++stepperX_spos>7) stepperX_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperX_pins[i],bitRead(stepper_sequence_clw[stepperX_spos],i));
    steps_X_pos--;
    }
  steps_X_step = 0; 
    
  }

void doStepY(byte s_step, byte s_direction){
  if(!s_step) return;
  if(++steps_Y_step < stepperY_delay) return;
  
  if(s_direction){
    if(++stepperY_spos>7) stepperY_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperY_pins[i],bitRead(stepper_sequence_ccw[stepperY_spos],i));
    steps_Y_pos++;
    
    } else {
    if(++stepperY_spos>7) stepperY_spos=0;
    for(byte i=0;i<4;i++)
      digitalWrite(stepperY_pins[i],bitRead(stepper_sequence_clw[stepperY_spos],i));
    steps_Y_pos--;
    }
 steps_Y_step=0;   
  }


 void loop(void) { //main loop, do non time critical things here


//set the steps to go

steps_X_goto = 4076;   //go 1 revolution clockwise
steps_Y_goto = -4076; //and 1 rev counterclockwise


delay(1); //always have a little bit of delay in here 
}

The timed function is called every 1250us, resulting to 8k steps per second or 1kHz per cycle ("wave"). In my experiments this gives the stepper a quite decent turn rate leaving at least some torque. For more torque stepperX/Y_delay can be set as plain divider, using a delay of 10 will set the stepper to 100Hz as rated in its specs - which is really slow but should deliver the steppers max torque.

Beneath the timer interrupt and thus no need of using delay() in stepper control this example uses two different wave "signatures" for running back and forth to pick up the exact step in sequence instead of running the whole cycle before changing direction.

Happy experimenting!

Regards, k4rma

Does anyone know if the 28BYJ could be made to spin at 100RPM+? Or could one of its brothers/cousins go that fast?

Thanks

The darlington diagram has 2 of the diodes reversed .