I am using a 28byj-48 stepper motor with a ULN-2003 motor driver with my Arduino Uno. I wanted it to move clockwise and then anticlockwise. The following is the code:
#include <Stepper.h>
// change this to fit the number of steps per revolution
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(512, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(30);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(512);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-512);
delay(500);
}
It moves clockwise but doesn't move anticlockwise for some reason and any help here would be appreciated
I wanted to do half a revolution/quarter revolution. Also yes, the connections are correct. I referred to multiple tutorials and they all showed the same
If that's a "standard" 28BYJ-48, it wont run 30 RPM, about 12 is screaming wide open without missing steps, try a sane value like 5 or 6 to start.
EDIT: If you have one of the weird types that Adafruit sells, it does about 513 steps per rev and will go about 33 to 35 RPM.
There are 24 ways to wire a unipolar stepper and 8 of them work, 16 don't, and its hard to determine the
actual order of the coils other than by trial and error unless you know the wire colour scheme for sure
(this is highly variable and there's no real standard).