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);
}
}
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.
//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);
}
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..