Delay/Pause/Wait ???

Hi all, I am a newbie to C++ and Arduino so have a small project but am not sure how best to tackle it. Basically I have a Mega board and will put 2x PIR sensors on it and then output to a 2x Relay board. These will be installed in my shed and 2 sets of lights on the relays. All nice and simple so far. The idea is that you walk in the shed and it will switch on the 1st set of lights and the same with sensor #2. The issue is that I do not want to use the timer on the PIR, but want to tell the program that if it detects movement (PIN 53 goes high) then to turn on Relay No. 22 for 5 minutes (pin 22 to go High). Then if it detects movement within that 5 minutes, to reset teh 5 mins countdown. I tried to use the 'pause' command, but this paused the program, so PIR 2 would not work independently. Is there any way I can tell it code wise to hold for 5 mins (or so) but still allow the program to run so PIR#2 can still independently work? Or do I need to buy a real time clock and some how interface that into my code for counting? Anybody got any idea, such a simple project, but am scratching my head. My code so far is this:

In advance, thank you all for any assistance you can give me.

const int pirshed = 53;     // the number of the pushbutton pin
const int lightsshed =  22;      // the number of the LED pin

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  pinMode(lightsshed, OUTPUT);      
  pinMode(pirshed, INPUT);     
}


void loop(){
// This is the PIR Sensor for the main shed area
  buttonState = digitalRead(pirshed);
  if (buttonState == LOW) {     
    LightShedOn();
  } 
  else {
    LightShedOff();
  }
}


void LightShedOn(){
  digitalWrite(lightsshed, HIGH);
}


void LightShedOff(){
  digitalWrite(lightsshed, LOW);
}

Search for blink without delay.You will find your answer there

I tried to use the 'pause' command

C and C++ do not have commands. They have functions. The Arduino does not have a pause function. It has a delay() function.

Is there any way I can tell it code wise to hold for 5 mins (or so) but still allow the program to run so PIR#2 can still independently work?

Yes. You turn the relay on as needed, and record when you did that, Periodically (every pass through loop), you see if the relay is on, and if it is, you see if it still needs to be on (there has been movement in the last n milliseconds) or not. If it is on, but does not need to be, you turn it off. The blink without delay begins to explain the concept.

The demo several things at a time is an extended example of the Blink Without Delay technique.

If you want to keep extending a time delay a simple way is to record the time when the movement was detected. The light should go off if (currentMillis - movementDetectedMillis >= interval)

If, whenever a further movement is detected you update movementDetectedMillis = currentMillis; the effect will be to require the whole interval to be counted from that moment rather than from the original moment.

(It's a bit like a child counting up to 100, forgetting their place and starting again from 0)

...R