I don't know which is the active state of a PIR sensor .
My assumption, for this sketch, was that it would go Low.
You can change that easily.
Anyway, once the 5 consecutive second threshold is crossed, LED 13 goes On.
And it stays on till the Reset button is pushed or you include a separate reset option
// trippoint5sec
//
// wait for 5 seconds
// of constant detection
//
unsigned long refTime;
unsigned long trippoint;
const long threshold = 5000;
byte DET;
const byte pirPin = 8;
const byte ledPin = 13;
void setup ()
{
//pirPin is INPUT by default, use ExtPullup
pinMode (ledPin,OUTPUT);
digitalWrite (ledPin,LOW);
}
void loop ()
{
DET = digitalRead(pirPin);
if (DET == 1) // inactive
{
refTime = millis();
trippoint = refTime;
}
else // Active Low
{
pir_active();
}
}
void pir_active ()
{
trippoint = millis();
if ((trippoint-refTime) > threshold)
{
digitalWrite(ledPin,HIGH);
}
}