@kfccucumber if you don't yet automatically enforce a good coding style as far as little formatting details is concerned, which make no never mind to the compiler but can mislead a person be she the author or the reader, you should get in the habit of using the IDE Auto Format tool.
It can make some errors obvious.
Here's some of your code after I did, and tweaked it a bit beyond what Auto Format does:
if (sensorValue < 800) {
digitalWrite(enPin, HIGH);
digitalWrite(MOSPin, HIGH);
}
if (sensorValue > 800) {
digitalWrite(enPin, LOW);
digitalWrite(MOSPin, LOW);
}
for (int x = 0; x < 400; x++)
digitalWrite(stepPin, HIGH);
digitalWrite(stepPin, LOW);
if (digitalRead(sensorPinb) == HIGH) {
// If yes, set the output pin to HIGH and record the start time
digitalWrite(outputPinb, HIGH);
startTimeb = millis();
}
HTH
a7