Moving stepper motor ant-clockwise

Hi,

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

Thanks.

A 28BYJ-48 needs 2048 steps for a revolution

Are you sure you have the wiring correct between the Arduino and the ULN2003

If you put a 2 second delay between moves it will make the behaviour easier to observe.

...R

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.

I have the "standard" one. I tried it with 5 and the same thing happened, just slower.

This works with mine, notice the different pin numbers, set RPM to 4.

Stepper myStepper(2048, 8, 10, 9, 11);

Thanks! It worked

Good! A Karma point for responding, have fun.

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).