Stepper motor not turning counterclockwise

My stepper motor is not turning counterclockwise. When it tries to turn it just goes on in one direction.

Here is my code:

#include <Stepper.h>
int stepsPerRevolution=2048;
int stepsPerRevolution2=-2048;
int motSpeed=10;
int dt=500;

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

void setup() {
  // put your setup code here, to run once:
Serial.begin (9600);
myStepper.setSpeed (motSpeed);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println ("clockwise");
myStepper.step (stepsPerRevolution);
delay (dt);
Serial.println ("counterclockwise");
myStepper.step (stepsPerRevolution2/2);
delay (dt);


}

}

Try using the stepper library correctly, and change the direction of rotation instead.

myStepper.step (-stepsPerRevolution);

changed still not working

Sorry, I was thinking of a different stepper library. That should have worked, so check the motor wiring for continuity. Perhaps one coil is not properly connected, or the wire order is not correct. On those motors, the wire colors vary between manufacturers.

1 Like

I have connected it correctly, it may be a problem due to voltage cause I used the 5v pin of R3 or could be something else.

How do you know?

All the pins are connected correctly like pin IN1 to pin 8, IN2 to 9, IN3 to 10 and IN4 to 11.

Does the ULN2003 have soldered pins (or sockets) or are the wire pins (or sockets) just placed in a hole?

As in ??

@1_jaivardhan
Do the LEDs on the driver board blink when it tries to go backwards?

That may not be correct. See this whole thread:

If the problem is that the coils are crossed, perhaps swapping the middle two wires in code would uncross them:

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

Try your code in this simulation if you don't want to risk your hardware:

1 Like

This could be it. The 5V pin on the Arduino is not meant for high currents, so your stepper motor might not be getting enough power.

Then it would not move forward either.

True, though it could still be a problem, even if it's not the specific problem here.

If it moves forwards OK I don't see how you could still consider it to be a problem.

That's not correct. You must swap pin 9 and 10. Either in HW or in this line:

2 Likes

Try:

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

2 Likes

Yes they blink

Yeah I will try.

Thanks

1 Like