how to get Stepper to reverse

HI,
I am trying to get my stepper motor to run forward and backward.
I am using the the stepper library in Arduino.
but when I give the stepper a -ve value it still runs forward.
I am using an H-bridge and have tried all combination to wire my 4 wire 9V stepper motor.
Any suggestions…


#include <Stepper.h>

// with stepper J835S: from h-bridge 1-out = orange, 2 = blue, 3 = yellow, 4 = purple

// change this to the number of steps on your motor
#define STEPS 96

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it’s
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

int ledPin = 13;
void setup()
{
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}

void loop()
{

// move a number of steps forward

stepper.step(2STEPS);
blink(1);
delay(500);
// move a number of steps backward
stepper.step(-2
STEPS);
blink(2);
delay(500);
}

// Blink the reset LED:
void blink(int howManyTimes) {
int i;
for (i=0; i< howManyTimes; i++) {
digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}
}

I'm still very new and tryinf to get used to reading C, but it looks like to me that i would try changing this code you have:

Stepper stepper(STEPS, 8, 9, 10, 11);

Change the order for reverse to

Stepper stepper(STEPS, 11, 10, 9, 8);

Hi SteveB inCO I want the shaft to move in both the direction. According to the Stepper Library you should be able to turn the stepper in both the direction by giving it a +ve or a -ve value. But in my code when stepper.steps(some -ve value); it runs in the same forward direction.

Basically a stepper motor has two coils in it and by changing the polarity you can make the shaft turn in either direction which you can control by a microcontroller. Changing the order does not solve the problem.

I just looked at the Stepper Library and I think you need a setSpeed(rpms) line then if you put the -in the RPM you should get it to reverse.

I was just looking at the library again. I think I was was wrong about the setRPM before and think you are on the right track. The following was in the library.

Turns the motor a specific number of steps, at a speed determined by the most recent call to setSpeed(). This function is blocking; that is, it will wait until the motor has finished moving to pass control to the next line in your sketch. For example, if you set the speed to, say, 1 RPM and called step(100) on a 100-step motor, this function would take a full minute to run. For better control, keep the speed high and only go a few steps with each call to step().

So maybe increase your delay between forward and reverse. I probably haven't helped much but try that once. If that doesn't work I don't know. But now you have got me wondering and I will get a stepper and see if I can get it to work.

I changed the motor and it works fine now. May be there was something wrong with the motor