Fatal error: I2CIO.h: No such file or directory

I am using arduino nano and i trying to make a RFID lock. I find a tutorial online and I copy the code from there. I am using the library it provides but it keeps showing the fatel error. Here is the link of github of the library.
And here is the code

#include <SPI.h>

#include <MFRC522.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <Keypad.h>

#include<EEPROM.h>



int relPin;

int state=0;

byte  COD[10];

byte  AUX[10];

int k=0;

String accessCode="*123456#";

String codpairing="*654321#";

//NFC

#define RST_PIN   9

#define SS_PIN 10   

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



//KEYPAD

const byte numRows= 4; //number of rows on the keypad

const byte numCols= 4; //number of columns on the keypad



char keymap[numRows][numCols]=

{

{'1', '2', '3', 'A'},

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

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

{'*', '0', '#', 'D'}

};



//Code that shows the the keypad connections to the arduino terminals

byte rowPins[numRows] = {2,3,4,5}; //Rows 0 to 3

byte colPins[numCols]= {A0,7,8,9}; //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);

  //NFC

  Serial.begin(9600);  // Initialize serial communications with the PC

  while (!Serial);  // Do nothing if no serial port is opened

  SPI.begin(); // Init SPI bus

 mfrc522.PCD_Init();     // Init MFRC522 card



 for (byte i = 0; i < 6; i++) {        

key.keyByte[i] = 0xFF;

 }

lcd.begin();

lcd.backlight();

lcd.setCursor(0,0);

lcd.clear();

lcd.print( "BLOCKED" );

}



void  readNFC(){   // This function will read the code stored on  

 for (byte i =0; i<(mfrc522.uid.size); i++) {  // the  UID

   COD[i]=mfrc522.uid.uidByte[i];

 }

 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++){                       //The UID cannot be stored on

switch(i%4){                                                     // one variable, it was needed to be

      case 1 :{AUX[0]=EEPROM.read(i); break;}     // split

      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] ){                                      //Verify if the code is in EEPROM

         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 aux2=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(aux2+1,COD[0]);  //Writing code in EEPROM

         EEPROM.write(aux2+2,COD[1]);

         EEPROM.write(aux2+3,COD[2]);

         EEPROM.write(aux2+4,COD[3]);



         aux2=aux2+4; // Position for a new code

         Serial.println("aux2");

         Serial.println(aux2);

         EEPROM.write(0,0);

         EEPROM.write(0,aux2);    

         lcd.clear();

         lcd.setCursor(0,0);

         lcd.print("CODE PAIRED");

         delay(2000);}   

 }



boolean validationNFC(){

  boolean c=false;

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

      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; //Verify if the code is in EEPROM and make flag=true;

     }

}       

  return c;  

}



int compareCODE(String a)    //We type a code on keypad and this will be compared

{ //with the accessCode;

 if(a.equals(accessCode))    

return 1;

 else if(a.equals(codpairing)) return 2;

 else return 0;  

}



String takeCode(char x) //Will display on the LCD the code typed

{ 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(); //Waits for 8 keys to be pressed and after that  

     lcd.print('X');} //is taking the decision

 vec[8]=NULL;

 String str(vec);

 return str;

}  



  void loop() {

   

  switch(state){

  case 0: {

    mfrc522.PCD_Init();

    if (  mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){

   

    readNFC(); //It will read the card and it will search for UID in its

    if(validationNFC()) //memory

       { state=1;

        lcd.clear();

        lcd.setCursor(0,0);

lcd.print( "VALID NFC CODE" ); //The door will be opened

        delay(1000);

        return;

       }

    else{

         lcd.clear();

         lcd.setCursor(0,0);

         lcd.print( "INVALID NFC CODE" ) //If the code was wrongblocked

         delay(1000);

         lcd.setCursor(0,0);

         lcd.clear();

         lcd.print( "BLOCKED" );

         return;

        }

    }      

 

char c=myKeypad.getKey();

  if(c != NO_KEY){

   

String codcurent=takeCode(c);

int A=compareCODE(codcurent);

  if(A==0){                                //A is a variable that stores the current code

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

   state = 1;

   Return;

}

  if(A==2); {

state=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); //The red LED will be off

    digitalWrite(A2,HIGH); //The green LED will be on

    tone(6,3000,5010); //The buzzer will make a sound

    delay(5000); //After 5 seconds the system will be blocked

    digitalWrite(A3,HIGH);

    digitalWrite(A1,HIGH);

    digitalWrite(A2,LOW);

    state=0;

    lcd.setCursor(0,0);

    lcd.clear();

    lcd.print( "BLOCKED" );

return;

    }



  case 2:{

   mfrc522.PCD_Init();

      if (  mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial() ){

      readNFC();

      pairNFC();

      state=0;

      delay(2000);

      lcd.clear();

      lcd.setCursor(0,0);

      lcd.print( "BLOCKED" );   }

 

break;

}

}

}

Please show the error message in fill. Do not post screenshots, insert the message as a text with code tags.

Why do you have a blank line between EVERY LINE of CODE? That makes it difficult and annoying to look at.

You are mixing up LCD libraries and appear to have installed an incomplete LCD library.
i.e. there are multiple LCD libraries that have a header file called LiquidCrystal_I2C.h and provide a class called LiquidCrystal_I2C

To name the two most common libraries that have this header file:
newLiquidCrystal
LiquidCrystal_I2C

But you seem to have found and installed another LCD "library" that contains only a part of the newLiquidCrystal library.

When you have multiple libraries with the same header file name things can easily get confused.

In this case it is even worse, since the libraries contain a LiquidCrystal_I2C class but they work differently.

I2CIO.h is a header file that comes with the newLiquidCrystal library.
The LCD library you pointed to is only a small piece of the newLiquidCrystal library and is missing most of the newLiquidCrystal library files.
You are using LiquidCrystal_I2C.h in your code
but the constructor you are using for your lcd object is not for the LiquidCrystal_I2C class from the LiquidCrystal_I2C.h header file from the newLiquidCrystal library.
You are using a constructor for the LiquidCrystal_I2C class from the LiquidCrystal_I2C class from the LiquidCrystal_I2C library.
i.e. you have installed a library (an incomplete portion of newLiquidCrystal) but your code is attempting to use the LiquidCrystal_I2C library.

There will be errors, as you have seen.

For sure you need to ditch that LCD library your linked to and do a proper install of a working LCD library.

You could avoid all this LiquidCrystal_I2C header file issue stuff by switching to the hd44780 library and using the hd44780_I2Cexp i/o class.

The hd44780 library is available in the IDE library manager so you can quickly install it from the IDE GUI without having to manually download any files.

Here is a link to the hd44780 library and the
hd44780_I2Cexp i/o class wiki

--- bill

Your sketch in a readable way:

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

int relPin;
int state = 0;
byte COD[10];
byte AUX[10];
int k = 0;
String accessCode = "*123456#";
String codpairing = "*654321#";

//NFC
#define RST_PIN 9
#define SS_PIN 10
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);

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

char keymap[numRows][numCols] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = { 2, 3, 4, 5 };   //Rows 0 to 3
byte colPins[numCols] = { A0, 7, 8, 9 };  //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);
  //NFC
  Serial.begin(9600);  // Initialize serial communications with the PC
  while (!Serial)
    ;                  // Do nothing if no serial port is opened
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card

  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.clear();
  lcd.print("BLOCKED");
}

void readNFC() {                                   // This function will read the code stored on
  for (byte i = 0; i < (mfrc522.uid.size); i++) {  // the  UID
    COD[i] = mfrc522.uid.uidByte[i];
  }
  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++) {  //The UID cannot be stored on
    switch (i % 4) {                           // one variable, it was needed to be
      case 1:
        {
          AUX[0] = EEPROM.read(i);
          break;
        }  // split
      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]) {  //Verify if the code is in EEPROM
        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 aux2 = 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(aux2 + 1, COD[0]);  //Writing code in EEPROM
    EEPROM.write(aux2 + 2, COD[1]);
    EEPROM.write(aux2 + 3, COD[2]);
    EEPROM.write(aux2 + 4, COD[3]);

    aux2 = aux2 + 4;  // Position for a new code
    Serial.println("aux2");
    Serial.println(aux2);
    EEPROM.write(0, 0);
    EEPROM.write(0, aux2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("CODE PAIRED");
    delay(2000);
  }
}

boolean validationNFC() {
  boolean c = false;
  for (int i = 1; i <= EEPROM.read(0); i++) {  //Read the EEPROM
    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;  //Verify if the code is in EEPROM and make flag=true;
    }
  }
  return c;
}

int compareCODE(String a)  //We type a code on keypad and this will be compared
{                          //with the accessCode;
  if (a.equals(accessCode))
    return 1;
  else if (a.equals(codpairing)) return 2;
  else return 0;
}

String takeCode(char x)  //Will display on the LCD the code typed
{
  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();  //Waits for 8 keys to be pressed and after that
    lcd.print('X');
  }  //is taking the decision
  vec[8] = NULL;
  String str(vec);
  return str;
}

void loop() {
  switch (state) {
    case 0:
      {
        mfrc522.PCD_Init();
        if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {

          readNFC();            //It will read the card and it will search for UID in its
          if (validationNFC())  //memory
          {
            state = 1;
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("VALID NFC CODE");  //The door will be opened
            delay(1000);
            return;
          } else {
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("INVALID NFC CODE")  //If the code was wrongblocked
              delay(1000);
            lcd.setCursor(0, 0);
            lcd.clear();
            lcd.print("BLOCKED");
            return;
          }
        }

        char c = myKeypad.getKey();
        if (c != NO_KEY) {

          String codcurent = takeCode(c);
          int A = compareCODE(codcurent);
          if (A == 0) {  //A is a variable that stores the current code
            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);
            state = 1;
            Return;
          }
          if (A == 2)
            ;
          {
            state = 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);   //The red LED will be off
        digitalWrite(A2, HIGH);  //The green LED will be on
        tone(6, 3000, 5010);     //The buzzer will make a sound
        delay(5000);             //After 5 seconds the system will be blocked
        digitalWrite(A3, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, LOW);
        state = 0;
        lcd.setCursor(0, 0);
        lcd.clear();
        lcd.print("BLOCKED");
        return;
      }

    case 2:
      {
        mfrc522.PCD_Init();
        if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
          readNFC();
          pairNFC();
          state = 0;
          delay(2000);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("BLOCKED");
        }
        break;
      }
  }

What is "Return;" with a capital "R" ?

It should be a typo.

Thanks for your suggestion. I have changed the library of LCD. But seems like every library it provides have problems.

Now there is a new error coming. fatal error: utility/Key.h: No such file or directory
I think the library it provides is all incomplete. Does anyone know if there is a complete rfid and keypad library that can be use in my project?

You have some cleaning up to do :broom:

Please remove the libraries that you installed from the "SmartDoor" on Github.
When the Arduino IDE is not running, go to the "Documents / Arduino / libraries" folder, and check that you have no weird libraries. It is okay if you remove too many libraries (folders) there, you can always install libraries that you need.

Turn on the "verbose" mode for the compiler output in the preferences. Copy-paste the output to show it to us if there is a problem. You can try to read it yourself, it says which libraries are used.

Keep the "hd44870" library, if you have installed it via the Library Manager.
I think that the EEPROM library is already part of the Arduino IDE, so that is okay.

Go to the Library Manager of the Arduino IDE.
Install the "MFRC522 by GithubCommunity", and "Keypad by Mark Stanley, Alexander Brevig".

Please make the text layout of your sketch look good. Put every new line, every indent, every space and comma at the right place. You do that for yourself, not for us. This is important to see what the code is doing and to spot a bug easier. Press Ctrl+T or right-click and "Format document" to let the Arduino IDE do the first automatic text layout cleanup.

If you are not using the Arduino IDE, please tell what you use.

When you have cleaned up everything, then we have to look at your code. There are so many "return" in the loop(), that makes it harder to read.

it should be like

lcd.begin(16, 2);           // set up the LCD 16x2

and Return should be return

Here is the code now.

#include <Key.h>
#include <Keypad.h>

#include <MFRC522.h>
#include <MFRC522Extended.h>
#include <deprecated.h>
#include <require_cpp11.h>

#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <SPI.h>

#include <Wire.h>

#include <EEPROM.h>

int relPin;
int state = 0;
byte COD[10];
byte AUX[10];
int k = 0;
String accessCode = "*123456#";
String codpairing = "*654321#";

//NFC
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
#define NEW_UID \
  { 0xDE, 0xAD, 0xBE, 0xEF }
MFRC522::MIFARE_Key key;

//LCD
 hd44780_I2Cexp lcd(0x27, 16, 2);

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

char keymap[numRows][numCols] = {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

//Code that shows the the keypad connections to the arduino terminals
byte rowPins[numRows] = { 2, 3, 4, 5 };   //Rows 0 to 3
byte colPins[numCols] = { A0, 7, 8, 9 };  //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);
  //NFC
  Serial.begin(9600);  // Initialize serial communications with the PC
  while (!Serial)
    ;                  // Do nothing if no serial port is opened
  SPI.begin();         // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522 card

  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }
  lcd.begin(16,2); //set up the LCD 16X2
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.clear();
  lcd.print("BLOCKED");
}

void readNFC() {                                   // This function will read the code stored on
  for (byte i = 0; i < (mfrc522.uid.size); i++) {  // the  UID
    COD[i] = mfrc522.uid.uidByte[i];
  }
  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++) {  //The UID cannot be stored on
    switch (i % 4) {                           // one variable, it was needed to be
      case 1:
        {
          AUX[0] = EEPROM.read(i);
          break;
        }  // split
      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]) {  //Verify if the code is in EEPROM
        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 aux2 = 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(aux2 + 1, COD[0]);  //Writing code in EEPROM
    EEPROM.write(aux2 + 2, COD[1]);
    EEPROM.write(aux2 + 3, COD[2]);
    EEPROM.write(aux2 + 4, COD[3]);

    aux2 = aux2 + 4;  // Position for a new code
    Serial.println("aux2");
    Serial.println(aux2);
    EEPROM.write(0, 0);
    EEPROM.write(0, aux2);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("CODE PAIRED");
    delay(2000);
  }
}

boolean validationNFC() {
  boolean c = false;
  for (int i = 1; i <= EEPROM.read(0); i++) {  //Read the EEPROM
    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;  //Verify if the code is in EEPROM and make flag=true;
    }
  }
  return c;
}

int compareCODE(String a)  //We type a code on keypad and this will be compared
{                          //with the accessCode;
  if (a.equals(accessCode))
    return 1;
  else if (a.equals(codpairing)) return 2;
  else return 0;
}

String takeCode(char x)  //Will display on the LCD the code typed
{
  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();  //Waits for 8 keys to be pressed and after that
    lcd.print('X');
  }  //is taking the decision
  vec[8] = NULL;
  String str(vec);
  return str;
}

void loop() {
  switch (state) {
    case 0:
      {
        mfrc522.PCD_Init();
        if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {

          readNFC();            //It will read the card and it will search for UID in its
          if (validationNFC())  //memory
          {
            state = 1;
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("VALID NFC CODE");  //The door will be opened
            delay(1000);
            return;
          } else {
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("INVALID NFC CODE")  //If the code was wrongblocked
              delay(1000);
            lcd.setCursor(0, 0);
            lcd.clear();
            lcd.print("BLOCKED");
            return;
          }
        }

        char c = myKeypad.getKey();
        if (c != NO_KEY) {

          String codcurent = takeCode(c);
          int A = compareCODE(codcurent);
          if (A == 0) {  //A is a variable that stores the current code
            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);
            state = 1;
            return;
          }
          if (A == 2)
            ;
          {
            state = 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);   //The red LED will be off
        digitalWrite(A2, HIGH);  //The green LED will be on
        tone(6, 3000, 5010);     //The buzzer will make a sound
        delay(5000);             //After 5 seconds the system will be blocked
        digitalWrite(A3, HIGH);
        digitalWrite(A1, HIGH);
        digitalWrite(A2, LOW);
        state = 0;
        lcd.setCursor(0, 0);
        lcd.clear();
        lcd.print("BLOCKED");
        return;
      }

    case 2:
      {
        mfrc522.PCD_Init();
        if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
          readNFC();
          pairNFC();
          state = 0;
          delay(2000);
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("BLOCKED");
        }
        break;
      }
  }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.