Stepper won't rotate counter clock wise

I am making a program to turn a stepper motor if a button is pressed or a 4 digit code has been entered.

I can get the motor to rotate clock wise, but not counter clock wise.

apparently negative number is not working?? or my code is wrong.

My program is not finished yet.

thanks in advance!

#include <Keypad.h>
#include <Stepper.h>

const int stepsPerRev = 8; // Number of steps in 1 revolution.

const byte ROWS = 4;       // set display to 4 rows.
const byte COLS = 3;       // ste display to 3 columns.
char keys[ROWS][COLS] =
{ {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};

Keypad keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
Stepper myStepper(stepsPerRev, A0, A1, A2, A3);

const int Lock = 11;            // pushbutton 1, to unlock.
const int Unlock = 12;            // pushbutton 2, to lock.
const int ledPin = 13;

char Str1[] = {"123"};



void setup() {
  pinMode(Lock, INPUT);
  pinMode(Unlock, INPUT);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {


  char key = keypad.getKey();

  myStepper.setSpeed(500);

  if (digitalRead(Lock) == HIGH) {
    Serial.println("LOCKED");
    myStepper.step(130);
    delay(500);
  }

  else if (digitalRead(Unlock) == HIGH) {
    Serial.println("UNLOCKED");
    myStepper.step(-130);
    delay(500);
  }
  else if (key) {
    if (key) {
      Serial.print(key);
      // Serial.print("Correct");
      Serial.println();
    }
    else {
      Serial.print("Wrong");
      Serial.println();
    }
  }
}

I can tell you that some steppers, such as the 28BYJ-48, have to be wired differently. Instead of a 1-2-3-4 pattern, they use a 1-3-2-4 pattern. So, maybe try switching your middle 2 pins.

myStepper.setSpeed(500);

Start with something sane, like 50, and work your way up. :)

This works for me, steps per rev = 512, speed, start with 20.

edgemoron: myStepper.setSpeed(500);

Start with something sane, like 50, and work your way up. :)

500 is sane for the 28BYJ-48 (which is 2000 steps per rev approx), not not for NEMA style motors which are usually 200 steps-per-rev. If in doubt use a low step rate to prevent stalls.

thanks for the help! switching pin 2 and 3 worked!