const int pirPin = 7; // Pin connected to PIR sensor
const int ledPin = 12; // Pin connected to LED
unsigned long motionDetectedTime = 0;
unsigned long ledOnTime = 0;
unsigned long responseTime = 0;
void setup() {
pinMode(pirPin, INPUT); // Set PIR pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Start serial communication
}
void loop() {
int pirValue = digitalRead(pirPin); // Read PIR sensor value
if (pirValue == HIGH) { // If motion is detected
motionDetectedTime = micros(); // Record the time when motion is detected
digitalWrite(ledPin, HIGH); // Turn on the LED
ledOnTime = micros(); // Record the time when LED turns on
responseTime = ledOnTime - motionDetectedTime; // Calculate response time
Serial.print("Response Time: ");
Serial.print(responseTime);
Serial.println(" microseconds");
}
delay(100); // Small delay for stable reading
}