CODED LOCK, with database on excel

hi guys , i have problem to save the date , time out , time in and the user( matricule ) on EXCEL
PLS HELP GUYS , this is the code

#include <LiquidCrystal.h>
#include <Keypad.h>

/*-------------------------------KEYPAD---------------------------------------*/
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 3; //number of columns on the keypad
char key_pressed;
int i ;
int j ;
int PIR = A0;
int LOCK = A4;
const int BUTTON = A3; // boutton pour la sorie placer dans la face de porte dans l'enterieur


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] = {4, 5, 6, 7};//Rows 0 to 3
byte colPins[numCols] = { A5, 2, 3};//Columns 0 
Keypad mykeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

/*-------------------------------CONSTANTS------------------------------------*/
LiquidCrystal lcd(13,12,11,10,9,8); //LCD

char MAT[5][4] = {"1111","2222","3333","4444","5555"}; //MATRICULE
char PASS[5][4] = {"1111","2222","3333","4444","5555"};// MOT DE PASSE
    int VAS=0;// ENRGISTRE FIHA VALEUR DE 1 JUSQU'A 5
    char mat[5];
    char password[5];

    //boolean changedPassword = false;


    
void setup() {


 Serial.begin(9600); // Initialize serial communications with the PC
             
  Serial.println("LABEL,Date,Matricule,Time IN,Time OUT");// make four columns (Date,Time,[Name:"user name"]line 48 & 52,[Number:"user number"]line 49 & 53) 

              
             
              lcd.begin(16, 2); //Setup the LCD's number of columns and rows
              pinMode(BUTTON, INPUT);// BUTTON
              pinMode(A1, OUTPUT); // LED RED
              pinMode(A2, OUTPUT); // LED GREEN
              pinMode(A0, INPUT);//PIR  
              pinMode(A4, OUTPUT);   //LOCK
           }

void loop() {
 if(digitalRead(PIR) == HIGH)
      {
       
        lcd.setCursor(0,0);
        lcd.print("ENTER MAT:  ");
        lcd.setCursor(0,1);
        lcd.print("");
  
   
  
  
 key_pressed = mykeypad.getKey();
  if (key_pressed == '0' || key_pressed == '1' || key_pressed == '2' || key_pressed == '3' || key_pressed == '4' || key_pressed == '5' || key_pressed == '6' || key_pressed == '7' || key_pressed == '8' || key_pressed == '9' ) {
    mat[i++] = key_pressed;
    ;
      lcd.setCursor(i, 2);
      lcd.print(key_pressed);
        
    if (i == 4)
    {
    for(int l=0;l<4;l++)
     { 


       int resultat = 0;  //ajout de resultat pour afficher la valeur renvoyer par la comparaison
       resultat = strncmp(mat, MAT[l],4) ; //on compare les mots

  if(resultat == 0) 
      {
        VAS=l;      
        i =0;
        lcd.setCursor(0, 0);
        lcd.print(" Mat Accepted");
        lcd.setCursor(0, 1); 
        lcd.print("                ");
        digitalWrite(A2, HIGH);
        delay(300);
        digitalWrite(A2, LOW);
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Enter Password   ");
        delay(400);
        
  
  
  while (j < 4) { 
          key_pressed = mykeypad.getKey();
    if (key_pressed== '0' || key_pressed== '1' || key_pressed== '2' || key_pressed== '3' || key_pressed== '4' || key_pressed== '5' || key_pressed== '6' || key_pressed== '7' || key_pressed== '8' || key_pressed== '9') 
        {
          password[j++] = key_pressed;
          
          lcd.setCursor(j, 2);
          lcd.print("*");
      
      }
  
  
          key_pressed=0;
      }
  if (!strncmp(password, PASS[VAS],4))
 
      {
          j=0;
          lcd.setCursor(0, 0);
          lcd.print("Pass Accepted");
          lcd.setCursor(0, 1);
          lcd.print("WELCOME"); 
          digitalWrite(LOCK, HIGH);//unlock the door for 5 seconds
          digitalWrite(A2, HIGH);
          delay(500);
                 Serial.print("DATA,DATE," + MAT[5][4]);//send the Name to excel
      Serial.print(",");
      Serial.print(MAT[5][4]); //send the Number to excel
      Serial.print(",");
      Serial.print("");
      Serial.print(",");
      Serial.println("TIME");
           digitalWrite(LOCK, LOW);
          digitalWrite(A2, LOW);
          delay(300);
          lcd.clear();
          
}

      
      else
      { 
            j=0;
            lcd.setCursor(0, 1);
            lcd.print("                    ");
            lcd.setCursor(0, 1);
            lcd.print("Wrong Password");
            digitalWrite(A1,HIGH);
            delay(200);
            digitalWrite(A1,LOW);
           
            
       }
        }
       
    
        else  
        {
           
            lcd.setCursor(0, 0);
            lcd.print("Wrong Mat");
            lcd.setCursor(0, 1);
            lcd.print("Try again PLS");
            digitalWrite(A1,HIGH);
            delay(200);
            digitalWrite(A1,LOW);
            delay(200);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Enter Mat");
            lcd.setCursor(0, 1);
             i =0;
        }    
        } 
        }
        }
        } 
    else
        {
            lcd.clear();
            digitalWrite(4,LOW);
            digitalWrite(5,LOW);
            digitalWrite(6,LOW);
            digitalWrite(7,LOW);
            
      
        }
    if(digitalRead(BUTTON) == HIGH){
        j=0;
          
          
       
          digitalWrite(LOCK, HIGH);//unlock the door for 5 seconds
          digitalWrite(A2, HIGH);
          delay(500);
           digitalWrite(LOCK, LOW);
          digitalWrite(A2, LOW);
          delay(1000);
       /*   Serial.print(",");
      Serial.print(MAT[5][4]); //send the Number to excel
      Serial.print(",");
      Serial.print("");
      Serial.print(",");
      Serial.println("TIME");*/
          lcd.clear();
    }
        return loop();
        }

i have problem to save the date , time out , time in and the user( matricule ) on EXCEL

Don't you think it might be important to tell us what the problem is?

  Serial.println("LABEL,Date,Matricule,Time IN,Time OUT");// make four columns (Date,Time,[Name:"user name"]line 48 & 52,[Number:"user number"]line 49 & 53)

That comment makes no sense.

  if (key_pressed == '0' || key_pressed == '1' || key_pressed == '2' || key_pressed == '3' || key_pressed == '4' || key_pressed == '5' || key_pressed == '6' || key_pressed == '7' || key_pressed == '8' || key_pressed == '9' ) {

or

  if (key_pressed >= '0' && key_pressed <= '9' ) {

Which one is easier to read and understand?

    ;

Why?

I gave up reading your code. It looks like it was typed by a drunken monkey high on crack.

Get that monkey into rehab, and learn to use Tools + Auto Format.

return loop();

what do you want with this?

this code is to open the door by 5 users ,everyone has his number and password, i need to save the time of enter and the number of the user on excel , pls help

You've gotten several responses with questions and suggestions. It does not appear that you've even read the responses. Just why should we continue trying to help?

I did what you told me , i am amateure , that's why i am asking you guys , i tried to change few things

#include <LiquidCrystal.h>
#include <Keypad.h>

/*-------------------------------KEYPAD---------------------------------------*/
const byte numRows= 4; //number of rows on the keypad
const byte numCols= 3; //number of columns on the keypad
char key_pressed;
int i ;
int j ;
int PIR = A0;
int LOCK = A4;
const int BUTTON = A3; // boutton pour la sorie placer dans la face de porte dans l'enterieur


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] = {4, 5, 6, 7};//Rows 0 to 3
byte colPins[numCols] = { A5, 2, 3};//Columns 0 
Keypad mykeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

/*-------------------------------CONSTANTS------------------------------------*/
LiquidCrystal lcd(13,12,11,10,9,8); //LCD

char MAT[5][4] = {"1111","2222","3333","4444","5555"}; //MATRICULE
char PASS[5][4] = {"1111","2222","3333","4444","5555"};// MOT DE PASSE
    int VAS=0;// ENRGISTRE FIHA VALEUR DE 1 JUSQU'A 5
    char mat[5];
    char password[5];

    //boolean changedPassword = false;


    
void setup() {


 Serial.begin(9600); // Initialize serial communications with the PC
             
  Serial.println("LABEL,Date,Matricule,Time IN,Time OUT"); 

              
             
              lcd.begin(16, 2); 
              pinMode(BUTTON, INPUT);// BUTTON
              pinMode(A1, OUTPUT); // LED RED
              pinMode(A2, OUTPUT); // LED GREEN
              pinMode(A0, INPUT);//PIR  
              pinMode(A4, OUTPUT);   //LOCK
           }

void loop() {
 if(digitalRead(PIR) == HIGH)
      {
       
        lcd.setCursor(0,0);
        lcd.print("ENTER MAT:  ");
        lcd.setCursor(0,1);
        lcd.print("");
  
   
  
  
 key_pressed = mykeypad.getKey();
   if (key_pressed >= '0' && key_pressed <= '9' ) {
    mat[i++] = key_pressed;
    ;
      lcd.setCursor(i, 2);
      lcd.print(key_pressed);
        
    if (i == 4)
    {
    for(int l=0;l<4;l++)
     { 


       int resultat = 0;  //ajout de resultat pour afficher la valeur renvoyer par la comparaison
       resultat = strncmp(mat, MAT[l],4) ; //on compare les mots

  if(resultat == 0) 
      {
        VAS=l;      
        i =0;
        lcd.setCursor(0, 0);
        lcd.print(" Mat Accepted");
        lcd.setCursor(0, 1); 
        lcd.print("                ");
        digitalWrite(A2, HIGH);
        delay(300);
        digitalWrite(A2, LOW);
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("Enter Password   ");
        delay(400);
        
  
  
  while (j < 4) { 
          key_pressed = mykeypad.getKey();
        if (key_pressed >= '0' && key_pressed <= '9' ) {
          password[j++] = key_pressed;
          
          lcd.setCursor(j, 2);
          lcd.print("*");
      
      }
  
  
          key_pressed=0;
      }
  if (!strncmp(password, PASS[VAS],4))
 
      {
          j=0;
          lcd.setCursor(0, 0);
          lcd.print("Pass Accepted");
          lcd.setCursor(0, 1);
          lcd.print("WELCOME"); 
          digitalWrite(LOCK, HIGH);//unlock the door for 5 seconds
          digitalWrite(A2, HIGH);
          delay(500);
                 Serial.print("DATA,DATE," + MAT[5][4]);//send the Name to excel
      Serial.print(",");
      Serial.print(MAT[5][4]); //send the Number to excel
      Serial.print(",");
      Serial.print("TIME IN");
      Serial.print(",");
      Serial.println("");
           digitalWrite(LOCK, LOW);
          digitalWrite(A2, LOW);
          delay(300);
          lcd.clear();
          
}

      
      else
      { 
            j=0;
            lcd.setCursor(0, 1);
            lcd.print("                    ");
            lcd.setCursor(0, 1);
            lcd.print("Wrong Password");
            digitalWrite(A1,HIGH);
            delay(200);
            digitalWrite(A1,LOW);
           
            
       }
        }
       
    
        else  
        {
           
            lcd.setCursor(0, 0);
            lcd.print("Wrong Mat");
            lcd.setCursor(0, 1);
            lcd.print("Try again PLS");
            digitalWrite(A1,HIGH);
            delay(200);
            digitalWrite(A1,LOW);
            delay(200);
            lcd.clear();
            lcd.setCursor(0, 0);
            lcd.print("Enter Mat");
            lcd.setCursor(0, 1);
             i =0;
        }    
        } 
        }
        }
        } 
    else
        {
            lcd.clear();
            digitalWrite(4,LOW);
            digitalWrite(5,LOW);
            digitalWrite(6,LOW);
            digitalWrite(7,LOW);
            
      
        }
    if(digitalRead(BUTTON) == HIGH){
        j=0;
          
          
       
          digitalWrite(LOCK, HIGH);//unlock the door for 5 seconds
          digitalWrite(A2, HIGH);
          delay(500);
           digitalWrite(LOCK, LOW);
          digitalWrite(A2, LOW);
          delay(1000);
       /*   Serial.print(",");
      Serial.print(MAT[5][4]); //send the Number to excel
      Serial.print(",");
      Serial.print("");
      Serial.print(",");
      Serial.println("TIME");*/
          lcd.clear();
    }
        
        }

i am amateure

Even an amateur can answer questions about what the problem is. Why should we keep looking at your code, when we do not know what the problem is?

i can connect excel to arduino but when i open the door i get nothing on table , no save for data

i tried to change few things

The indention was not one of them. The Tools + Auto Format menu item doesn't require any effort to use. Reading piss-poorly indented code requires too much effort.

;

Instead of writing to Excel, for the time being, open the Serial Monitor app, instead, and add more Serial.print() statements, to see what your code is actually doing.

;

              pinMode(A1, OUTPUT); // LED RED
              pinMode(A2, OUTPUT); // LED GREEN
              pinMode(A0, INPUT);//PIR 
              pinMode(A4, OUTPUT);   //LOCK

You gave some of these pins meaningful names. Why are you not using them?

;

INPUT is rarely the correct value. INPUT_PULLUP is usually much better. You need to understand what each value means, and determine, based on how the thing connected to the pin is actually wired, which is better.

;

                 Serial.print("DATA,DATE," + MAT[5][4]);//send the Name to excel
      Serial.print(MAT[5][4]); //send the Number to excel

That array does not have an element with those indices. Array indexes start at 0.

What does your calculator say the result is of ADDing a string literal and a non-existent value? That operator does NOT append strings.