Weird script with a timer but no timer function

Hey All,
I’m setting up a motion sensor and found the following sketch to start with. It works as intended with a short “ON’ cycle”, I want to extend the length of time the pin is HIGH but I don’t see a timer here.

When I run the sketch on a board there is about 15 seconds of ON time before the pin goes LOW. But I don’t see a variable for timeOn in this sketch.

So I have 2 questions

How does this sketch have 15 second on time?

How can I write the sketch to include a timeOn variable?

Thanks!
Rich

int calibrationTime = 5;        

boolean sensorActive = false;
boolean previousSensorState = false;

int pirPin = 12;    //the digital pin connected to the PIR sensor's output
int ledPin = 9;


// setup phase
void setup(){
  Serial.begin(115200);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);

  //give the sensor some time to calibrate
  Serial.println("Sensor Calibration in Progress");
  Serial.println("------------------------------");
  for(int i = 0; i < calibrationTime; i++){
    Serial.print(".");
    digitalWrite(ledPin, HIGH);
    delay(250);
    digitalWrite(ledPin, LOW);
    delay(250);
    digitalWrite(ledPin, HIGH);
    delay(250);
    digitalWrite(ledPin, LOW);
    delay(250);
  }
  Serial.println("");
  Serial.println("Sensor Calibration Completed");
  Serial.println("Sensor Reading Active");
  sensorActive = false;
  previousSensorState = false;
}

// loop sequence
void loop()
{
  // takes the pin value and saves it to the sensorActive boolean value
  if(digitalRead(pirPin) == HIGH)
  {
    sensorActive = true;
    digitalWrite(ledPin, HIGH);
  }
  if(digitalRead(pirPin) == LOW)
  {
    sensorActive = false;
    digitalWrite(ledPin, LOW);
  }
  
  // performs action if the state of the sensor changes
  // since this is a loop, here is now it works:
  // if the sensor pin goes HIGH (on) after it being LOW (off), the sensorActive value changes from the previousSensorState value.
  // it then turns on the LED. when the pin goes LOW (off) it will do the same thing but opposite values.
  // it also prints status to serial. it will print the time of triggering by providing the number of seconds that have passed since the program started.
  if(sensorActive != previousSensorState)
  {
    if(sensorActive == true)
    {
      previousSensorState = sensorActive;
      Serial.println("---");
      Serial.print("Motion Detected At: ");
      Serial.print(millis()/1000);
      Serial.println(" Seconds"); 
      delay(50);
    }
    if(sensorActive == false)
    {
      previousSensorState = sensorActive;
      Serial.println("---");
      Serial.print("Motion Stopped At: ");
      Serial.print(millis()/1000);
      Serial.println(" Seconds"); 
      delay(50);
    }
  }
}

PIR sensors come usually with 2 potentiometers, One of the potentiometer is to set the dwell time of the HIGH state (how long it stays HIGH after triggering) - The second potentiometer is a trimmer to adjust the sensitivity on the PIR boards I have the dwell time is labeled T with a letter next to it and Sensitivity S with a letter next to it. those are what my 2 types of PIR looks like |500x348

this is something you adjust manually, so "How can I write the sketch to include a timeOn variable?" is a challenge unless you want to have a servo turning the small potentiometer.

Alternatively, set the time as low as possible and handle a longer duration in your code but you won't be able to go below the minimum timing available on your specific hardware unless you ignore the pin information.

Oh yeah, Duh! I knew about that feature but had forgotten about it. I’ll turn it down as low as possible and do the rest in the code.

Thanks!
R