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();
}