Stepper motor not reversing

Hi, I’m trying to make the stepper motor 28BYJ-48 to rotate first then rotate reversely. But it’s not working. I changed a new motor but it’s still not working. According to the codes given in libraries, positive number inside the function step() makes motor turns left while negative turns right.

Why my code is not working? Is there any other way to control the motor?

Thank you so much for any information.

#include <Stepper.h>

int stpPin1 = 8;
int stpPin2 = 9;
int stpPin3 = 10;
int stpPin4 = 11;
int buttonPin = 2;
double angle = -30; 


//the number of steps of the motor and the pins it's
// attached to
Stepper motor(50, stpPin1,stpPin2,stpPin3,stpPin4);


void setup()
{
  pinMode(stpPin1, OUTPUT);  
  pinMode(stpPin1, OUTPUT);  
  pinMode(stpPin1, OUTPUT);  
  pinMode(stpPin1, OUTPUT);  
  pinMode(buttonPin, INPUT);
  
  motor.setSpeed(80);//speed(RPMs) of moving steps
}

void rotate(int deg){
  deg = deg*550/90; //make the motor rotates according to degrees 
 motor.step(deg);
  
}

void loop()
{
  if (digitalRead(buttonPin)==LOW)
  {
    rotate(angle);
    delay(500);
    rotate(-angle);
  }
}

Can you show how your motor is connected?

It's just the normal motor like this, PIN 1234 connecting to arduino pin 7,8,9,10

http://www.amazon.com/28BYJ-48-28BYJ48-4-Phase-Arduino-Stepper/dp/B0089JV2OM/ref=sr_1_1?ie=UTF8&qid=1390930426&sr=8-1&keywords=28BYJ-48+28BYJ48+DC+5V+4-Phase+5-Wire+Arduino+Stepper+Motor+with+ULN2003+Driver+Board

Try changing

void loop()
{
  if (digitalRead(buttonPin)==LOW)
  {
    rotate(angle);
    delay(500);
    rotate(-angle);
  }
}

to

void loop()
{
  if (digitalRead(buttonPin)==LOW)
  {
    rotate(angle);
    delay(500);
    rotate(-angle);
    delay (500) ;  // wait for motor to rotate the other way
  }
}

That way the reverse rotation has more than ~4us in which to take effect!!

You need to swap Pin 2 and Pin 3 in the Stepper init