Thanks for the advice,
i have attempted to tidy up the formatting and code.
Below is the latest version. When i powered it up and triggered the motion sensor the stepper moved cw once. But it did not move ccw afterwards (to essentially return to its starting position). And when i triggered the motion sensor again the stepper didnt move at all.
#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;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int PIRValue = 0;
void setup()
{
stepper.setMaxSpeed(1000);
stepper.setAcceleration(200);
Serial.begin(9600);
pinMode(pirPin, INPUT);
}
void loop()
{
PIRSensor();
}
void PIRSensor()
{
if (digitalRead(pirPin) == HIGH)
{
if (lockLow)
{
stepper.moveTo(100);
stepper.moveTo(-100);
PIRValue = 1;
lockLow = false;
Serial.println("Motion detected.");
delay(50);
}
takeLowTime = true;
}
if (digitalRead(pirPin) == LOW)
{
if (takeLowTime) {
lowIn = millis();
takeLowTime = false;
}
if (!lockLow && millis() - lowIn > pause)
{
PIRValue = 0;
lockLow = true;
Serial.println("Motion ended.");
delay(50);
}
stepper.run();
}
}