help with coding for a stepper motor

Hi Robin2,

i meant the latter;

Robin2:
after it has done one out-and-back it should not start another one for at least 5 seconds

Thanks so much for the code, i am now trying to format it, although coming up with a few errors, on my part,

at the moment i cant seem to figure out the code: if (PIR is detected)

Do i need to declare PIR at the start of the sketch?

#include <AccelStepper.h>

AccelStepper stepper (1, 3, 2); // name of stepper motor (1 = driver, pin 3 = step, pin 2 = direction)
int pirPin = 4;

int calibrationTime = 30;


void setup() {

  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(200);

  Serial.begin(9600);
  pinMode(pirPin, INPUT);

}

void loop() {

  if (PIR is detected) {
    PIRdetected = true;
    motorDirection = 'F';
    motorMoving = false;
  }

  if (PIRdetected == true) {
    if (motorMovng == false) {
      if (motorDirection == 'F') {
        moveTo (200);
        motorMoving = true;
        else {   // meaning motorDirection == 'R'
          moveTo (-200);
          motorMoving = true;
        }
        if (motorMoving == true and distanceToGo() == 0) {
          motorMoving = false;
        }
        if (motorDirection = 'F') {
          motorDirection = 'R';
        }
        else {
          PIRdetected = false;
          motorDirection = 'F';
        }
      }
    }
  }
  stepper.run();


}