#include <Stepper.h>
#define STEPS 200 // steps per revolution for biaxial motor
Stepper fanMotor(STEPS, 9, 11, 10, 12);
#define PIR_PIN 2
#define LIGHT_PIN 8
unsigned long lastMotionTime = 0;
unsigned long timeout = 10000;
bool systemActive = false;
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LIGHT_PIN, OUTPUT);
digitalWrite(LIGHT_PIN, LOW);
fanMotor.setSpeed(60); // Exhaust fan speed (RPM)
Serial.begin(9600);
}
void loop() {
int pirState = digitalRead(PIR_PIN);
if (pirState == HIGH) {
systemActive = true;
lastMotionTime = millis();
digitalWrite(LIGHT_PIN, HIGH);
fanMotor.step(15);
Serial.println("Motion detected → Light ON, Fan Running");
}
if (systemActive==true){
fanMotor.step(15);
}
if (systemActive && (millis() - lastMotionTime > timeout)) {
systemActive = false;
digitalWrite(LIGHT_PIN, LOW);
Serial.println("No movement → Light OFF, Fan OFF");
}
}