///////////////////////////// //VARS //the time we give the sensor to calibrate (10-60 secs according to the datasheet) int calibrationTime = 30; int pirPin = 0; //the digital pin connected to the PIR sensor's output int ledPin = 7; int lowRead[5]; ///////////////////////////// //SETUP void setup(){ Serial.begin(9600); pinMode(pirPin, INPUT); pinMode(ledPin, OUTPUT); digitalWrite(pirPin, LOW); digitalWrite(ledPin, LOW); //give the sensor some time to calibrate Serial.print("calibrating sensor "); for(int i = 0; i < calibrationTime; i++){ Serial.print("."); delay(1000); } Serial.println(" done"); Serial.println("SENSOR ACTIVE"); delay(50); } //////////////////////////// //LOOP void loop(){ while(digitalRead(pirPin == HIGH)) { digitalWrite(ledPin, HIGH); Serial.print("motion detected at "); Serial.print(millis()/1000); Serial.println(" sec"); delay(5000); } for(int i=0; i < 5; i++){ if(digitalRead(pirPin)==LOW){ lowRead[i]=1; Serial.print(" no motion detected at "); Serial.print(millis()/1000); Serial.println(" sec"); } delay(1000); } if (lowRead [0] == 1 && lowRead [1] == 1 && lowRead [2] == 1 && lowRead [3] == 1 && lowRead [4] == 1 ){ digitalWrite(ledPin,LOW); } else{ digitalWrite(ledPin, HIGH); } } /////////////////////////////////