PIR sensor code to keep the lock open until no motion detected

Hi , i am new to arduino programming and its my campus project and its about smart pet door . i have added components RFID solenoid locks to arduino Uno device. what i need is to when the tag reads from the RFID the locks are open properly and no problem with that but i want to fix the PIR sensor to keep the locks open untill cat leaves the door( because if the lock close while the cat leaves the cat might get injured and door wont close properly.
in short i am expecting the locks to be open until the rfid reads the correct tag , until there is no motion detected , then locks close

hear is the code for the current setup. the current setup reads the tag and open the locks for 10 seconds then close ( there is a Bluetooth device as well to send the signal to phone but that is negligible in this case, please ignore the Bluetooth device code). i do appriciate some one can help me with this. thank you.

#include <MFRC522.h>
#include <SPI.h>
#include <SoftwareSerial.h>
//#include <SD.h>




#define RST_PIN         9           // Configurable, see typical pin layout above
#define SS_PIN          8          // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
SoftwareSerial BTSerial(3, 4); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN

String read_rfid;
String ok_rfid_1="261c9018";
int lock=6;



String dooropen;
String data1;
char stb="t";



void setup() { 
  Serial.begin(9600);
  BTSerial.begin(38400);
  SPI.begin();                // Init SPI bus
  mfrc522.PCD_Init();         // Init MFRC522 card
 
   
  digitalWrite(lock,HIGH);
  pinMode(lock, OUTPUT);
   
  
}

void dump_byte_array(byte *buffer, byte bufferSize) {
    read_rfid="";
    for (byte i = 0; i < bufferSize; i++) {
        read_rfid=read_rfid + String(buffer[i], HEX);
    }
}

void bluesend(){
 BTSerial.println(stb);    
}

void open_lock() {
  //Use this routine when working with Relays and Solenoids etc.
  digitalWrite(lock,LOW);
  delay(8000);
  digitalWrite(lock,HIGH);
  
}


void loop(){

      // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;

    // Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
        return;

    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
    Serial.println(read_rfid);

    if (read_rfid==ok_rfid_1) {
      
    //ok, open the door.
      Serial.println(ok_rfid_1);
      Serial.println("Access Granted for pet 1");
      Serial.println("Door is poen and close in 10 seconds ");
     // open_lock();  
     bluesend(); 
  
       open_lock();        

  
}
char stb="t";

Oops.

i have removed most of the codes i have written as a test so my apologies for some unnecessary codes. just wanted to know where are the PIR code i need to put inside the loop, thank you for your help.

A PIR sensor usually cannot be programmed.

All you have got is :

  • adjustment for sensitivity
  • adjustment for lenght of output signal
  • retrigger yes/no

The retrigger DIP jumper allows you to retrigger the PIR as long as someone is moving within the sensor range.

So the light (or whatever) will stay on as long as you detect movements before the lenght of the output times out when you use RETRIGGERING.

The PIR will only give you ON or OFF signals, that cannot be programmed.
You got 2 potentiometers and a DIP switch.

The is no SIGNAL IN pin.

May be there are models which can be programmed. The stuff you can buy on Ebay cannot be programmed.

However, there is an idea for you ....

You set the timeout value as you think you need them. You use the Arduino to see how many trigger signals you will get and then you can let your Arduino decide what to do with the signals.