Stepper motor is not working according to code #include &lt;Stepper.h&gt;
#define STEPS_PER_MOTOR_REVOLUTION 32   
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 480  //2048  
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
int Steps2Take;
int dirpin=8;
int steppin=9;
int buttonApin=2;
int buttonBpin=3;

void setup() {
  pinMode(dirpin,OUTPUT);
  pinMode(steppin,OUTPUT);
  pinMode(buttonApin,INPUT);
  pinMode(buttonBpin,INPUT);
}

void loop() {
  int valA=digitalRead(buttonApin);
  int valB=digitalRead(buttonBpin);
  if(valA==HIGH) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(40000);
    delay(1000);
  }
  if(valB==HIGH) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(-40000);
    delay(1000);
  }
  if((valA==LOW)&amp;&amp;(valB==LOW)) {
    digitalWrite(steppin,HIGH);
    digitalWrite(dirpin,LOW);
    small_stepper.step(0);
  }
}


Here I have written this code to rotate stepper motor. When the input on digital pin 2 becomes high, then the motor should rotate clockwise. When the digital pin 3 becomes high, it should rotate in a different direction. When the input on both pins is low, the motor should not move.

But with this code the motor is moving continuously even if you apply high input to digital pins.

Please suggest how to fix this problem. For input signal I am taking signal from relays: if relay is in on condition, it should give a high signal and vice versa.
Does the relay actually connect the pin to ground when it is off?  Or does it leave the input floating?  If it leaves it floating then you should use a pull-down resistor to make sure the pin actually sees ground and not stray interference.  

If you can rewire the relays you can use an active low configuration and save the resistor since the Arduino has built-in pullup resistors.