Optical Encoder and Stepper Motor

I have a pulley system with a optical encoder attached to the timing belt pulley and they need to work together. Right now, mechanically things are set up correctly. I need help with the program. This is the program.

#include <Stepper.h>
const int stepsPerRev = 10;
int encoderIn = 11;
int statusLED = 13;
int val = 0;
int detectState = 0;
Stepper myStepper(stepsPerRev, 12, 10);
void setup() {
// Serial.begin(9600);
myStepper.setSpeed(5000);
pinMode(encoderIn, INPUT);
pinMode(statusLED, OUTPUT);

}

void loop() {
detectState=digitalRead(encoderIn);
if (detectState == HIGH)
{
digitalWrite(statusLED, HIGH);
myStepper.step(stepsPerRev);

}
else
{
digitalWrite(statusLED, LOW);
myStepper.step(stepsPerRev);

}
//{Serial.println("counterclockwise");

//}
}

With the code as is the motor will spin without pausing and the encoder will show a HIGH or LOW input by activating the pin 13 light on the Arduino.
What I need to happen is have the motor step to each "LOW" and pause for a short period of time.
If anyone has any coding suggestions I would appreciate it.

Why the encoder? .. its a stepper!
What you need is a switch to detect end_position.
Your program keeps track of current position

Thanks for the response. The encoder is needed to ensure that the valley of the belt is ending up under a sensor each time. Previous trials without an encoder showed that the belt would eventually skip a tooth under the sensor.

I will look into your suggestion thanks again.

ae

aedge:
Thanks for the response. The encoder is needed to ensure that the valley of the belt is ending up under a sensor each time. Previous trials without an encoder showed that the belt would eventually skip a tooth under the sensor.

I will look into your suggestion thanks again.

ae

Please explain "valley of the belt".

I have a selective soldering machine with stepper motors and timing belts. It has been running more than 10 years. The only timing belt problem we has was one time when the belt got slack after years of use and skipped a tooth. Put back and tightened the pelt properly and all is well.

Paul

Does each LOW correspond exactly with a full step of the motor?
5000 RPM? Have you tried running slower?