28BYJ-48 motor back and forward not precise ?

Hi . I am working on a simple project for my son. I am using one of this motor and the code below. I want to achivie some effect very simple and move the motor between two point back and forward (need for moving one simple wooden bird :slight_smile: ) . I think should be enough to oscillate between 90 degree and 0 then from 0 to 90. The problem is that it does not completely go back to the initial point hence the motor keep slightly moving forward. Any help? The motor is broken ? :frowning: Thanks.

#include <Stepper.h>
const int stepsPerRevolution = 1048;
int revolutionVal = 200;

//Use pin 8-11 to IN1-IN4
Stepper stepperName = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {

  //Set the RPM of the stepper motor
  stepperName.setSpeed(20);
}

void loop() {
    //This should make the stepper do a full 360 degrees
    stepperName.step(revolutionVal * 1);
    delay(2000);
    stepperName.step(revolutionVal * -1);
    delay(2000);
}

Post a project schematic.

Two possible explanations: you are either commanding the stepper to step too quickly, so it is skipping steps, or not waiting until the move is complete before commanding another move.

Keep in mind that the gearbox has backlash, so forward and backward movements will not end up in the same places.

1 Like

A 28BYJ-48 stepper motor has (about) 2048 steps per rev, not 1048.
That make a 90 degrees move about 512 steps.

Top speed of that stepper motor is about 12rpm.

"revolutionValue", does that come from an unrelated 200-step motor?
Leo..

What is "this" motor? Is it a 28BYJ-48 stepper motor as suggested by @Wawa?
Maybe it's your mechanics and the motor is losing steps due to mechanical resistance. And maybe you need acceleration/deceleration to reach the set speed without loosing steps ( or you have to lower the speed )

See topic title.

Hi, @franekko
Welcome to the forum.

What are you using as a power supply for the stepper?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Can you please post some pictures of your project?
So we can see you component layout.

Is the stepper shaft connected to anything?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Thanks, obviously I need new glasses :roll_eyes:

1 Like

Very simple connection , no load connected to motor.
8=> IN1
9 => IN2
10=> IN3
11=> IN4

Hi
I posted above the connection from the arduino mega. Then 2 cable from the driver to the GND and 5V. I am using the driver ULN2003. Holding the stepper motor in my hand.
28byj48-stepper-motor-arduino-tutorial

yep with driver ULN2003

From the code above will be able to advice me how to setup the constants just to have an oscillation between two point in 0-90 degree? :frowning:

Hi update the code like this :

#include <Stepper.h>
const int stepsPerRevolution = 512 ;
int revolutionVal = 512;

//Use pin 8-11 to IN1-IN4
Stepper stepperName = Stepper(stepsPerRevolution, 8, 10, 9, 11);

void setup() {

  //Set the RPM of the stepper motor
  stepperName.setSpeed(20);
}

void loop() {
    //This should make the stepper do a full 360 degrees
    stepperName.step(revolutionVal * 1);
    delay(2000);
    stepperName.step(revolutionVal * -1);
    delay(2000);
}

it does 90 degree I assume one side but then it should come back it only vibrates.

No, because it will take some experimentation, and I don't have your setup.

Reduce the motor speed and change step numbers and delay timing until you get what you want.

@Wawa told you everything already in #5, but obviously you ignored it.

No I did not , I did adjust and I got what I described in post 14.

But you didn't use the numbers I told you to use.
Leo..

Change the numbers.

Bad connection due to arduino board, solved. Is it possible to set the motor in a specific initial position before starting the actual loop ? Thank you.

It would be nice to upload the sketch with the right numbers first.
Now it seems you're ignoring us.

A stepper motor doesn't know where it is on start-up.
You can use an end-switch and a homing sequence in setup().
Leo..