28byj-48 stepper motor

I have a 28BYJ-48 stepper motor. I tried to rotate it both clock wise and anticlock wise but it only rotate on clock wise. Even if the condition is false it only rotate on clock wise. I used to search youtube but none of any videos are useful. I don't know is it faulty or good. I used ULN2003 motor driver to operate the motor.
I attached the code and image.
First I used 200 steps per revolution it works.
Then I used 2048 steps per revolution it didn't work. I used Arduino Uno digital pins 9,10,11,12 but the result same. Now I'm using 2,3,4,5 it rotate same as before on clock wise.

#include <Stepper.h>

const int stepsPerRevolution = 200;  

Stepper myStepper(stepsPerRevolution, 2, 3, 4, 5);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(15);
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one revolution  in one direction:
  int a=10;
  if(a==11)
  {
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(50);
  }
  else
  {
  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(50);
  }
}


  • Do not use your Arduino to power a motor, use an external power supply.
  • Say what ?

Try 2048 steps per revolution and:

myStepper.setSpeed(2500);

myStepper.setSpeed(5);

Are these the pins corresponding to IN1, IN2, IN3, IN4?
Did you try myStepper.setspeed() for RPM speed?

Try this - it is your sketch with setspeed:

#include <Stepper.h>
int stepperrev = 2048;

Stepper myStepper(stepperrev, 2, 4, 3, 5); // IN1, IN3, IN2, IN4

void setup() {
  Serial.begin(115200);
}

void loop() {
  myStepper.setSpeed(18); // RPM
  myStepper.step(stepperrev); // forward
  Serial.println(stepperrev);
  myStepper.setSpeed(1); // RPM - look at the pretty lights
  myStepper.step(-stepperrev); // reverse
  Serial.println(-stepperrev);
}

myStepper.setSpeed ( 5 );

1 Like

I already tried it but it only vibrating not rotating

No it only rotate on clock wise

#include <Stepper.h>
int stepperrev = 2048;

Stepper myStepper(stepperrev, 2, 4, 3, 5); // IN1, IN3, IN2, IN4

void setup() {
  Serial.begin(115200);
}

void loop() {
  //myStepper.setSpeed(18); // RPM
 // myStepper.step(stepperrev); // forward
  //Serial.println(stepperrev);
  myStepper.setSpeed(1); // RPM - look at the pretty lights
  myStepper.step(-stepperrev); // reverse
  Serial.println(-stepperrev);
}

I changed the clock wise rotating line to comment line but it still rotate on clock wise

I used to test by using if condition if a equal to a it will execute if block of statement otherwise it will execute else block of statement. The condition execute correctly but stepper motor rotate on clock wise.

You need to match the wiring:

//2 to IN1
//3 to IN2
//4 to IN3
//5 to IN4
//28BYJ-48

#include <Stepper.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution
// for your motor

//2 to IN1
//3 to IN2
//4 to IN3
//5 to IN4

Stepper myStepper(stepsPerRevolution, 2, 4, 3, 5);

void setup()
{
  myStepper.setSpeed(5);
  // initialize the serial port:
  Serial.begin(115200);
}

void loop()
{
  // step one revolution  in one direction:
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);

  // step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
}
1 Like

How? I already match it correctly as you mentioned.

  • Show us several good images of your wiring.

Ok here





  • The motor needs an external 5v power supply with a common GND to the Arduino.

BTW, do you know you can remove the protection paper form the plastic covers ?

The example code for stepper.h uses (stepsPerRevolution,8,9,10,11), which is wrong for some (most) motors. Changing that to (8, 10, 9, 11) should have fixed this.

You can do the same (swapping the two middle numbers) with another series of pins.

That stepper motor has 2048 steps/rev and a max speed of about 12RPM.
But it could work with the wrong numbers.
Leo..

I already tried it to many times sir

I don't know thanks for your help

  • The sketch in post #10 works CW and CCW here.

  • Use an external 5v power supply with a common GND to the Arduino.