Why isn't my stepper going counterclockwise???

I am trying to make a curtain open and close with a stepper motor rotating the curtain handle. When I press a button and pin 2 gets the input, the stepper will rotate and a boolean will switch whether the curtain is open or closed. Everything thing works fine except the motor will not turn counterclockwise. I dont know why this wont happen and I cant figure out how to get it to work. Can anyone help me with this?

I’m using a stepper motor with a ULN2003 Stepper Motor Driver board.
in 1 → pin8
in 2 → pin9
in 3 → pin10
in 4 → pin11

  • → 5v on arduino
  • → gnd on arduino
#include <Stepper.h>

int stepsPerRevolution = 500;  // change this to fit the number of steps per revolution
// for your motor


// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);



int timeForRotation = 10;
int timeDecrease = 1;

int button = 2;

boolean canPressButton = true;
boolean curtainOpen = true;

void setup() {

 pinMode(button, INPUT);
 myStepper.setSpeed(25);
 Serial.begin(9600);
}

void loop() {
 if(canPressButton == true){
   if(digitalRead (button) == HIGH)
   {
     timeForRotation = 10;
     curtainOpen = !curtainOpen;
     canPressButton = false;
     Serial.println(curtainOpen);
     delay(50);
   }else{
       digitalWrite(button, LOW);
 
    }
 }else{
       digitalWrite(button, LOW);
 
    }

if(timeForRotation <= 0)
{
 delay(500);
 canPressButton = true;
}
 
if(curtainOpen == true){
  while(timeForRotation > 0){
    digitalWrite(button, LOW);
    timeForRotation -= timeDecrease;  
    Serial.println("clockwise");
    myStepper.step(-stepsPerRevolution);
   }
}

if(curtainOpen == false){
  stepsPerRevolution = -500;
  while(timeForRotation > 0){
    digitalWrite(button, LOW);
    timeForRotation -= timeDecrease;
    Serial.println("countercouclockwise");  
    myStepper.step(stepsPerRevolution);
   }
}
}

FPSworrior:
I am trying to make a curtain open and close with a stepper motor rotating the curtain handle. When I press a button and pin 2 gets the input, the stepper will rotate and a boolean will switch whether the curtain is open or closed. Everything thing works fine except the motor will not turn counterclockwise.

Have you written a short program that does nothing except move the servo one revolution clockwise followed by one revolution counter-clockwise?

If not, that should be your first step.

...R

I used the (Stepper/OneRevolution) example sketch in the arduino app and it seems to be going only clockwise. I'm using the ULN2003 stepper motor driving a regular stepper motor and it wont go counterclockwise, dont know what the problem might be, maybe the driver? Or do I just get a new one? thanks for the help.

Always use code tags when posting code ("</>" button). Please edit your first post to add them, and post a hand drawn (not Fritzing) wiring diagram.

What is writing to a button supposed to accomplish?

digitalWrite(button, LOW);

You should avoid using delay(). See the “blink without delay” example that comes with the Arduino software.

FPSworrior:
I used the (Stepper/OneRevolution) example sketch in the arduino app and it seems to be going only clockwise.

Post the program that you have uploaded to your Arduino.

...R

I suspect something to do with one of these statements and a minus sign.

int stepsPerRevolution = 500;  // change this to fit the number of steps per revolution
...
    myStepper.step(-stepsPerRevolution);
...
  stepsPerRevolution = -500;
...
    myStepper.step(stepsPerRevolution);

I suspect something to do with one of these statements and a minus sign.

One of the beauties of Arduino is that you can change things, and in a few seconds, observe the effect! Do we need to tell you to remove the minus signs?

Do you have a 500 step/revolution motor? That would be unusual.

Is your motor a unipolar or bipolar, the ULN2003 is for unipolars, won't work with bipolars. How many wires on the motor? The Arduino stepper library is for bipolars and is finicky with unipolars like 28BYJ-48 but can be made to work (sometimes) by swapping wires around until you find a combo that works.