Try this simplified program
const int stepPin = 3;
const int dirPin = 4;
int relpin = 12;
const int stepsPerRevolution = 200;
void setup()
{
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(relpin, INPUT);
digitalWrite (relpin, LOW);
Serial.begin(9600);
}
void loop()
{
if (digitalRead(relpin) == HIGH)
{
runMotor(LOW);
}
else
{
runMotor(HIGH);
}
}
void runMotor(byte direction)
{
digitalWrite(dirPin, direction);
for (int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
}
}
NOTE : it does not do what you want but it will allow you to test reading your input pin and running the motor and can then be added to.
Note the use of a function that moves the motor 200 steps in a direction set by the value passed to it.
Try the program and report back what happens. If it does what I think then you can move on to do exactly what you want but that will involve adding more logic but the moveMotor() function can still be used.
How is the input wired ?