const int DIR = 12;
const int STEP = 14;
const int PIR_PIN = 35; // Change this to the actual pin number connected to your PIR sensor
const int step_per_rev = 1000;
void setup() {
Serial.begin(115200);
pinMode(STEP, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(PIR_PIN, INPUT);
}
void loop() {
if (digitalRead(PIR_PIN) == HIGH) {
// PIR sensor is HIGH (motion detected)
digitalWrite(DIR, HIGH);
Serial.println("Motion detected! Working continuously...");
// Continue rotating the stepper motor
while (digitalRead(PIR_PIN) == HIGH) {
digitalWrite(STEP, HIGH);
delayMicroseconds(2000);
digitalWrite(STEP, LOW);
delayMicroseconds(2000);
}
// Stepper motor stopped due to no motion
Serial.println("Motion stopped. Stepper motor turned off for 10 seconds.");
// Add a delay to keep the motor off for 10 seconds (adjust as needed)
delay(10000);
} else {
// PIR sensor is LOW (no motion)
Serial.println("No motion detected. Stepper motor continues to work.");
digitalWrite(STEP, HIGH);
delayMicroseconds(2000);
digitalWrite(STEP, LOW);
delayMicroseconds(2000);
}
}