PIR flashing

This sketch will initially make the PIR pin go high when I approach the board but then it will flash, several seconds on, then off. I want it to remain high for five or ten seconds and then sit inactive until the next motion is detected.

int calibrationTime = 30;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

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

//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, 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(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);   //the led visualizes the sensors output pin state
       if(lockLow){
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec");
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }

Just after:-
digitalWrite(ledPin, HIGH);
Put
delay(5000);
That will keep the LED on for 5 seconds. It will then look again at the sensor and turn the LED off if there is no one there.
Is that what you want?

I may have added the delay in the wrong place but the hardware behaves the same; the led lights when I approach but then the it toggles on/off thereafter. Yes, I want it to remain on for 5 seconds, then off until the PIR senses another movement.

Here is the current sketch:

int calibrationTime = 30;        

//the time when the sensor outputs a low impulse
long unsigned int lowIn;         

//the amount of milliseconds the sensor has to be low 
//before we assume all motion has stopped
long unsigned int pause = 5000;  

boolean lockLow = true;
boolean takeLowTime;  

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

//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, 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(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
  }

////////////////////////////
//LOOP
void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);
    delay(5000);
       //the led visualizes the sensors output pin state
       if(lockLow){
         //makes sure we wait for a transition to LOW before any further output is made:
         lockLow = false;
         Serial.println("---");
         Serial.print("motion detected at ");
         Serial.print(millis()/1000);
         Serial.println(" sec");
         delay(50);
         }         
         takeLowTime = true;
       }

     if(digitalRead(pirPin) == LOW){
       digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state

       if(takeLowTime){
        lowIn = millis();          //save the time of the transition from high to LOW
        takeLowTime = false;       //make sure this is only done at the start of a LOW phase
        }
       //if the sensor is low for more than the given pause, 
       //we assume that no more motion is going to happen
       if(!lockLow && millis() - lowIn > pause){
           //makes sure this block of code is only executed again after 
           //a new motion sequence has been detected
           lockLow = true;
           Serial.print("motion ended at ");      //output
           Serial.print((millis() - pause)/1000);
           Serial.println(" sec");
           delay(50);
           }
       }
  }

but the hardware behaves the same

Now that I do not believe that, the code will delay for 5 seconds once the LED turns on.

The comments in your code do not match what you say you want to do and the also do not match what the code is doing.
For example the comment:-
//makes sure we wait for a transition to LOW before any further output is made:
Then just has an if statement there is no waiting involved at all.
Try a different approach along these lines, As I haven't got your hardware I can't try it but 5the structure should be better.

int calibrationTime = 30;

//the time when the sensor outputs a low impulse
long unsigned int lowIn;

//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;

boolean lockLow = true;
boolean takeLowTime;

int pirPin = 4;    //the digital pin connected to the PIR sensor's output
int ledPin = 13;
long timeToRelease;
//SETUP
void setup(){
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);  // this turns off any internal pull ups is this right? if so you don't need to do it they are off by default

  //give the sensor some time to calibrate
  Serial.print("calibrating sensor ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
    timeToRelease = millis();
  }

////////////////////////////
//LOOP

void loop(){

     if(digitalRead(pirPin) == HIGH){
       digitalWrite(ledPin, HIGH);
        timeToRelease = millis() + 5000; // reset timer so LED lasts 5 seconds after movement stops       
       }
    else {
      if(millis() > timeToRelease) {
        digitalWrite(ledPin, LOW);  // Turn LED off as movement has stopped for 5 seconds
      }
    }
     
  }

Your sketch works fine with a hacked motion detector night light but the PIR continues to flash briefly every five seconds, after the initial high. Wouldn't this point to a hardware problem?

Forgive me if what I'm about to say is of no interest, or maybe even just wrong... but I wonder if the comments above are perhaps getting confused through not being explicit enough about the following....

When the PIR sensor "sees" movement, it will change the state on its output pin, the input to the Arduino. How long that signal stays in the "PIR sees movement" state will be a function of the electronics of the PIR, and of the movement that triggered/is triggering it. It is possible that the PIR module has some kind of pulse stretcher built into it... or not. (Or, if you really want to, you could add discrete electronics to stretch the signal.... but I'd be inclined to do it in software, if stretching is needed)

Now let's turn to the LED driven by the program in the Arduino. The program can be written in at least two ways....

a) the LED driven by the Arduino could be on or off in (nearly) "exact" synchrony with the signal from the PIR, or...

b) whenever the Arduino sees a "movement" signal from the PIR, the LED could be switched on for the next, say, 10 seconds, to "say": "sometime in the recent past, the PIR saw movement. The signal from the PIR may be back at "no movement" at this particular moment."

Option "b" is what I meant by a "software pulse stretcher".

Sorry if everyone was already clearly distinguishing the two things... state of signal from PIR and state of LED driven by Arduino. (They don't have to be in perfect lockstep.)

I finally put the delay(5000); where it should have been and the sketch works! I appreciate all the help with this one.

i

     if(digitalRead(pirPin) == LOW){
       digitalWrite(ledPin, LOW);  /
       [u]delay(5000);[/u]
       if(takeLowTime){
        lowIn = millis();           
        takeLowTime = false;