Stepper Motor 28BYJ

I have built a custom project in which I need a stepper motor to go 11 times forward with specific steps and come back to its original position so on.
With builtin Stepper.h library which is working but lagging in number of steps, I would like to know what is wrong
I explored the Accelstepper library but could not make it as I am not very good at programing skills
Can anyone help me write the code in Accelstepper library? or find the solution?
I forgot to write I have included a limit switch also to reset the loop

My code is as follows...

#include <Stepper.h>
#include <ezButton.h>
Stepper stepper1(2048, 2, 4, 3, 5);
ezButton button1(6);
void setup() {
  Serial.begin(9600);
  stepper1.setSpeed(15);
}
void loop() {
  button1.loop();
  int btn1State = button1.getState();
  Serial.print("Button 1 State = ");
  Serial.println(btn1State);

if (btn1State == 1){
  for (int i = 0; i <= 10; i++) {
    stepper1.step(675);
    delay(500);
  }

  stepper1.step(-7000);
}
}

What is your exakt problem? Did you try with slower speed? Which board are you using?
If you go 11x675 steps in one direction these are 7425 steps. Going back 7000 steps will not reach your starting point.

Thanks for quick reply.
I am using Arduino Uno Board with pc USB supply
and motor is running with external 5 volt supply
The program was running OK but sometimes motor doesn't looks like taking load in forward steps
Thats why I was thinking about Accelstepper Library but can not program it properly
Motor is 28BYJ-48 5Volt
about the value 7425 I had calculated that before and tried it but it was banging the limit switch so I put 7000 to try it
now as it does not take forward 11 steps properly every time it lags behind after some loops
Please help

Thanks once again

Did you try with lower speed? This motor isn't very strong, and if it cannot keep up with the lood at lower speed, acceleration or deceleration will not help.

These stepper motors do not do 2048 steps per revolution, more like 2038. See this blog post https://arduinoplusplus.wordpress.com/2021/10/09/28byj-stepper-motor-limits-testing/.

In your code you are advancing 10*675 steps (6750) and then returning 7000 steps. This will not come back to the same place.

There are also limits to how fast they will run without acceleration (as per MicroBahner suggestion) and you may be exceeding that which causes the motor to stall, causing a miscount.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.