does not store rfid tags in eeprom

HI, i hope is ok posting my question here, i tried asking for help on the Arduino cc forum and people on there are very unhelpful to my surprise.

i am trying to set up a door opener which uses a keypad or Rfid.

After scouring the net for days i could only find one project which did this, absolutely everything else out there expects you to use an Rfid tag and then input a passcode on the keypad, not one or the other.

The creator of this code actually made two almost identical versions, the second just adding Bluetooth.

The first displayed correctly on the lcd but both the keypad and rfid functions were broken.

The second version which is what im trying to get working is sort of working.

The passcode on the keypad works and triggers the output pin to trigger the relay and the led outputs work correctly.

The Display is broken, it only displays the first character of messages but for some reason it displays all of the ‘x’ characters correctly when inputting the passcode?

it would be nice if i could get it displaying the messages in full instead of just the first character but its not something i need as i only intended to have the lcd on the inside of the door to display status when pairing Rfid tags ect and will be using two leds with the keypad outside.

The Bluetooth is broken, it does not respond to codes being sent but the arduino is being sent the data as you can see the rx led on the board blink but i really dont care about the Bluetooth as i have no intention of using it or even having a module connected and just thought id have a play with it in testing.

Now for the important part, the Rfid is broken.

The module (RC522) sees tags just fine, the arduino responds and tag numbers are displayed in serial monitor.

putting in the keypad code to enter pairing mode works fine and when you present a tag the it says its been paired (well one character on the lcd but i know what it means lol) and it also says its been paired in serial monitor but it does not store the tag and subsequent reads of that tag will generate the ‘invalid NFC code’ message and does not trigger the relay output pin.

The code has a section about storing tags to the eeprom but this is clearly not happening but i cannot code Arduino, i just about manage to read existing codes and modify certain things for slightly different behaviour and this is beyond my ability.

Please could someone read though the code (its not huge) and see if they can figure out why its not storing tags please?

If the messages not being displayed is a simple thing then that would be great too but that’s not really important, i just want the physical side working.

ive looked at the lcd code and its baffled me as the original sketch where none of the physical functions worked, the lcd code worked fine and messages were correctly displayed, ive examined and compared the code between the two different sketches and cant see any difference so no idea why it would only display the first character :smiley-confuse:

The Rfid tags being stored is the only thing i really want to fix or even just know if i can manually enter tag serials into the code anything else is a bonus, ive looked at the code to see if i can manually input tag numbers and ive tried a couple of places that looked like code sections but nothing worked.

Your help would be really appreciated!

Thanks, Steve.

#include <EEPROM.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>


int state_bt=1;
int relPin;
int stare=0;
byte  COD[10];
byte  AUX[10];
int k=0;
String codacces="*123456#";
String codpairing="*654321#";
//nfc
#define RST_PIN   9     // Configurable, see typical pin layout above
#define SS_PIN    10    // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}
MFRC522::MIFARE_Key key;
//lcd

LiquidCrystal_I2C  lcd(0x27,16,2);

//TASTATURA
const byte numRows= 4; //number of rows on the keypad
 
const byte numCols= 3; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3',},
 
{'4', '5', '6',},
 
{'7', '8', '9',},
 
{'*', '0', '#',}
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = {5, A0, 7, 8}; //Rows 0 to 3
 
byte colPins[numCols]= {2, 3, 4}; //Columns 0 to 3
 

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);


void setup() {
   pinMode(A0,OUTPUT);
   digitalWrite(A0,HIGH);
   pinMode(A3,OUTPUT);
   digitalWrite(A3,HIGH);
   pinMode(A1,OUTPUT);
   digitalWrite(A1,HIGH);
   pinMode(A2,OUTPUT);
   digitalWrite(A2,LOW);
   pinMode(6,OUTPUT);
   digitalWrite(6,LOW);
   //nfc
  Serial.begin(9600);  // Initialize serial communications with the PC
  Serial.println("What did you say?:");
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card
 
    for (byte i = 0; i < 6; i++) {
    key.keyByte = 0xFF;
  }

    lcd.init();
    lcd.backlight();
    lcd.setCursor(0,0);
    lcd.clear();
    lcd.print( "LOCKED" );

}

void  citireNFC(){
  for (byte i =0; i<(mfrc522.uid.size); i++) {
    COD=mfrc522.uid.uidByte;
  }
  Serial.print("COD");
  Serial.print(COD[0]);
  Serial.print(COD[1]);
  Serial.print(COD[2]);
  Serial.print(COD[3]);
 
}

void pairNFC(){
  Serial.println("COD in pair");
  Serial.print(COD[0]);
  Serial.print(COD[1]);
  Serial.print(COD[2]);
  Serial.print(COD[3]);
   long  r=0;
   int c=0;
  for(int i=1;i<=EEPROM.read(0);i++){
    switch(i%4){
          case 1 :{AUX[0]=EEPROM.read(i); break;}
          case 2 :{AUX[1]=EEPROM.read(i); break;}
          case 3 :{AUX[2]=EEPROM.read(i); break;}
          case 0 :{AUX[3]=EEPROM.read(i); break;}
    }
    if((i)%4==0)
       {Serial.println(r);
        if( AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3] ){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("CODE ALREADY IN");
          lcd.setCursor(0,1);
          lcd.print("SYSTEM");
          delay(2000);
           c=1;
          break;}   
      }
      }
  if(c==0){int ttt=EEPROM.read(0);
              Serial.println("CODE PAIRED");
              Serial.print(COD[0]);
              Serial.print(COD[1]);
              Serial.print(COD[2]);
              Serial.print(COD[3]);

          EEPROM.write(ttt+1,COD[0]);
          EEPROM.write(ttt+2,COD[1]);
          EEPROM.write(ttt+3,COD[2]);
          EEPROM.write(ttt+4,COD[3]);

          ttt=ttt+4;
          Serial.println("ttt");
          Serial.println(ttt);
          EEPROM.write(0,0);
          EEPROM.write(0,ttt);   
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("CODE PAIRED");
          delay(2000);}   
  }
 

boolean validareNFC(){
   boolean c=false;
      for(int i=1;i<=EEPROM.read(0);i++){
          switch(i%4){
          case 1 :{AUX[0]=EEPROM.read(i); break;}
          case 2 :{AUX[1]=EEPROM.read(i); break;}
          case 3 :{AUX[2]=EEPROM.read(i); break;}
          case 0 :{AUX[3]=EEPROM.read(i); break;}
        }
    if((i)%4==0)
       {
        if( AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3])
          c=true;
         }}       
   return c;     
}

int comparareCOD(String a)
 {
  if(a.equals(codacces))
     return 1;
  else if(a.equals(codpairing)) return 2;
  else return 0;   
 }


String iaCOD(char x)
{ char vec[10];
  vec[0]=x;
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print('X');
  for(int i=1;i<8;i++)
     {vec=myKeypad.waitForKey();
      lcd.print('X');}
  vec[8]=NULL;
  String str(vec);
  return str;
}   



void loop() {
 
  //Start BT autentification
   if(Serial.available())
  {
  char c=Serial.read();
  switch (state_bt) {
 
  case 1:
  if(c=='*') state_bt=2;
  else state_bt=1;
  break;
 
  case 2:
  if(c=='1') state_bt=3;
  else state_bt=1;
  break;
 
  case 3:
  if(c=='2') state_bt=4;
  else state_bt=1;
  break;
 
  case 4:
  if(c=='3') state_bt=5;
  else state_bt=1;
  break;
 
  case 5:
  if(c=='4') state_bt=6;
  else state_bt=1;
  break;
 
  case 6:
  if(c=='5') state_bt=7;
  else state_bt=1;
  break;
 
  case 7:
  if(c=='6') state_bt=8;
  else state_bt=1;
  break;
 
  case 8:
  if(c=='#') state_bt=9;
  else state_bt=1;
  break;
 
  case 9:

  lcd.init();   
  lcd.backlight();
  lcd.print("OPEN");
  digitalWrite(6,LOW);
  delay(5000);
  digitalWrite(6,HIGH);
  lcd.init();   
  lcd.backlight();
  lcd.print("BLOCKED");
  state_bt=1;
  break;
 
  default:
 
  break;
  }
  }
 
 
  //////////END BT Autentification
       
      switch(stare){
      case 0: {
        mfrc522.PCD_Init();
        if (  mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){
       
        citireNFC();
        if(validareNFC()) 
           {stare=1;
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("VALID NFC CODE");
            delay(1000);
            return;   
           }
        else{
             lcd.clear();
             lcd.setCursor(0,0);
             lcd.print("INVALID NFC CODE");
             delay(1000);
             lcd.setCursor(0,0);
             lcd.clear();
             lcd.print("BLOCKED");
             return;
            }
        }
      char c=myKeypad.getKey();
      if(c != NO_KEY){
       
      String codcurent=iaCOD(c);
      int A=comparareCOD(codcurent);
      if(A==0)
      {lcd.clear();
       lcd.print("INVALID CODE");
       delay(2000);
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("BLOCKED");
       return;}
      if(A==1)
      {lcd.setCursor(0,0);
       lcd.clear();
       lcd.print("VALID CODE");
       delay(2000);
       stare = 1;
       return;}
      if(A==2);
       {stare=2;
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("Pairing...");
          delay(2000);
        return;}
      } break;
       }
      case 1:{
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("UNLOCKED");
        digitalWrite(A3,LOW);
        digitalWrite(A1,LOW);
        digitalWrite(A2,HIGH);
        //tone(6,3000,5010);
        digitalWrite(6,HIGH);
        delay(2000);
        digitalWrite(6,LOW);
        digitalWrite(A3,HIGH);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,LOW);
        stare=0;
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("BLOCKED");
       
       
     
        return;
        }
        case 2:{
         
          mfrc522.PCD_Init();
          if (  mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){
          citireNFC();
          pairNFC();
          stare=0;
          delay(2000);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("BLOCKED");   }
                   
       
       
         
         
          break;
         
        }
         
       }

}

Hello,

What SparkFun products are you using?

I’m not, that’s why I asked if posting here was OK because I wasn’t sure if it was just for spark fun gear or a general arduino forum too.

The board is an arduino nano and the the RFID is a rc522.

Im sure the problem is in the code, the setup can read RFID tags fine but they don’t get stored in the eeprom and as hard as I’ve tried to find out why or try to figure out if I can manually place tag I.D’s in the code , I’ve not been successful and no other arduino sketch I can find after extensive searching does what I want :frowning:

Steve.

hi

I looked at your code. Couple of feedback make sure to keep the code with indent and clean. It is hard to debug the code and follow the logic without, second : add comments about why routines/ variables are set, makes it easier to follow and understand. There are a number of unused/ non-clear variables which is confusion. On a 2 places in the code missed bracket ‘i’ bracket, on 1 place there was a ‘;’ right behind an if statement (causing the content not to be executed). I have indicated that in the, non tested only try to clean-up, code.

#include <EEPROM.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>


int state_bt=1;              // button state
int relPin;                  // ???????????? NOT USED
int stare=0;                 // machine state
byte  COD[10];               // store the NFC code
byte  AUX[10];               // used for compare NFC code
int k=0;                     // ???????????? NOT USED
String codacces="*123456#";  // entry access code
String codpairing="*654321#";// pairting access code

//nfc
#define RST_PIN   9          // Configurable, see typical pin layout above
#define SS_PIN    10         // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN);        // Create MFRC522 instance
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF} // ???????????? NOT USED
MFRC522::MIFARE_Key key;

//lcd
LiquidCrystal_I2C  lcd(0x27,16,2);

//TASTATURA
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 3; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{'1', '2', '3',},

{'4', '5', '6',},

{'7', '8', '9',},

{'*', '0', '#',}
};

//Code that shows  the keypad connections to the arduino terminals
byte rowPins[numRows] = {5, A0, 7, 8}; //Rows 0 to 3

byte colPins[numCols]= {2, 3, 4}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);


void setup() {
  pinMode(A0,OUTPUT);          // ???
  digitalWrite(A0,HIGH);
  pinMode(A3,OUTPUT);          // ???
  digitalWrite(A3,HIGH);
  pinMode(A1,OUTPUT);          // ???
  digitalWrite(A1,HIGH);
  pinMode(A2,OUTPUT);          // ???
  digitalWrite(A2,LOW);
  pinMode(6,OUTPUT);           // door opener
  digitalWrite(6,LOW);

  Serial.begin(9600);  // Initialize serial communications with the PC
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  Serial.println("What did you say?:");

  //nfc
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card

  // clear key
  for (byte i = 0; i < 6; i++) {
    key.keyByte = 0xFF;
  }

  // set LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print( "LOCKED" );
}

// extract NFC info
void  citireNFC(){
  for (byte i =0; i<(mfrc522.uid.size); i++) {
    COD[i]=mfrc522.uid.uidByte;        // was wrong missing [i] !!!!
  }
  Serial.print("COD");
  Serial.print(COD[0]);
  Serial.print(COD[1]);
  Serial.print(COD[2]);
  Serial.print(COD[3]);

}

// add a new card in EEPROM (if not already there)
void pairNFC() {

  Serial.println("COD in pair");
  Serial.print(COD[0]);
  Serial.print(COD[1]);
  Serial.print(COD[2]);
  Serial.print(COD[3]);
  long  r=0;            //????????????????????????? WHY
  int c=0;              // flag to save in EEPROM

  // check COD is NOT already in
  for(int i=1;i<=EEPROM.read(0);i++) {

    switch(i%4){
      case 1 :{AUX[0]=EEPROM.read(i); break;}
      case 2 :{AUX[1]=EEPROM.read(i); break;}
      case 3 :{AUX[2]=EEPROM.read(i); break;:
      case 0 :{AUX[3]=EEPROM.read(i); break;}
    }

    if(i%4 == 0) {
      Serial.println(r);  //???????????????????????????? WHY?
        if(AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3] ){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("CODE ALREADY IN");
          lcd.setCursor(0,1);
          lcd.print("SYSTEM");
          delay(2000);
          c=1;      // indicate it is already in EEPROM
          break;
        }
      }
    }
  }

  // if NOT yet in EEPROM
  if(c == 0){
    // get length last postion in EEPROM
    // ????????? NO CHECK ON MAXIMUM IN EEPROM ??????????
    int ttt=EEPROM.read(0);

    Serial.print("CODE PAIRED: ");
    Serial.print(COD[0]);
    Serial.print(COD[1]);
    Serial.print(COD[2]);
    Serial.println(COD[3]);

    // write to EEPROM
    EEPROM.write(ttt+1,COD[0]);
    EEPROM.write(ttt+2,COD[1]);
    EEPROM.write(ttt+3,COD[2]);
    EEPROM.write(ttt+4,COD[3]);

    // save new length
    ttt=ttt+4;
    Serial.println("ttt");
    Serial.println(ttt);
    EEPROM.write(0,0);
    EEPROM.write(0,ttt);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("CODE PAIRED");
    delay(2000);}
}

// check for COD match with stored in EEPROM
boolean validareNFC(){
   boolean c=false;

   // read complete EEPROM for match
   for(int i=1;i<=EEPROM.read(0);i++){

      switch(i%4){
        case 1 :{AUX[0]=EEPROM.read(i); break;}
        case 2 :{AUX[1]=EEPROM.read(i); break;}
        case 3 :{AUX[2]=EEPROM.read(i); break;}
        case 0 :{AUX[3]=EEPROM.read(i); break;}
      }

      if(i%4 == 0) {
        if( AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3]) {
          c=true;
          break;
        }
      }
   return c;
}

// check access code match
int comparareCOD(String a) {
  if(a.equals(codacces)) return 1;
  else if(a.equals(codpairing)) return 2;
  else return 0;
}

// read keypad information
String iaCOD(char x) {
  char vec[10];

  vec[0]=x;

  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print('X');

  for(int i=1;i<8;i++) {
    vec[i]=myKeypad.waitForKey();       // was wrong missing [i] !!!!!!!
    lcd.print('X');
  }

  vec[8]=NULL;
  String str(vec);
  return str;
}

void loop() {

  /*??? THIS LOOKS LIKE A HARD CODED PASSWORD VALIDATION ??? */
  //Start BT autentification
  if(Serial.available()) {

    char c = Serial.read();


      switch (state_bt) {

        case 1:
            if(c == '*') state_bt=2;
            else state_bt=1;
            break;

        case 2:
            if(c == '1') state_bt=3;
            else state_bt=1;
            break;

        case 3:
            if(c == '2') state_bt=4;
            else state_bt=1;
            break;

        case 4:
            if(c == '3') state_bt=5;
            else state_bt=1;
            break;

        case 5:
            if(c == '4') state_bt=6;
            else state_bt=1;
            break;

        case 6:
            if(c == '5') state_bt=7;
            else state_bt=1;
            break;

        case 7:
            if(c == '6') state_bt=8;
            else state_bt=1;
            break;

        case 8:
            if(c == '#') state_bt=9;
            else state_bt=1;
            break;

        case 9:

            lcd.init();
            lcd.backlight();
            lcd.print("OPEN");
            digitalWrite(6,LOW);
            delay(5000);
            digitalWrite(6,HIGH);
            lcd.init();
            lcd.backlight();
            lcd.print("BLOCKED");
            state_bt=1;
            break;

        default:
            state_bt=1;
            break;
      }
    }   // end serialavailable()


  //////////END BT Autentification

  switch(stare){

    // read and validate NFC or Keypad
    case 0:
       mfrc522.PCD_Init();
       // check for NFC card
       if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){

         // extract COD
         citireNFC();

         // validate COD against EEPROM
         if(validareNFC()) {
            stare=1;        // open the door in the next loop
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("VALID NFC CODE");
            delay(1000);
            return;
         }
         else {
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("INVALID NFC CODE");
            delay(1000);
            lcd.setCursor(0,0);
            lcd.clear();
            lcd.print("BLOCKED");
            return;
         }
       }

       // check keypad for access code
       char c = myKeypad.getKey();
       if(c != NO_KEY){

          // extract the keypad code
          String codcurent=iaCOD(c);

          int A=comparareCOD(codcurent);

          // neither entry access nor pair access code
          if(A == 0) {
             lcd.clear();
             lcd.print("INVALID CODE");
             delay(2000);
             lcd.setCursor(0,0);
             lcd.clear();
             lcd.print("BLOCKED");
             return;
          }
          // entry access code
          else if(A == 1) {
             lcd.setCursor(0,0);
             lcd.clear();
             lcd.print("VALID CODE");
             delay(2000);
             stare = 1;         // open the door
             return;
          }
          // pairing access code
          else if(A == 2) { // was wrong has ; at the end ???????????????
             stare=2;          // perform pairing
             lcd.clear();
             lcd.setCursor(0,0);
             lcd.print("Pairing...");
             delay(2000);
             return;
          }
         } // keypad check
         break;

      // open the door
      case 1:
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("UNLOCKED");
        digitalWrite(A3,LOW);       //???
        digitalWrite(A1,LOW);
        digitalWrite(A2,HIGH);
        //tone(6,3000,5010);

        digitalWrite(6,HIGH);       // door opener
        delay(2000);
        digitalWrite(6,LOW);

        digitalWrite(A3,HIGH);      //?????
        digitalWrite(A1,HIGH);
        digitalWrite(A2,LOW);

        stare=0;                    // reset to wait for NFC or KEYPAD
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("BLOCKED");
        return;
        break;

     // perform pairing
     case 2:
        mfrc522.PCD_Init();

        if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){
          // extract card
          citireNFC();

          // store in EEPROM
          pairNFC();
          stare=0;                  // reset to wait for NFC or KEYPAD
          delay(2000);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("BLOCKED");
        }
        break;
    }
}

paulvha:
hi

I looked at your code. Couple of feedback make sure to keep the code with indent and clean. It is hard to debug the code and follow the logic without, second : add comments about why routines/ variables are set, makes it easier to follow and understand. There are a number of unused/ non-clear variables which is confusion. On a 2 places in the code missed bracket ‘i’ bracket, on 1 place there was a ‘;’ right behind an if statement (causing the content not to be executed). I have indicated that in the, non tested only try to clean-up, code.

#include <EEPROM.h>

#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

int state_bt=1; // button state
int relPin; // ??? NOT USED
int stare=0; // machine state
byte COD[10]; // store the NFC code
byte AUX[10]; // used for compare NFC code
int k=0; // ??? NOT USED
String codacces=“*123456#”; // entry access code
String codpairing=“*654321#”;// pairting access code

//nfc
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF} // ??? NOT USED
MFRC522::MIFARE_Key key;

//lcd
LiquidCrystal_I2C lcd(0x27,16,2);

//TASTATURA
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 3; //number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]=
{
{‘1’, ‘2’, ‘3’,},

{‘4’, ‘5’, ‘6’,},

{‘7’, ‘8’, ‘9’,},

{‘*’, ‘0’, ‘#’,}
};

//Code that shows the keypad connections to the arduino terminals
byte rowPins[numRows] = {5, A0, 7, 8}; //Rows 0 to 3

byte colPins[numCols]= {2, 3, 4}; //Columns 0 to 3

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup() {
pinMode(A0,OUTPUT); // ???
digitalWrite(A0,HIGH);
pinMode(A3,OUTPUT); // ???
digitalWrite(A3,HIGH);
pinMode(A1,OUTPUT); // ???
digitalWrite(A1,HIGH);
pinMode(A2,OUTPUT); // ???
digitalWrite(A2,LOW);
pinMode(6,OUTPUT); // door opener
digitalWrite(6,LOW);

Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
Serial.println(“What did you say?:”);

//nfc
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card

// clear key
for (byte i = 0; i < 6; i++) {
key.keyByte = 0xFF;
}

// set LCD
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.clear();
lcd.print( “LOCKED” );
}

// extract NFC info
void citireNFC(){
for (byte i =0; i<(mfrc522.uid.size); i++) {
COD[i]=mfrc522.uid.uidByte; // was wrong missing [i] !!!
}
Serial.print(“COD”);
Serial.print(COD[0]);
Serial.print(COD[1]);
Serial.print(COD[2]);
Serial.print(COD[3]);

}

// add a new card in EEPROM (if not already there)
void pairNFC() {

Serial.println(“COD in pair”);
Serial.print(COD[0]);
Serial.print(COD[1]);
Serial.print(COD[2]);
Serial.print(COD[3]);
long r=0; //??? WHY
int c=0; // flag to save in EEPROM

// check COD is NOT already in
for(int i=1;i<=EEPROM.read(0);i++) {

switch(i%4){
  case 1 :{AUX[0]=EEPROM.read(i); break;}
  case 2 :{AUX[1]=EEPROM.read(i); break;}
  case 3 :{AUX[2]=EEPROM.read(i); break;:
  case 0 :{AUX[3]=EEPROM.read(i); break;}
}

if(i%4 == 0) {
  Serial.println(r);  //???????????????????????????? WHY?
    if(AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3] ){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("CODE ALREADY IN");
      lcd.setCursor(0,1);
      lcd.print("SYSTEM");
      delay(2000);
      c=1;      // indicate it is already in EEPROM
      break;
    }
  }
}

}

// if NOT yet in EEPROM
if(c == 0){
// get length last postion in EEPROM
// ??? NO CHECK ON MAXIMUM IN EEPROM ???
int ttt=EEPROM.read(0);

Serial.print("CODE PAIRED: ");
Serial.print(COD[0]);
Serial.print(COD[1]);
Serial.print(COD[2]);
Serial.println(COD[3]);

// write to EEPROM
EEPROM.write(ttt+1,COD[0]);
EEPROM.write(ttt+2,COD[1]);
EEPROM.write(ttt+3,COD[2]);
EEPROM.write(ttt+4,COD[3]);

// save new length
ttt=ttt+4;
Serial.println("ttt");
Serial.println(ttt);
EEPROM.write(0,0);
EEPROM.write(0,ttt);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("CODE PAIRED");
delay(2000);}

}

// check for COD match with stored in EEPROM
boolean validareNFC(){
boolean c=false;

// read complete EEPROM for match
for(int i=1;i<=EEPROM.read(0);i++){

  switch(i%4){
    case 1 :{AUX[0]=EEPROM.read(i); break;}
    case 2 :{AUX[1]=EEPROM.read(i); break;}
    case 3 :{AUX[2]=EEPROM.read(i); break;}
    case 0 :{AUX[3]=EEPROM.read(i); break;}
  }

  if(i%4 == 0) {
    if( AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3]) {
      c=true;
      break;
    }
  }

return c;
}

// check access code match
int comparareCOD(String a) {
if(a.equals(codacces)) return 1;
else if(a.equals(codpairing)) return 2;
else return 0;
}

// read keypad information
String iaCOD(char x) {
char vec[10];

vec[0]=x;

lcd.setCursor(0,0);
lcd.clear();
lcd.print(‘X’);

for(int i=1;i<8;i++) {
vec[i]=myKeypad.waitForKey(); // was wrong missing [i] !!!
lcd.print(‘X’);
}

vec[8]=NULL;
String str(vec);
return str;
}

void loop() {

/*??? THIS LOOKS LIKE A HARD CODED PASSWORD VALIDATION ??? */
//Start BT autentification
if(Serial.available()) {

char c = Serial.read();


  switch (state_bt) {

    case 1:
        if(c == '*') state_bt=2;
        else state_bt=1;
        break;

    case 2:
        if(c == '1') state_bt=3;
        else state_bt=1;
        break;

    case 3:
        if(c == '2') state_bt=4;
        else state_bt=1;
        break;

    case 4:
        if(c == '3') state_bt=5;
        else state_bt=1;
        break;

    case 5:
        if(c == '4') state_bt=6;
        else state_bt=1;
        break;

    case 6:
        if(c == '5') state_bt=7;
        else state_bt=1;
        break;

    case 7:
        if(c == '6') state_bt=8;
        else state_bt=1;
        break;

    case 8:
        if(c == '#') state_bt=9;
        else state_bt=1;
        break;

    case 9:

        lcd.init();
        lcd.backlight();
        lcd.print("OPEN");
        digitalWrite(6,LOW);
        delay(5000);
        digitalWrite(6,HIGH);
        lcd.init();
        lcd.backlight();
        lcd.print("BLOCKED");
        state_bt=1;
        break;

    default:
        state_bt=1;
        break;
  }
}   // end serialavailable()

//////////END BT Autentification

switch(stare){

// read and validate NFC or Keypad
case 0:
   mfrc522.PCD_Init();
   // check for NFC card
   if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){

     // extract COD
     citireNFC();

     // validate COD against EEPROM
     if(validareNFC()) {
        stare=1;        // open the door in the next loop
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("VALID NFC CODE");
        delay(1000);
        return;
     }
     else {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("INVALID NFC CODE");
        delay(1000);
        lcd.setCursor(0,0);
        lcd.clear();
        lcd.print("BLOCKED");
        return;
     }
   }

   // check keypad for access code
   char c = myKeypad.getKey();
   if(c != NO_KEY){

      // extract the keypad code
      String codcurent=iaCOD(c);

      int A=comparareCOD(codcurent);

      // neither entry access nor pair access code
      if(A == 0) {
         lcd.clear();
         lcd.print("INVALID CODE");
         delay(2000);
         lcd.setCursor(0,0);
         lcd.clear();
         lcd.print("BLOCKED");
         return;
      }
      // entry access code
      else if(A == 1) {
         lcd.setCursor(0,0);
         lcd.clear();
         lcd.print("VALID CODE");
         delay(2000);
         stare = 1;         // open the door
         return;
      }
      // pairing access code
      else if(A == 2) { // was wrong has ; at the end ???????????????
         stare=2;          // perform pairing
         lcd.clear();
         lcd.setCursor(0,0);
         lcd.print("Pairing...");
         delay(2000);
         return;
      }
     } // keypad check
     break;

  // open the door
  case 1:
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("UNLOCKED");
    digitalWrite(A3,LOW);       //???
    digitalWrite(A1,LOW);
    digitalWrite(A2,HIGH);
    //tone(6,3000,5010);

    digitalWrite(6,HIGH);       // door opener
    delay(2000);
    digitalWrite(6,LOW);

    digitalWrite(A3,HIGH);      //?????
    digitalWrite(A1,HIGH);
    digitalWrite(A2,LOW);

    stare=0;                    // reset to wait for NFC or KEYPAD
    lcd.setCursor(0,0);
    lcd.clear();
    lcd.print("BLOCKED");
    return;
    break;

 // perform pairing
 case 2:
    mfrc522.PCD_Init();

    if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){
      // extract card
      citireNFC();

      // store in EEPROM
      pairNFC();
      stare=0;                  // reset to wait for NFC or KEYPAD
      delay(2000);
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("BLOCKED");
    }
    break;
}

}


[/quotun



Sorry for the late response, thing have been hectic and I've not had the chance to even get on my pc till now :/



The changes have broken the sketch completely now and it won't even compile (it compiled before but only the keypad code would trigger an unlock) but your notes against so many things in the code have been a really big help to me in terms of learning what things mean in the code and learning is what I want to do!



I wish I could get this working , I'm getting so desperate that I'm tempted to run two separate nano's one to work the keypad and another to trigger an unlock on the RFID and tie them both to the same relay as there are sketches that work fine which are just RFID but none which are RFID or keypad code like this one I'm trying to get working.



The original creator has videos showing it working but she's obviously done something to the code since the sketch that she had running in her video and I've noticed differences in the code she put on her YouTube channel description vs what's on github.



She's not responding to messages on ether so I don't think I'll he getting any help from her unfortunately.



Steve.</QUOTE>

Just because I found this an interesting project, have the different parts and had some time available, I have build and tested a working solution. Make sure to read the top of the sketch for hardware connection and usage. I do not know what the following is doing in your code, so I have left that in.

  digitalWrite(A3,LOW);       // ?????? NEEDED ??
  digitalWrite(A1,LOW);
  digitalWrite(A2,HIGH);
/*
 * HARDWARE Connection on UNO
 *
 * LCD UNO
 * SCL  A5
 * SDA  A4
 * VCC  5v
 * GND  GND
 * 
 * MFC 522
 *            UNO              MFC522
 * Reset      9                RST
 * SPI SS     10               SDA
 * SPI MOSI   11               MOSI
 * SPI MISO   12               MISO
 * SPI SCK    13               SCK
 * GND        GND              GND
 * 
 * KEYPAD
 * 
 * ROW = {5, A0, 7, 8};      // Rows 0 to 4
 * Columns = {2, 3, 4};      // Columns 0 to 3
 * 
 * Dooropener activater
 * 
 * pin 6 of the UNO
 * 
 * USAGE
 * 
 * If this is the first time the program ever runs on this board, you need to clear the EEPROM count, as we 
 * do NOT know what is currently in the length location. Enter the codInitProm (defined below) on the 
 * keypad to set the length to zero. 
 * 
 * To prevent an EEPROM overrun, the maximum size of the EEPROM can be set with MAXPOSTEEPROM.
 * 
 * You first need to pair a NFC card in the system. Enter the codpairing (defined below) and 
 * then hold the card for the reader.
 * 
 * If you set TRIGGERMOMENT to EITHER. you can open the door with EITHER a valid NFC card or 
 * valid access password codacces (defined below). 
 * 
 * If you set TRIGGERMOMENT to BOTH. you can only open the door with BOTH a valid NFC card AND 
 * valid access password codacces (defined below). 
 * 
 * The access password codacces (defined below) can be entered from remote over the serial port to 
 * open the door as well.
 * 
 */

#include <EEPROM.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

//=================================================================
// passwords
//================================================================
String codacces="*123456#";    // entry access code keypad
String codpairing="*654321#";  // pairing access code
String codInitProm="##6655**"; // set EEPROM location to zero

//=================================================================
// dooropening parameters
//================================================================
// set TRIGGERMOMENT to 
//  EITHER to open the door with EITHER valid NFC OR valid password from keypad
//  BOTH to open the door with BOTH valid NFC AND valid password from keypad
#define EITHER  1            
#define BOTH    2
#define TRIGGERMOMENT  BOTH

//=================================================================
// NFC parameters
//================================================================
#define RST_PIN   9         // Configurable, see typical pin layout above
#define SS_PIN    10        // Configurable, see typical pin layout above
#define MAXPOSTEEPROM 1000  // Maximum size EEPROM in bytes

//=================================================================
// KEYPAD parameters
//================================================================
const byte numRows= 4;      // number of rows on the keypad
const byte numCols= 3;      // number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]= {
{'1', '2', '3',},
{'4', '5', '6',},
{'7', '8', '9',},
{'*', '0', '#',}};

//Code that shows  the keypad connections to the arduino terminals
byte rowPins[numRows] = {5, A0, 7, 8}; // Rows 0 to 4
byte colPins[numCols]= {2, 3, 4};      // Columns 0 to 3

/////////////////////////////////////////////////////////
// NO CHANGES NEEDED BEYOND THIS POINT                 //
/////////////////////////////////////////////////////////

//==============================================
// GLOBAL VARIABLES
//=============================================

int OpenDoorState=0;   // needed to track for BOTH NFC and keypad
int state_bt=0;        // Serial input state)
int stare=0;           // machine state for NFC / keypad
byte COD[10];          // store the NFC code
byte AUX[10];          // used for compare NFC code

//==============================================
// Initialize
//=============================================
//nfc
MFRC522 mfrc522(SS_PIN, RST_PIN);        // Create MFRC522 instance
MFRC522::MIFARE_Key key;

//lcd
LiquidCrystal_I2C  lcd(0x27,16,2);

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

//==============================================
// Start of program
//=============================================
void setup() {

  pinMode(A3,OUTPUT);          // ??? was in the original code 
  digitalWrite(A3,HIGH);
  pinMode(A1,OUTPUT);          // ???
  digitalWrite(A1,HIGH);
  pinMode(A2,OUTPUT);          // ???
  digitalWrite(A2,LOW);
  pinMode(6,OUTPUT);           // door opener
  digitalWrite(6,LOW);

  Serial.begin(9600);  // Initialize serial communications with the PC
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  Serial.println("What did you say?:");

  //nfc
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card

  // clear nfc key
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }

  // set LCD
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("BLOCKED");
}

//==============================================
// extract NFC info
//=============================================
void  citireNFC(){
  for (byte i =0; i<(mfrc522.uid.size); i++) {
    COD[i]=mfrc522.uid.uidByte[i];        
  }
  Serial.print("COD: ");
  Serial.print(COD[0],HEX);
  Serial.print(" ");
  Serial.print(COD[1],HEX);
  Serial.print(" ");
  Serial.print(COD[2],HEX);
  Serial.print(" ");
  Serial.println(COD[3],HEX);

}

//==============================================
// add a new card in EEPROM (if not already there)
//=============================================
void pairNFC() {

  Serial.print("COD to pair: ");
  Serial.print(COD[0],HEX);
  Serial.print(" ");
  Serial.print(COD[1],HEX);
  Serial.print(" ");
  Serial.print(COD[2],HEX);
  Serial.print(" ");
  Serial.println(COD[3]);
  
  boolean AlreadyInEEPROM = false;              // flag to save in EEPROM

  // check COD is NOT already in
  for(int i=1;i<=EEPROM.read(0);i++) {

    switch(i%4){
      case 1 :{AUX[0]=EEPROM.read(i); break;}
      case 2 :{AUX[1]=EEPROM.read(i); break;}
      case 3 :{AUX[2]=EEPROM.read(i); break;}
      case 0 :{AUX[3]=EEPROM.read(i); break;}
    }

    if(i%4 == 0) {
        if(AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3] ){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("CODE ALREADY IN");
          lcd.setCursor(0,1);
          lcd.print("SYSTEM");
          delay(2000);
          AlreadyInEEPROM=true;      // indicate it is already in EEPROM
          break;
        }
      }
    }

  if(! AlreadyInEEPROM){
    // get current last postion in EEPROM 
    int ttt=EEPROM.read(0);

    // check on Maximum size EEPROM
    if (ttt + 4 > MAXPOSTEEPROM){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("EEPROM IS FULL");
      delay(2000);
      
      //Serial.print("EEPROM IS FULL. Maximum positions ");
      //Serial.print(MAXPOSTEEPROM);
      
      return;
    }

    Serial.print("CODE PAIRED: ");
    Serial.print(COD[0],HEX);
    Serial.print(" ");
    Serial.print(COD[1],HEX);
    Serial.print(" ");
    Serial.print(COD[2],HEX);
    Serial.print(" ");
    Serial.println(COD[3]);

    // write to EEPROM
    EEPROM.write(ttt+1,COD[0]);
    EEPROM.write(ttt+2,COD[1]);
    EEPROM.write(ttt+3,COD[2]);
    EEPROM.write(ttt+4,COD[3]);

    // save new length
    ttt=ttt+4;
    EEPROM.write(0,0);
    EEPROM.write(0,ttt);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("CODE PAIRED");
    delay(2000);
  }
}
//==============================================
// reset EEPROM buffer (as we do not know what is in EEPROM count if we start from scratch)
//=============================================
void InitProm()
{
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("Clear EEPROM");
  // reset length
  EEPROM.write(0,0);
  
  delay(2000);
  
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("BLOCKED");
}

//==============================================
//check for COD match with stored in EEPROM
//=============================================
boolean validareNFC(){
   boolean c=false;

   // read complete EEPROM for match
   for(int i=1;i<=EEPROM.read(0);i++){

      switch(i%4){
        case 1 :{AUX[0]=EEPROM.read(i); break;}
        case 2 :{AUX[1]=EEPROM.read(i); break;}
        case 3 :{AUX[2]=EEPROM.read(i); break;}
        case 0 :{AUX[3]=EEPROM.read(i); break;}
      }

      if(i%4 == 0) {
        if( AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3]) {
          c=true;
          break;
        }
      }
  }
  return c;
}

//==============================================
// check code match
//=============================================
int comparareCOD(String a) {
  if(a.equals(codacces)) return 1;
  else if(a.equals(codpairing)) return 2;
  else if(a.equals(codInitProm)) return 3;
  else return 0;
}

//==============================================
// read keypad information
//=============================================
String iaCOD(char x) {
  char vec[10];

  vec[0]=x;
//Serial.print("got keypad ");
//Serial.println(vec[0]);
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print('X');

  for(int i=1;i<8;i++) {
    vec[i]=myKeypad.waitForKey();
//Serial.print("got keypad ");
//Serial.println(vec[i]);
    lcd.print('X');
  }

  vec[8]=NULL;
  String str(vec);
  return str;
}
//==============================================
// Open the door
//=============================================
void open_door()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("UNLOCKED");

  digitalWrite(A3,LOW);       // ?????? NEEDED ??
  digitalWrite(A1,LOW);
  digitalWrite(A2,HIGH);
  //tone(6,3000,5010);
 
  digitalWrite(6,LOW);
  delay(5000);
  digitalWrite(6,HIGH);

  digitalWrite(A3,HIGH);      // ????? NEEDED ??
  digitalWrite(A1,HIGH);
  digitalWrite(A2,LOW);

  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("BLOCKED");
}

//==============================================
// Main_loop
//=============================================
void loop() {

  //Start BT autentification
  if (Serial.available()) {

    char c = Serial.read();
      
      // do we have match 
      if (codacces[state_bt] == c) {
        state_bt++;
        
        // does the complete password match
        if (state_bt == codacces.length()) {
          open_door();
          state_bt = 0;   // reset for next round
        }
      }
      else
        state_bt = 0;    // reset wrong code
  }  // end serialavailable()

  switch(stare){

    // read and validate NFC or Keypad
    case 0:
     {
       mfrc522.PCD_Init();
       // check for NFC card
       if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){

         // extract COD
         citireNFC();

         // validate COD against EEPROM
         if(validareNFC()) {

            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("VALID NFC CODE");
            
            if (TRIGGERMOMENT == EITHER)  stare = 1;     // open the door in the next loop
            else if (OpenDoorState == 2)  stare = 1;     // if password was also detected now open the door
            else {
              OpenDoorState = 1;                         // indicate the card was detected
              lcd.setCursor(0,1);
              lcd.print("Need Password");
             }

             delay(1000);
            return;
         }
         else {
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("INVALID NFC CODE");
            delay(2000);
            lcd.setCursor(0,0);
            lcd.clear();
            lcd.print("BLOCKED");
            OpenDoorState = 0;                              // indicate the No valid card was detected
            return;
         }
       }

       // check keypad for access code
       char c = myKeypad.getKey();
       if(c != NO_KEY){

          // extract the keypad code
          String codcurent=iaCOD(c);

          int A=comparareCOD(codcurent);

          // None match to any of the passwords
          if(A == 0) {
             lcd.clear();
             lcd.print("INVALID CODE");
             delay(2000);
             lcd.setCursor(0,0);
             lcd.clear();
             lcd.print("BLOCKED");
             OpenDoorState = 0;                          // indicate the No valid password was detected
             return;
          }

          // entry access code
          else if(A == 1) {
             lcd.setCursor(0,0);
             lcd.clear();
             lcd.print("VALID CODE");

             if (TRIGGERMOMENT == EITHER)  stare = 1;    // open the door in the next loop
             else if (OpenDoorState == 1)  stare = 1;    // if NFC was also detected open the door
             else {
              OpenDoorState = 2;                         // indicate the Passwd was detected
              lcd.setCursor(0,1);
              lcd.print("Need card");
             }
             delay(1000);
             return;
          }
          
          // pairing access code
          else if(A == 2) {
             stare=2;               // perform pairing in next loop
             lcd.clear();
             lcd.setCursor(0,0);
             lcd.print("Pairing...");
             delay(1000);
             return;
          }
          
          // reset EEprom counter
          else if (A == 3) {
            InitProm();
          }   
         } // keypad check
         break;
       }
      // open the door
      case 1:
       {
        open_door();
        stare=0;                    // reset to wait for NFC or KEYPAD
        OpenDoorState = 0;          // indicate NO valid NFC nor Passwrd
        break;
      }
     
     // perform pairing
     case 2:
        mfrc522.PCD_Init();

        if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){
          
          // extract card
          citireNFC();

          // store in EEPROM
          pairNFC();
          stare=0;                  // reset to wait for NFC or KEYPAD
          OpenDoorState = 0;        // indicate NO valid NFC nor Password
          delay(2000);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("BLOCKED");
        }
        break;
     default :
      {
        Serial.print("Default. you should never get here.  stare = ");
        Serial.println(stare,HEX);
        break;
      }
    }
}

added the libraries used and removed some typo’s

/*
 * HARDWARE Connections with UNO
 *
 * LCD UNO
 * SCL  A5
 * SDA  A4
 * VCC  5v
 * GND  GND
 * 
 * MFC 522
 *            UNO              MFC522
 * Reset      9                RST
 * SPI SS     10               SDA
 * SPI MOSI   11               MOSI
 * SPI MISO   12               MISO
 * SPI SCK    13               SCK
 * GND        GND              GND
 * 
 * KEYPAD
 * 
 * ROW = {5, A0, 7, 8};      // Rows 0 to 4
 * Columns = {2, 3, 4};      // Columns 0 to 3
 * 
 * Dooropener activator
 * 
 * pin 6 of the UNO (defined by DOORPIN)
 * 
 * USAGE
 * 
 * If this is the first time the program ever runs on this board, you need to clear the EEPROM count, as we 
 * do NOT know what is currently in the length location. Enter the codInitProm (defined below) on the 
 * keypad to set the length to zero. 
 * 
 * TO prevent an EEPROM overrun, the maximum size of the EEPROM can be set with MAXPOSTEEPROM.
 * 
 * You first need to pair a NFC card in the system. Enter the codpairing (defined below) and 
 * then hold the card for the reader.
 * 
 * If you set TRIGGERMOMENT to EITHER. you can open the door with EITHER a valid NFC card or 
 * valid access password codacces (defined below). 
 * 
 * If you set TRIGGERMOMENT to BOTH. you can only open the door with BOTH a valid NFC card AND 
 * valid access password codacces (defined below). 
 * 
 * The access password codacces (defined below) can be entered from remote over the serial port to 
 * open the door as well.
 * 
 * Extra libraries needed :
 * 
 * https://github.com/Chris--A/Keypad
 * http://playground.arduino.cc/Code/Keypad 
 * 
 * https://www.makerguides.com/character-i2c-lcd-arduino-tutorial/
 * https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c
 * https://github.com/marcoschwartz/LiquidCrystal_I2C 
 * 
 * https://playground.arduino.cc/Learning/MFRC522/
 * https://github.com/miguelbalboa/rfid
 * 
 */

#include <EEPROM.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

//=================================================================
// passwords
//================================================================
String codacces="*123456#";    // entry access code keypad
String codpairing="*654321#";  // pairing access code
String codInitProm="##6655**"; // set EEPROM location to zero

//=================================================================
// dooropening parameters
//================================================================
// set TRIGGERMOMENT to 
//  EITHER to open the door with EITHER valid NFC OR valid password from keypad
//  BOTH to open the door with BOTH valid NFC AND valid password from keypad
#define EITHER  1            
#define BOTH    2
#define TRIGGERMOMENT  BOTH

// Dooropener connection
#define DOORPIN 6

// Dooropener time (mS)
#define DOOR_OPEN_TIME 5000

//=================================================================
// NFC parameters
//================================================================
#define RST_PIN   9         // Configurable, see typical pin layout above
#define SS_PIN    10        // Configurable, see typical pin layout above
#define MAXPOSTEEPROM 1000  // Maximum size EEPROM in bytes

//=================================================================
// KEYPAD parameters
//================================================================
const byte numRows= 4;      // number of rows on the keypad
const byte numCols= 3;      // number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]= {
{'1', '2', '3',},
{'4', '5', '6',},
{'7', '8', '9',},
{'*', '0', '#',}};

//Code that shows  the keypad connections to the arduino terminals
byte rowPins[numRows] = {5, A0, 7, 8}; // Rows 0 to 4
byte colPins[numCols]= {2, 3, 4};      // Columns 0 to 3

/////////////////////////////////////////////////////////
// NO CHANGES NEEDED BEYOND THIS POINT                 //
/////////////////////////////////////////////////////////

//==============================================
// GLOBAL VARIABLES
//=============================================

int OpenDoorState=0;   // needed to track for BOTH NFC and keypad
int state_bt=0;        // Serial input state)
int stare=0;           // machine state for NFC / keypad
byte COD[10];          // store the NFC code
byte AUX[10];          // used for compare NFC code

//==============================================
// Initialize
//=============================================
//nfc
MFRC522 mfrc522(SS_PIN, RST_PIN);        // Create MFRC522 instance
MFRC522::MIFARE_Key key;

//lcd
LiquidCrystal_I2C  lcd(0x27,16,2);

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

//==============================================
// Start of program
//=============================================
void setup() {

  pinMode(A3,OUTPUT);          // ??? was in the original code 
  digitalWrite(A3,HIGH);
  pinMode(A1,OUTPUT);          // ???
  digitalWrite(A1,HIGH);
  pinMode(A2,OUTPUT);          // ???
  digitalWrite(A2,LOW);
  pinMode(DOORPIN,OUTPUT);           // door opener
  digitalWrite(DOORPIN,LOW);

  Serial.begin(9600);  // Initialize serial communications with the PC
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  Serial.println("What did you say?:");

  //nfc
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card

  // clear nfc key
  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }

  // set LCD
  lcd.init();
  lcd.backlight();
  blocked(0);
}

//==============================================
// Print LCD blocked after delay
//=============================================
void blocked(unsigned long t)
{
  if (t) delay(t);
  
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("BLOCKED");
}

//==============================================
// extract NFC info
//=============================================
void  citireNFC(){
  for (byte i =0; i<(mfrc522.uid.size); i++) {
    COD[i]=mfrc522.uid.uidByte[i];        
  }
  Serial.print("COD: ");
  Serial.print(COD[0],HEX);
  Serial.print(" ");
  Serial.print(COD[1],HEX);
  Serial.print(" ");
  Serial.print(COD[2],HEX);
  Serial.print(" ");
  Serial.println(COD[3],HEX);

}

//==============================================
// add a new card in EEPROM (if not already there)
//=============================================
void pairNFC() {

  Serial.print("COD to pair: ");
  Serial.print(COD[0],HEX);
  Serial.print(" ");
  Serial.print(COD[1],HEX);
  Serial.print(" ");
  Serial.print(COD[2],HEX);
  Serial.print(" ");
  Serial.println(COD[3]);
  
  boolean AlreadyInEEPROM = false;              // flag to save in EEPROM

  // check COD is NOT already in
  for(int i=1;i<=EEPROM.read(0);i++) {

    switch(i%4){
      case 1 :{AUX[0]=EEPROM.read(i); break;}
      case 2 :{AUX[1]=EEPROM.read(i); break;}
      case 3 :{AUX[2]=EEPROM.read(i); break;}
      case 0 :{AUX[3]=EEPROM.read(i); break;}
    }

    if(i%4 == 0) {
        if(AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3] ){
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("CODE ALREADY IN");
          lcd.setCursor(0,1);
          lcd.print("SYSTEM");
          delay(2000);
          AlreadyInEEPROM=true;      // indicate it is already in EEPROM
          break;
        }
      }
    }

  if(! AlreadyInEEPROM){
    // get current last postion in EEPROM 
    int ttt=EEPROM.read(0);

    // check on Maximum size EEPROM
    if (ttt + 4 > MAXPOSTEEPROM){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("EEPROM IS FULL");
      delay(2000);
      
      //Serial.print("EEPROM IS FULL. Maximum positions ");
      //Serial.print(MAXPOSTEEPROM);
      
      return;
    }

    Serial.print("CODE PAIRED: ");
    Serial.print(COD[0],HEX);
    Serial.print(" ");
    Serial.print(COD[1],HEX);
    Serial.print(" ");
    Serial.print(COD[2],HEX);
    Serial.print(" ");
    Serial.println(COD[3]);

    // write to EEPROM
    EEPROM.write(ttt+1,COD[0]);
    EEPROM.write(ttt+2,COD[1]);
    EEPROM.write(ttt+3,COD[2]);
    EEPROM.write(ttt+4,COD[3]);

    // save new length
    ttt=ttt+4;
    EEPROM.write(0,0);
    EEPROM.write(0,ttt);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("CODE PAIRED");
    delay(2000);
  }
}
//==============================================
// reset EEPROM buffer (as we do not know what is in EEPROM count if we start from scratch)
//=============================================
void InitProm()
{
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print("Clear EEPROM");

  // reset length
  EEPROM.write(0,0);

  blocked(2000);
}

//==============================================
//check for COD match with stored in EEPROM
//=============================================
boolean validareNFC(){
   boolean c=false;

   // read complete EEPROM for match
   for(int i=1;i<=EEPROM.read(0);i++){

      switch(i%4){
        case 1 :{AUX[0]=EEPROM.read(i); break;}
        case 2 :{AUX[1]=EEPROM.read(i); break;}
        case 3 :{AUX[2]=EEPROM.read(i); break;}
        case 0 :{AUX[3]=EEPROM.read(i); break;}
      }

      if(i%4 == 0) {
        if( AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3]) {
          c=true;
          break;
        }
      }
  }
  return c;
}

//==============================================
// check code match
//=============================================
int comparareCOD(String a) {
  if(a.equals(codacces)) return 1;
  else if(a.equals(codpairing)) return 2;
  else if(a.equals(codInitProm)) return 3;
  else return 0;
}

//==============================================
// read keypad information
//=============================================
String iaCOD(char x) {
  char vec[10];

  vec[0]=x;
//Serial.print("got keypad ");
//Serial.println(vec[0]);
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print('X');

  for(int i=1;i<8;i++) {
    vec[i]=myKeypad.waitForKey();
//Serial.print("got keypad ");
//Serial.println(vec[i]);
    lcd.print('X');
  }

  vec[8]=NULL;
  String str(vec);
  return str;
}
//==============================================
// Open the door
//=============================================
void open_door()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("UNLOCKED");

  digitalWrite(A3,LOW);       // ?????? NEEDED ??
  digitalWrite(A1,LOW);
  digitalWrite(A2,HIGH);
  //tone(6,3000,5010);
 
  digitalWrite(DOORPIN,HIGH); // open door
  delay(DOOR_OPEN_TIME);
  digitalWrite(DOORPIN,LOW);

  digitalWrite(A3,HIGH);      // ????? NEEDED ??
  digitalWrite(A1,HIGH);
  digitalWrite(A2,LOW);

  blocked(0);
}

//==============================================
// Main_loop
//=============================================
void loop() {

  //Start BT autentification
  if (Serial.available()) {

    char c = Serial.read();
      
      // do we have match 
      if (codacces[state_bt] == c) {
        state_bt++;
        
        // does the complete password match
        if (state_bt == codacces.length()) {
          open_door();
          state_bt = 0;   // reset for next round
        }
      }
      else
        state_bt = 0;    // reset wrong code
  }  // end serialavailable()

  switch(stare){

    // read and validate NFC or Keypad
    case 0:
     {
       mfrc522.PCD_Init();
       // check for NFC card
       if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){

         // extract COD
         citireNFC();

         // validate COD against EEPROM
         if(validareNFC()) {

            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("VALID NFC CODE");
            
            if (TRIGGERMOMENT == EITHER)  stare = 1;     // open the door in the next loop
            else if (OpenDoorState == 2)  stare = 1;     // if password was also detected now open the door
            else {
              OpenDoorState = 1;                         // indicate the card was detected
              lcd.setCursor(0,1);
              lcd.print("Need Password");
             }

            delay(1000);
            return;
         }
         else {
            lcd.clear();
            lcd.setCursor(0,0);
            lcd.print("INVALID NFC CODE");
            blocked(2000);
            OpenDoorState = 0;                           // indicate the No valid card was detected
            return;
         }
       }

       // check keypad for access code
       char c = myKeypad.getKey();
       if(c != NO_KEY){

          // extract the keypad code
          String codcurent=iaCOD(c);

          int A=comparareCOD(codcurent);

          // None match to any of the passwords
          if(A == 0) {
             lcd.clear();
             lcd.print("INVALID CODE");
             blocked(2000);
             OpenDoorState = 0;                          // indicate the No valid password was detected
             return;
          }

          // entry access code
          else if(A == 1) {
             lcd.setCursor(0,0);
             lcd.clear();
             lcd.print("VALID CODE");

             if (TRIGGERMOMENT == EITHER)  stare = 1;    // open the door in the next loop
             else if (OpenDoorState == 1)  stare = 1;    // if NFC was also detected open the door
             else {
              OpenDoorState = 2;                         // indicate the Passwd was detected
              lcd.setCursor(0,1);
              lcd.print("Need card");
             }
             delay(1000);
             return;
          }
          
          // pairing access code
          else if(A == 2) {
             stare=2;               // perform pairing in next loop
             lcd.clear();
             lcd.setCursor(0,0);
             lcd.print("Pairing...");
             delay(1000);
             return;
          }
          
          // reset EEprom counter
          else if (A == 3) {
            InitProm();
          }   
         } // keypad check
         break;
       }
      // open the door
      case 1:
       {
        open_door();
        stare=0;                    // reset to wait for NFC or KEYPAD
        OpenDoorState = 0;          // indicate NO valid NFC nor Passwrd
        break;
      }
     
     // perform pairing
     case 2:
        mfrc522.PCD_Init();

        if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){
          
          // extract card
          citireNFC();

          // store in EEPROM
          pairNFC();
          stare=0;                  // reset to wait for NFC or KEYPAD
          OpenDoorState = 0;        // indicate NO valid NFC nor Password
          blocked(2000);
        }
        break;
     default :
      {
        Serial.print("Default. you should never get here.  stare = ");
        Serial.println(stare,HEX);
        break;
      }
    }
}

paulvha:
added the libraries used and removed some typo’s

/*

*/

#include <EEPROM.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>

//=================================================================
// passwords
//================================================================
String codacces=“123456#"; // entry access code keypad
String codpairing="654321#“; // pairing access code
String codInitProm=”##6655
”; // set EEPROM location to zero

//=================================================================
// dooropening parameters
//================================================================
// set TRIGGERMOMENT to
// EITHER to open the door with EITHER valid NFC OR valid password from keypad
// BOTH to open the door with BOTH valid NFC AND valid password from keypad
#define EITHER 1
#define BOTH 2
#define TRIGGERMOMENT BOTH

// Dooropener connection
#define DOORPIN 6

// Dooropener time (mS)
#define DOOR_OPEN_TIME 5000

//=================================================================
// NFC parameters
//================================================================
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
#define MAXPOSTEEPROM 1000 // Maximum size EEPROM in bytes

//=================================================================
// KEYPAD parameters
//================================================================
const byte numRows= 4; // number of rows on the keypad
const byte numCols= 3; // number of columns on the keypad

//keymap defines the key pressed according to the row and columns just as appears on the keypad
char keymap[numRows][numCols]= {
{‘1’, ‘2’, ‘3’,},
{‘4’, ‘5’, ‘6’,},
{‘7’, ‘8’, ‘9’,},
{‘*’, ‘0’, ‘#’,}};

//Code that shows the keypad connections to the arduino terminals
byte rowPins[numRows] = {5, A0, 7, 8}; // Rows 0 to 4
byte colPins[numCols]= {2, 3, 4}; // Columns 0 to 3

/////////////////////////////////////////////////////////
// NO CHANGES NEEDED BEYOND THIS POINT //
/////////////////////////////////////////////////////////

//==============================================
// GLOBAL VARIABLES
//=============================================

int OpenDoorState=0; // needed to track for BOTH NFC and keypad
int state_bt=0; // Serial input state)
int stare=0; // machine state for NFC / keypad
byte COD[10]; // store the NFC code
byte AUX[10]; // used for compare NFC code

//==============================================
// Initialize
//=============================================
//nfc
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
MFRC522::MIFARE_Key key;

//lcd
LiquidCrystal_I2C lcd(0x27,16,2);

//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

//==============================================
// Start of program
//=============================================
void setup() {

pinMode(A3,OUTPUT); // ??? was in the original code
digitalWrite(A3,HIGH);
pinMode(A1,OUTPUT); // ???
digitalWrite(A1,HIGH);
pinMode(A2,OUTPUT); // ???
digitalWrite(A2,LOW);
pinMode(DOORPIN,OUTPUT); // door opener
digitalWrite(DOORPIN,LOW);

Serial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
Serial.println(“What did you say?:”);

//nfc
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card

// clear nfc key
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}

// set LCD
lcd.init();
lcd.backlight();
blocked(0);
}

//==============================================
// Print LCD blocked after delay
//=============================================
void blocked(unsigned long t)
{
if (t) delay(t);

lcd.setCursor(0,0);
lcd.clear();
lcd.print(“BLOCKED”);
}

//==============================================
// extract NFC info
//=============================================
void citireNFC(){
for (byte i =0; i<(mfrc522.uid.size); i++) {
COD[i]=mfrc522.uid.uidByte[i];
}
Serial.print("COD: “);
Serial.print(COD[0],HEX);
Serial.print(” “);
Serial.print(COD[1],HEX);
Serial.print(” “);
Serial.print(COD[2],HEX);
Serial.print(” ");
Serial.println(COD[3],HEX);

}

//==============================================
// add a new card in EEPROM (if not already there)
//=============================================
void pairNFC() {

Serial.print("COD to pair: “);
Serial.print(COD[0],HEX);
Serial.print(” “);
Serial.print(COD[1],HEX);
Serial.print(” “);
Serial.print(COD[2],HEX);
Serial.print(” ");
Serial.println(COD[3]);

boolean AlreadyInEEPROM = false; // flag to save in EEPROM

// check COD is NOT already in
for(int i=1;i<=EEPROM.read(0);i++) {

switch(i%4){
  case 1 :{AUX[0]=EEPROM.read(i); break;}
  case 2 :{AUX[1]=EEPROM.read(i); break;}
  case 3 :{AUX[2]=EEPROM.read(i); break;}
  case 0 :{AUX[3]=EEPROM.read(i); break;}
}

if(i%4 == 0) {
    if(AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3] ){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("CODE ALREADY IN");
      lcd.setCursor(0,1);
      lcd.print("SYSTEM");
      delay(2000);
      AlreadyInEEPROM=true;      // indicate it is already in EEPROM
      break;
    }
  }
}

if(! AlreadyInEEPROM){
// get current last postion in EEPROM
int ttt=EEPROM.read(0);

// check on Maximum size EEPROM
if (ttt + 4 > MAXPOSTEEPROM){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("EEPROM IS FULL");
  delay(2000);
  
  //Serial.print("EEPROM IS FULL. Maximum positions ");
  //Serial.print(MAXPOSTEEPROM);
  
  return;
}

Serial.print("CODE PAIRED: ");
Serial.print(COD[0],HEX);
Serial.print(" ");
Serial.print(COD[1],HEX);
Serial.print(" ");
Serial.print(COD[2],HEX);
Serial.print(" ");
Serial.println(COD[3]);

// write to EEPROM
EEPROM.write(ttt+1,COD[0]);
EEPROM.write(ttt+2,COD[1]);
EEPROM.write(ttt+3,COD[2]);
EEPROM.write(ttt+4,COD[3]);

// save new length
ttt=ttt+4;
EEPROM.write(0,0);
EEPROM.write(0,ttt);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("CODE PAIRED");
delay(2000);

}
}
//==============================================
// reset EEPROM buffer (as we do not know what is in EEPROM count if we start from scratch)
//=============================================
void InitProm()
{
lcd.setCursor(0,0);
lcd.clear();
lcd.print(“Clear EEPROM”);

// reset length
EEPROM.write(0,0);

blocked(2000);
}

//==============================================
//check for COD match with stored in EEPROM
//=============================================
boolean validareNFC(){
boolean c=false;

// read complete EEPROM for match
for(int i=1;i<=EEPROM.read(0);i++){

  switch(i%4){
    case 1 :{AUX[0]=EEPROM.read(i); break;}
    case 2 :{AUX[1]=EEPROM.read(i); break;}
    case 3 :{AUX[2]=EEPROM.read(i); break;}
    case 0 :{AUX[3]=EEPROM.read(i); break;}
  }

  if(i%4 == 0) {
    if( AUX[0]==COD[0] && AUX[1]==COD[1] && AUX[2]==COD[2] && AUX[3]==COD[3]) {
      c=true;
      break;
    }
  }

}
return c;
}

//==============================================
// check code match
//=============================================
int comparareCOD(String a) {
if(a.equals(codacces)) return 1;
else if(a.equals(codpairing)) return 2;
else if(a.equals(codInitProm)) return 3;
else return 0;
}

//==============================================
// read keypad information
//=============================================
String iaCOD(char x) {
char vec[10];

vec[0]=x;
//Serial.print("got keypad ");
//Serial.println(vec[0]);
lcd.setCursor(0,0);
lcd.clear();
lcd.print(‘X’);

for(int i=1;i<8;i++) {
vec[i]=myKeypad.waitForKey();
//Serial.print("got keypad ");
//Serial.println(vec[i]);
lcd.print(‘X’);
}

vec[8]=NULL;
String str(vec);
return str;
}
//==============================================
// Open the door
//=============================================
void open_door()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“UNLOCKED”);

digitalWrite(A3,LOW); // ??? NEEDED ??
digitalWrite(A1,LOW);
digitalWrite(A2,HIGH);
//tone(6,3000,5010);

digitalWrite(DOORPIN,HIGH); // open door
delay(DOOR_OPEN_TIME);
digitalWrite(DOORPIN,LOW);

digitalWrite(A3,HIGH); // ??? NEEDED ??
digitalWrite(A1,HIGH);
digitalWrite(A2,LOW);

blocked(0);
}

//==============================================
// Main_loop
//=============================================
void loop() {

//Start BT autentification
if (Serial.available()) {

char c = Serial.read();
  
  // do we have match 
  if (codacces[state_bt] == c) {
    state_bt++;
    
    // does the complete password match
    if (state_bt == codacces.length()) {
      open_door();
      state_bt = 0;   // reset for next round
    }
  }
  else
    state_bt = 0;    // reset wrong code

} // end serialavailable()

switch(stare){

// read and validate NFC or Keypad
case 0:
 {
   mfrc522.PCD_Init();
   // check for NFC card
   if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){

     // extract COD
     citireNFC();

     // validate COD against EEPROM
     if(validareNFC()) {

        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("VALID NFC CODE");
        
        if (TRIGGERMOMENT == EITHER)  stare = 1;     // open the door in the next loop
        else if (OpenDoorState == 2)  stare = 1;     // if password was also detected now open the door
        else {
          OpenDoorState = 1;                         // indicate the card was detected
          lcd.setCursor(0,1);
          lcd.print("Need Password");
         }

        delay(1000);
        return;
     }
     else {
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("INVALID NFC CODE");
        blocked(2000);
        OpenDoorState = 0;                           // indicate the No valid card was detected
        return;
     }
   }

   // check keypad for access code
   char c = myKeypad.getKey();
   if(c != NO_KEY){

      // extract the keypad code
      String codcurent=iaCOD(c);

      int A=comparareCOD(codcurent);

      // None match to any of the passwords
      if(A == 0) {
         lcd.clear();
         lcd.print("INVALID CODE");
         blocked(2000);
         OpenDoorState = 0;                          // indicate the No valid password was detected
         return;
      }

      // entry access code
      else if(A == 1) {
         lcd.setCursor(0,0);
         lcd.clear();
         lcd.print("VALID CODE");

         if (TRIGGERMOMENT == EITHER)  stare = 1;    // open the door in the next loop
         else if (OpenDoorState == 1)  stare = 1;    // if NFC was also detected open the door
         else {
          OpenDoorState = 2;                         // indicate the Passwd was detected
          lcd.setCursor(0,1);
          lcd.print("Need card");
         }
         delay(1000);
         return;
      }
      
      // pairing access code
      else if(A == 2) {
         stare=2;               // perform pairing in next loop
         lcd.clear();
         lcd.setCursor(0,0);
         lcd.print("Pairing...");
         delay(1000);
         return;
      }
      
      // reset EEprom counter
      else if (A == 3) {
        InitProm();
      }   
     } // keypad check
     break;
   }
  // open the door
  case 1:
   {
    open_door();
    stare=0;                    // reset to wait for NFC or KEYPAD
    OpenDoorState = 0;          // indicate NO valid NFC nor Passwrd
    break;
  }
 
 // perform pairing
 case 2:
    mfrc522.PCD_Init();

    if ( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){
      
      // extract card
      citireNFC();

      // store in EEPROM
      pairNFC();
      stare=0;                  // reset to wait for NFC or KEYPAD
      OpenDoorState = 0;        // indicate NO valid NFC nor Password
      blocked(2000);
    }
    break;
 default :
  {
    Serial.print("Default. you should never get here.  stare = ");
    Serial.println(stare,HEX);
    break;
  }
}

}

Wow, thank you so much for taking so much time to look Into it!

I had to come on here and check once I’m in bed, I’ve gotta wait till tomorrow to try it out now, sob.

I will want the ‘ether’ option as I want to be able to use one or the other, something other projects don’t allow and every dam code I’ve found requires a RFID tag and then a passcode!

I have the cards and tags which came with the two RFID modules I have but I plan on using a sticker inside my phone case as I have a bunch of them sitting around which I bought for triggering things on my phone.

Technically my phone can be a tag itself but would involve going into a nfc menu each time to trigger it so a sticker in the case is far more convenient.

Thanks again for looking at this for me, ill report back tomorrow once ive had a chance to run the code.

Steve.

paulvha:
added the libraries used and removed some typo’s

Again, a massive, massive thanks for what you have done.

Its working exactly how it should now and you have taken time to re write significant parts of the code, something you didn’t have to do but chose to do out of being nice.

It’s not a much, I’m not a very well off person but if you want to send me the email tied to your PayPal I’m happy to send you £5 as a thanks for your time :slight_smile:

In you notes against parts of the code you mentioned A1, A2 and A3 stating it was in original code and needed?

I’m glad you left it in, they are for led and buzzer control.

I’ve had to change A3 to low as default (original code was wrong and had high) as you want two pins low normally which go high on an unlock for a green led and the buzzer and one pin high normally which is the red led and goes low on unlock but that was an easy change for me.

I see the Bluetooth was stripped out completely from the code, I really didn’t see the point in it being there other than a novelty, it was broken anyway (it was meant to send the regular keypad access code over the UART pins using an android app) but even if it worked, it would have taken 4x longer to open the app, connect to the Bluetooth module and then send the code and seemed absolutely pointless!

I have made a 3d printed case for all the main electronics and a separate window case for the RC522 with a little diffused led block in it and have a ultra heavy duty water and vandal proof keypad which I got for an absolute bargain price to go outside, vandals are not a concern but its well engineered and designed to endure heavy use.

I paid less than 1/5 of the price everyone else is charging for it and couldn’t have afforded to spend what it normally goes for and was originally trying to figure out if I could waterproof one of those cheap black arduino keypads lol.

Everything is built and wired up internally , I just need to fit the control and RFID boxes into their permanent locations, plug the keypad and solenoid lock in and supply the setup with 12v which happens to pass right by it on its way to a CCTV camera which is handy :wink:

I made sure the solenoid lock was a ‘fail secure’ type, if anything goes wrong with the system, the door will remain locked unless a fault energises the relay.

Should have everything in its permanent locations and fully functional tomorrow, maybe I’ll post a video, I’ll leave the keypad code as default and then change it to my actual choice of code after.

That reminds me, the code is a 8 digit job, it can be anything and does jot need to include * or # as long as its 8 characters long but any code less than 8 characters fails, can I change anything in the code to allow 6 character codes or is that a large re wife of something to make it work?

It its 8 then its 8 but if its easy to change it to 6 then I’ll do it :slight_smile:

Steve.

hi steve

I have NOT removed the option to enter the access key with Bluetooth. I has been changed to validate the access key in a different way. You can try to enter the access key with the serial monitor. YOu can of course take it out if not needed

You can change the length of the passwords, but all passwords MUST have the SAME length. If you want 6 digits change the following routine in your code

//==============================================
// read keypad information
//=============================================
String iaCOD(char x) {
  char vec[10];

  vec[0]=x;
//Serial.print("got keypad ");
//Serial.println(vec[0]);
  lcd.setCursor(0,0);
  lcd.clear();
  lcd.print('X');

  for(int i=1;i<6;i++) {
    vec[i]=myKeypad.waitForKey();
//Serial.print("got keypad ");
//Serial.println(vec[i]);
    lcd.print('X');
  }

  vec[6]=0x0;
  String str(vec);
  return str;
}

Just because I found it fun project I have made more changes to make a generic code and created a write-up which is posted on https://github.com/paulvha/dooropener for others to find. One can also change the access password without recompile, by enter a special other password. E.g. you can set a temporarily password when you go on vacation and someone looks after your house, or your access password is too widely known by others and you want to reduce the people who can access. You can also toggle between EITHER or BOTH without recompile. This can be handy if you want to change the access security level on a certain moment.

paulvha:
hi steve

I have NOT removed the option to enter the access key with Bluetooth. I has been changed to validate the access key in a different way. You can try to enter the access key with the serial monitor. YOu can of course take it out if not needed

You can change the length of the passwords, but all passwords MUST have the SAME length. If you want 6 digits change the following routine in your code

//==============================================

// read keypad information
//=============================================
String iaCOD(char x) {
char vec[10];

vec[0]=x;
//Serial.print("got keypad ");
//Serial.println(vec[0]);
lcd.setCursor(0,0);
lcd.clear();
lcd.print(‘X’);

for(int i=1;i<6;i++) {
vec[i]=myKeypad.waitForKey();
//Serial.print("got keypad ");
//Serial.println(vec[i]);
lcd.print(‘X’);
}

vec[6]=0x0;
String str(vec);
return str;
}




Just because I found it fun project I have made more changes to make a generic code and created a write-up which is posted on [https://github.com/paulvha/dooropener](https://github.com/paulvha/dooropener) for others to find. One can also change<B> **the access password without recompile**</B>, by enter a special other password. E.g. you can set a temporarily password when you go on vacation and someone looks after your house, or your access password is too widely known by others and you want to reduce the people who can access. You can also<B> **toggle between EITHER or BOTH without recompile**</B>. This can be handy if you want to change the access security level on a certain moment.

Thanks , I’ll change it too a 6 character string, 8 is a bit long.

After re reading over the code, I have found the Bluetooth, it just has a fleeting reference too it now which is why I missed it, in The original code it was quite obvious.

That said, its not something I plan to use .

I’ve just tried ataching the android app which sends the code access code over Bluetooth to this post in case anyone wants to play with it but it give me an error unfortunately.

I’m heading straight over to your post to check out what you have done, I’m likely going to flash that code as what you have described is appealing :wink:

Edit: I’ve uploaded the android bkuetooth app to github if anybody wants to play with it, here’s a link: https://github.com/stevefoxuk/bluetooth-app/tree/master

paulvha:
.

I’ve run into a new problem :frowning:

I was finding that the RFID would work once and sometimes a few times and then stop responding and playing around I found it made no difference is the reset pin was tied to D9 of the arduino or not.

Hmmm, I thought and cracked out the multi meter.

I found that pin 9 on the arduino is pulsing between 3.3 and 0v at a rate of around 200-300ms per state.

Next I measured the reset pin on the RC522 and found a steady 3.3v!

I have two ow these RC522 units and both are the same, 3.3v on the reset pin.

Grounding the reset pin momentarily resets the RC522 and it responds to a tag again, sometimes more than once but usually it needs to be reset by grounding that pin after each tag read.

Is there a way to make ether the reset pin 9 on the arduino or any other pin go to ground to reset the RC522 or can arduino pins only go 0-5v?

I have already figured out that I could use a pinmode digital write high to trigger an NPN transistor to give the RC522 the ground it expects but I’ll need to add a delay as I’ve found that it only responds to a reset action at the end of an unlock.

I tried the new code from your github and like it a lot and that’s what is now running on the system, I added the A1,A2 and A3 pins in to control LEDs and the buzzer and Ive already tried using the green unlocked led transistors ground output to reset the RC522 and it ignores it and only responds to ground after its gone back to locked again unfortunately

If arduino pins can go to ground it would be a lot easier than messing with adding a transistor.

I think the problem is that mfrc522.PCD_Init() is called as part of the loop in case 0 and case 2, while it is only necessary to call that once in setup. It is causing the reset pin to be triggered and reinitialize the registers. comment out the mfrc522.PCD_Init() except for in setup()

paulvha:
I think the problem is that mfrc522.PCD_Init() is called as part of the loop in case 0 and case 2, while it is only necessary to call that once in setup. It is causing the reset pin to be triggered and reinitialize the registers. comment out the mfrc522.PCD_Init() except for in setup()

I found mfrc522.PCD_Init() in two places other than in setup and tried commenting both out and then one at a time and in all cases it breaks communication with the RC522 completely unfortunately.

I also tried adding a digital write high then low to A6 with a delay after the door open script to actuate a npn transistor to ground the reset pin on the RC522 but the code sees it as part of the main script and it does not influence the RC522 as its kept in a state by the code which makes the reset ignored.

I also tried to tie the transistor to the reset pin on the arduino but for some reason it only as any affect if I’m touching the connection, that has me baffled as the reset using the transistor works fine if I trigger the transistor with a regular 5v source.

I have a 10k pull down between the gate and source and I have a 10k on the gate lead going to the arduino, I might play with the gate lead value and see if it makes any difference.

I know its a long way to do it but I have such little experience with arduino code that I can’t write it myself and only manage to edit certain stuff so if all else fails I’ll just set A6 as a duplicate of the A3 I use for the green led and I’ll use a 555 ic to trigger the reset with a delay after the door unlock script has fully run and returned to its standby state.

I get that a lot of people could easily write it into the code but I’m not close to that yet and adding pinmodes and digital writes ect into existing code sections is my current limit of ability.

I’m slowly learning things and people like you giving pointers on specific things and the notes against code sections are a real help, learning in little steps on how existing code works is the only way I’ve been able to pick any of this up as looking at the ‘mechanics’ of code is a lot easier than trying to learn how to write it from guides :slight_smile:

Edit: I’ve been thinking about how I can get a regular output repeatedly activating Independently and not influencing the main code, I will do some playing around later as I think I might have figured it out, hopefully I learn something new :slight_smile:

stevefox:

paulvha:
I think the problem is that mfrc522.PCD_Init() is called as part of the loop in case 0 and case 2, while it is only necessary to call that once in setup. It is causing the reset pin to be triggered and reinitialize the registers. comment out the mfrc522.PCD_Init() except for in setup()

I found mfrc522.PCD_Init() in two places other than in setup and tried commenting both out and then one at a time and in all cases it breaks communication with the RC522 completely unfortunately.

I also tried adding a digital write high then low to A6 with a delay after the door open script to actuate a npn transistor to ground the reset pin on the RC522 but the code sees it as part of the main script and it does not influence the RC522 as its kept in a state by the code which makes the reset be ignored.

I also tried to tie the transistor to the reset pin on the arduino but for some reason it only as any affect if I’m touching the connection, that has me baffled as the reset using the transistor works fine if I trigger the transistor with a regular 5v source.

I have a 10k pull down between the gate and source and I have a 10k on the gate lead going to the arduino, I might play with the gate lead value and see if it makes any difference.

I know its a long way to do it but I have such little experience with arduino code that I can’t write it myself and only manage to edit certain stuff so if all else fails I’ll just set A6 as a duplicate of the A3 I use for the green led and I’ll use a 555 ic to trigger the reset with a delay after the door unlock script has fully run and returned to its standby state.

I get that a lot of people could easily write it into the code but I’m not close to that yet and adding pinmodes and digital writes ect into existing code sections is my current limit of ability.

I’m slowly learning things and people like you giving pointers on specific things and the notes against code sections are a real help, learning in little steps on how existing code works is the only way I’ve been able to pick any of this up as looking at the ‘mechanics’ of code is a lot easier than trying to learn how to write it from guides :slight_smile:

Can you double check the wiring? I have been working (based on feedback from others) to add additional options to my posted code for the dooropener in github. Took me couple of hours testing and never I experience a problem with the MFR522 hanging or getting unresponsive. The fact that you measured on pin 9 of the UNO a fluctuating voltage, but a steady 3V3 on the reset pin of the MRFC522, while they should be directly connected, makes me wonder.

There is NO need for extra transistors etc to pull the reset on the MFRC522. Direct connection to the board should work.

One aspect however that “could” impact is the dooropener. Depending on how that is connected/working, they often have a coil that is activated to remove a blocking pin. That coil can generate a’ dip’ on the power supply when activated or a ‘spike’ when released. Same could be true if you have a relay connected to the doorpin. If that is using the same power supply as your solutions, this “dip” and " spike" can cause the logic to turn in undefined behavior and you need to reset. You can test that by using a led on the doorpin instead of activation circuit and see whether the MFRC522 is still getting unresponsive.

paulvha:
Can you double check the wiring? I have been working (based on feedback from others) to add additional options to my posted code for the dooropener in github. Took me couple of hours testing and never I experience a problem with the MFR522 hanging or getting unresponsive. The fact that you measured on pin 9 of the UNO a fluctuating voltage, but a steady 3V3 on the reset pin of the MRFC522, while they should be directly connected, makes me wonder.

There is NO need for extra transistors etc to pull the reset on the MFRC522. Direct connection to the board should work.

One aspect however that “could” impact is the dooropener. Depending on how that is connected/working, they often have a coil that is activated to remove a blocking pin. That coil can generate a’ dip’ on the power supply when activated or a ‘spike’ when released. Same could be true if you have a relay connected to the doorpin. If that is using the same power supply as your solutions, this “dip” and " spike" can cause the logic to turn in undefined behavior and you need to reset. You can test that by using a led on the doorpin instead of activation circuit and see whether the MFRC522 is still getting unresponsive.

My wiring is correct, I’ve double and triple checked it.

I think you miss understand me about the reset pin voltages , I’ve measured them on the arduino and the RC522 with no connection linking the two pins and the RC522 is measuring a steady 3.3v and expects to see ground to reset and the arduino is pulsing between 0 and 3.3v, its not steady on the RC522 and pulsing on the arduino with them physically tied and would measure a steady 3.3v at both ends like that because of the RC522’s steady 3.3v.

If the RC522 expects a ground to reset (my two modules at least) then it won’t get a reset from the arduino going between 3.3v and 0

If I manually trigger ground to the RC522, it resets and responds to a tag every single time.

That’s why I keep talking about transistors, I can used one to provide a path to ground from a positive voltage on the arduino but although the transistor is perfectly happy with any other 5v output pin on the arduino, it does not like the reset pin 9 for some reason, maybe the short pulses coupled with 3.3v?

The problem I have is getting it to be actuated automatically, my first idea of adding a delayed digital write high then low again to trigger the transistor failed as it was not finishing the maim cycle till the added digital write was finished and I’m guessing it was doing something with the RC522 on its data lines which prevented the reset taking affect but a manual trigger even just 100ms after that point works every time.

So my next idea was to try and place a repeating digital write high/low into the main loop which would generate a 500ms signal to trigger the transistor every minute or so after reading on adding it to existing code and thinking I had it worked out but after doing it and it successfully compiling, its not actually doing anything on the pin so I guess the code I out in was wrong or in the wrong place :frowning:

My door opener is powered from a 12v source and my relay is powered from a 5v regulator and the arduino is only providing the trigger signal to it.

The arduino is powered from the same 5v regulator but its rated at 3A and is more than sufficient for the task and is a clean, filtered power source designed for FPV video.

The only path for interference is the grounds which are all tied together, I can try putting a cap across the positive and ground at the main connections for additional filtering but I really don’t think that’s the problem.

Steve.

stevefox:

paulvha:
Can you double check the wiring? I have been working (based on feedback from others) to add additional options to my posted code for the dooropener in github. Took me couple of hours testing and never I experience a problem with the MFR522 hanging or getting unresponsive. The fact that you measured on pin 9 of the UNO a fluctuating voltage, but a steady 3V3 on the reset pin of the MRFC522, while they should be directly connected, makes me wonder.

There is NO need for extra transistors etc to pull the reset on the MFRC522. Direct connection to the board should work.

One aspect however that “could” impact is the dooropener. Depending on how that is connected/working, they often have a coil that is activated to remove a blocking pin. That coil can generate a’ dip’ on the power supply when activated or a ‘spike’ when released. Same could be true if you have a relay connected to the doorpin. If that is using the same power supply as your solutions, this “dip” and " spike" can cause the logic to turn in undefined behavior and you need to reset. You can test that by using a led on the doorpin instead of activation circuit and see whether the MFRC522 is still getting unresponsive.

My wiring is correct, I’ve double and triple checked it.

I think you miss understand me about the reset pin voltages , I’ve measured them on the arduino and the RC522 with no connection linking the two pins and the RC522 is measuring a steady 3.3v and expects to see ground to reset and the arduino is pulsing between 0 and 3.3v, its not steady on the RC522 and pulsing on the arduino with them physically tied and would measure a steady 3.3v at both ends like that because of the RC522’s steady 3.3v.

If the RC522 expects a ground to reset (my two modules at least) then it won’t get a reset from the arduino going between 3.3v and 0

If I manually trigger ground to the RC522, it resets and responds to a tag every single time.

That’s why I keep talking about transistors, I can used one to provide a path to ground from a positive voltage on the arduino but although the transistor is perfectly happy with any other 5v output pin on the arduino, it does not like the reset pin 9 for some reason, maybe the short pulses coupled with 3.3v?

The problem I have is getting it to be actuated automatically, my first idea of adding a delayed digital write high then low again to trigger the transistor failed as it was not finishing the main code cycle till the digital write i added was finished and I’m guessing the main code was doing something with the RC522 on its data lines which prevented the reset taking affect but a manual trigger even just 100ms after that point works every time.

So my next idea was to try and place a repeating digital write high/low into the main loop which would generate a 500ms signal to trigger the transistor every minute or so after reading on adding it to existing code and thinking I had it worked out but after doing it and it successfully compiling, its not actually doing anything on the pin so I guess the code I out in was wrong or in the wrong place :frowning:

My door opener is powered from a 12v source and my relay is powered from a 5v regulator and the arduino is only providing the trigger signal to it.

The arduino is powered from the same 5v regulator but its rated at 3A and is more than sufficient for the task and is a clean, filtered power source designed for FPV video, while its technically possible the relay coil could be putting something back down the shared 5v line, the door solenoid shouldn’t be able too due to the 5v regulators filtering.

Steve.

I do not know what is happening on your system, but there are 2 easy ways to reset.

The best way is NOT only perform a hard reset, but also reset the MFRC522 internal registers to the right state. If the MFRC522 is unresponsive after unlock try the following code for open_door();

void open_door()
{
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(F("UNLOCKED"));

  digitalWrite(DOORPIN,HIGH); // open door
  delay(DOOR_OPEN_TIME);
  digitalWrite(DOORPIN,LOW);

  // in case the MFRC is unresponsive after an unlock
  delay(500);           // wait 500mS for stabilize power (you can make this longer)
  mfrc522.PCD_Init();   // Init MFRC522 card

  // reset LCD
  blocked(0);
}

if you only want to do a hard reset, you can use this snipped from the MFRC522 PCD_init() call in your sketch:

pinMode(RST_PIN, INPUT);
  
if (digitalRead(RST_PIN) == LOW) { // The MFRC522 chip is in power down mode.
  pinMode(RST_PIN, OUTPUT);        // Now set the resetPowerDownPin as digital output.
  digitalWrite(RST_PIN, LOW);      // Make sure we have a clean LOW state.
  delayMicroseconds(2);            // 8.8.1 Reset timing requirements says about 100ns. Let us be generous: 2μsl
  digitalWrite(RST_PIN, HIGH);     // Exit power down mode. This triggers a hard reset.
  // Section 8.8.2 in the datasheet says the oscillator start-up time is the start up time of the crystal + 37,74μs. Let us be generous: 50ms.
  delay(50);
}

paulvha:
I do not know what is happening on your system, but there are 2 easy ways to reset.

The best way is NOT only perform a hard reset, but also reset the MFRC522 internal registers to the right state. If the MFRC522 is unresponsive after unlock try the following code for open_door();

void open_door()

{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(F(“UNLOCKED”));

digitalWrite(DOORPIN,HIGH); // open door
delay(DOOR_OPEN_TIME);
digitalWrite(DOORPIN,LOW);

// in case the MFRC is unresponsive after an unlock
delay(500); // wait 500mS for stabilize power (you can make this longer)
mfrc522.PCD_Init(); // Init MFRC522 card

// reset LCD
blocked(0);
}




if you only want to do a hard reset, you can use this snipped from the MFRC522 PCD_init() call in your sketch:




pinMode(RST_PIN, INPUT);

if (digitalRead(RST_PIN) == LOW) { // The MFRC522 chip is in power down mode.
pinMode(RST_PIN, OUTPUT); // Now set the resetPowerDownPin as digital output.
digitalWrite(RST_PIN, LOW); // Make sure we have a clean LOW state.
delayMicroseconds(2); // 8.8.1 Reset timing requirements says about 100ns. Let us be generous: 2μsl
digitalWrite(RST_PIN, HIGH); // Exit power down mode. This triggers a hard reset.
// Section 8.8.2 in the datasheet says the oscillator start-up time is the start up time of the crystal + 37,74μs. Let us be generous: 50ms.
delay(50);
}

You were right about the door lock.

After trying the above code alterations I was having more success and so did a tonne of testing.

During said testing I found myself touching the RFID pins at the point of unlock and got a painful shock!

Errrm, that’s not ment to even be possible I say to myself as its running on 12v but the solenoid is generating a very short but high voltage spike when power is removed and stuffing it back down the cable.

The door solenoid and the rest of the system only share a common ground when released as the relay isolates the like side but the spike is enough that its the cause of RC522 hangs.

I don’t know what the voltage of the spike is, I couldn’t be bothered to put the meter on it but I’ve put a 35v cap across the terminals on the solenoid to catch the spikes and with the stock code its now stable :slight_smile:

I figured a 35v cap to be the minimum seeing as I’m feeling the spike, if it kills the cap I’ll up it to a 50v but I think it will be fine.

What surprises me is that the power supply does not shut down, its running from an atx PC power supply and they are very fast to shut down normally if there is a voltage surge or spike but it is already powering a CCTV DVR , 6 cameras and an ir flood light so they may be damping it somewhat coupled with the distance of cable between the door lock and the PSU.

I have 12v led lighting in the keypad weather shield which I 3d printed but have been testing an ldr circuit to control it before I wire it as I don’t want them on 24/7 to make the leds last.

I have a 12v active microphone waiting to be connected up on the same 12v line as the door is using (its for my CCTV), with a bit of luck the cap will prevent massive noise being injected into it, I might increase the caps uf value and maybe look at a diode too as the audio input of the DVR won’t much like large spikes lol.