28BYJ-48 Stepper - run backwards?

Using the 28BYJ-48 stepper motor, using stepper.h library in IDE 1.8.0 I can only get forward (CW) rotation. See photo attached. The sketch comes direct from Examples>Stepper>Stepper_oneRevolution, on pins 6,7,8,9 so no need to repeat it here.

Then I went to this forum and saw that other experimenters have had the same problem with CCW rotation. I don't understand if this is a unique problem to this stepper, or if other steppers exhibit similar issues. Seems like the basic code is simple, however the library does not provide proper control.

One of the threads suggested using AccelStepper.h, so I downloaded that along with this suggested sketch. Although I see nothing suggesting CCW operation.

#include <AccelStepper.h>

// Define some steppers and the pins they will use
AccelStepper stepper1(5, 6, 7, 8, 9);
// The first argument '5' indicates that we're using a 28byj-48 geared motor. The rest is just pin numbers.
//You can still use all the other types of motors supported by accelstepper library (e.g. 4 for a normal 4 wire step motor, 8 for a halfstepped normal 4 wire motor etc.)
AccelStepper stepper2(5, 6, 7, 8, 9);

void setup() {
stepper1.setMaxSpeed(900.0); //max speed of the first motor - modify if you want to
stepper1.setAcceleration(700.0); // rate at which the first motor accelerate -

stepper2.setMaxSpeed(700.0);
stepper2.setAcceleration(400.0);
}

void loop() {

if (stepper1.distanceToGo() == 0){
stepper1.moveTo(random(1500,7000));//just an easy way to get the motors to move to random positions
}
if (stepper2.distanceToGo() == 0){
stepper2.moveTo(random(1500,7000));
}
stepper1.run();
stepper2.run();
}

No stepper movement at all. I've tried changing the speed and acceleration with no effect. So, now I am at a loss of what to try next. It doesn't seem that this should be difficult. Does anyone have an easy, surefire fix? Thanks in advance.

Hi,
See THIS PAGE for code example that we know works both directions.

Also look carefully about the CONNECTIONS shown there. I suspect you do not have the 4 wires in the correct (non-obvious) sequence.

Thanks for your input, I'll look at that link and get back to this thread. Sorry, my photo did no load on the orig post...too large they say. Here it is and I saw the warning about the wires. I think I've got it correct.
John

Terry,
That was easy...works perfect! Thank you. Still a bit confused about this stepper and # steps per 360 degrees...values from 32 to 4048. But it works and I can adjust the Steps_Per_Motor_Revolution and Speed to suit my needs now. I kept with your 8,9,10,11 pin location. (my photo used 6,7,8,9 pins because I had an LCD already connected to 12, 11, 5, 4, 3, 2 to give me loop messages.)
John

Further to my post of the same subject today. Many thanks to Terry King 'terry@yourduino.com' for the CW/CCW sketch...it worked great CW & CCW then I left it alone for a while and came back to it later and the stepper would only move CW. My indicators showed the sketch loop was performing the CW and CCW OK. Please see attached photo with setup including an lcd to indicate L/R movement. IDE 1.8.0 and sketch below. I made sure the wires are 6=1, 7=2, 8=3, 9=4 for the stepper with same in the sketch definition. I was quite happy with the progress and looking forward to my next step...so, now disappointed.

My thoughts:

  1. did something happen to the IC on the 2003 board?
  2. is the 28BYJ-48 is low-end piece of junk?
  3. if #2 is yes, can anyone suggest a good stepper model?
  4. arduino compiles and uploads A-OK for lcd and serial operation.

/* YourDuino.com Example Software Sketch
Small Stepper Motor and Driver V1.4 11/30/2013
http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126
Steps one revolution of output shaft, then back
terry@yourduino.com */

/-----( Import needed libraries )-----/
#include <Stepper.h>

/-----( Declare Constants, Pin Numbers )-----/
//---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
#define STEPS_PER_MOTOR_REVOLUTION 32

//---( Steps per OUTPUT SHAFT of gear reduction )---
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048

/-----( Declare objects )-----/
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to

//The pin connections need to be 4 pins connected
// to Motor Driver In1, In2, In3, In4 and then the pins entered
// here in the sequence 1-3-2-4 for proper sequencing
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 6, 7, 8, 9);

/-----( Declare Variables )-----/
int Steps2Take;

#include <LiquidCrystal.h> // call up the lcd library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() /----( SETUP: RUNS ONCE )----/
{
// initialize the serial port:
Serial.begin(9600);
lcd.begin(16,2);
// Stepper Library sets pins as outputs
}/--(end setup )---/

void loop() /----( LOOP: RUNS CONSTANTLY )----/
{
Serial.println("SWEEPING RIGHT");
Serial.println(""); // give a line space
lcd.clear();
lcd.print("Sweep Right");
Steps2Take = STEPS_PER_OUTPUT_REVOLUTION/2; // Rotate CW 1 turn
small_stepper.setSpeed(500);
small_stepper.step(Steps2Take);
delay(1000);

Serial.println("SWEEPING LEFT");
Serial.println(""); //give a line space
lcd.clear();
lcd.print("Sweep Left");
Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION/2; // Rotate CCW 1 turn
small_stepper.setSpeed(500); // 700 a good max speed??
small_stepper.step(Steps2Take);
delay(2000);

}/* --(end main loop )-- */

/* ( THE END ) */

Why are you double posting ?

http://forum.arduino.cc/index.php?topic=447127.0

Ask a moderator to merge your two threads.

because it is a DIFFERENT issue.

1st post requesting help in obtaining a sketch that would provide CW & CCW stepper movement.
2nd post stating that I may be having mechanical and/or electronic issues.

NOT double.