Help with sketch

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);
}

If you don’t want anything to happen for the two minutes just use delay ().

As you have no means of turning the LEDs off, I assume you will be resetting the Arduino each time you leave the room.

Weedpharma

In which case you should also have a lengthy delay in setup to allow you time to leave the room after you reset it.

How about just a 2-minute delay? When you detect movement, remember the time. Once 2 minutes are up, turn on the LED.

If that is all you are doing you could probably do:

if(digitalRead(pirPin) == HIGH){
       delay (2L * 60 * 1000);  // wait 2 minutes
       digitalWrite(ledredPin, HIGH);   // turn on the LED
     }

As you have no means of turning the LEDs off, I assume you will be resetting the Arduino each time you leave the room.

Good point. In setup() you would need to have a delay of a minute or so, so you can escape before it activates.

He has a loop of 30 x 200mS, or six seconds. Maybe if he runs fast.......

Weedpharma