I want to know if someone has entered a room when I am not there. If the motion sensor detects motion an LED lights up and stays on to indicate someone has been in the room while I was away.
Because I’m sure that I’ll trigger the motion sensor when I return to the room I want a two light system. If when I return there is one light on then I just triggered it and no one has been in the room. If two lights are on then any number of people have been in the room before me.
I have modified a sketch like this so far, but I need for there to be, say, a 2 minute delay between the first and second if statements.
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 7;
int ledredPin = 8;
int ledbluePin = 2;
/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledredPin, OUTPUT);
pinMode(ledbluePin, OUTPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print(“calibrating sensor “);
for(int i = 0; i < calibrationTime; i++){
Serial.print(”.”);
delay(200);
}
Serial.println(" done");
Serial.println(“SENSOR ACTIVE”);
delay(50);
}
////////////////////////////
//LOOP
void loop(){
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledredPin, HIGH); //the led visualizes the sensors output pin state
}
if(digitalRead(ledredPin) == HIGH && digitalRead(pirPin) == HIGH){
digitalWrite(ledbluePin, HIGH);
}