// PIR Motion Detection with Arduino Uno
int ledPin = 13;
int pirPin = 2;
int state = LOW;
unsigned long startTime, responseTime;
int motionCount = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(pirPin, INPUT);
Serial.begin(115200);
Serial.println("Arduino PIR Motion Detection - Response Time Test");
}
void loop(){
startTime = micros();
int pirValue = digitalRead(pirPin);
if (pirValue == HIGH) {
digitalWrite(ledPin, HIGH);
responseTime = micros() - startTime;
if (state == LOW) {
motionCount++;
Serial.print("Motion #");
Serial.print(motionCount);
Serial.print(" - Response Time: ");
Serial.print(responseTime);
Serial.println(" μs");
state = HIGH;
}
}
else {
digitalWrite(ledPin, LOW);
if (state == HIGH){
Serial.println("Motion stopped");
state = LOW;
}
}
delay(500);
}