rfid door system doesnt work succesfully

hi.
this is my first topic.

i want to make a "rfid door system".

something i have done.

When I run the system, the system is running at startup.
but after a few minutes, the system is not reading the cards.

++
The interesting thing is that if I open the serial screen, the system is triggered and started working.


to solve problem,
i changed arduino, lcd, rfid rc5522..
but all time the same problem.

I took the role.but the same problem.

#include <LiquidCrystal_I2C.h>
//#include <LiquidCrystal_I2C_AvrI2C.h>

#include <SPI.h>
#include <MFRC522.h>

constexpr uint8_t RST_PIN = 9;
constexpr uint8_t SS_PIN = 10;

LiquidCrystal_I2C lcd(0x27, 16, 2); //Parameters: (rs, enable, d4, d5, d6, d7)
//LiquidCrystal_I2C_AvrI2C lcd(0x27,16,2);  // 16 karakter 2 satır için - 20x4 satır için (0x27,20,4) yazın

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

int buzzerPin = 8;
int relayPin = 2;

void setup() {
  pinMode(buzzerPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);

  lcd.begin();   // LCD screen
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522

  lcd.setCursor(0, 0);
  lcd.print("RFID KAPI Kilidi");
  lcd.setCursor(0, 1);
  lcd.print("  by ATAMAN");
  delay(3000);

  lcd.clear();
}

void loop() {
  lcd.setCursor(0, 0);
  lcd.print("RFID KAPI Kilidi");
  lcd.setCursor(0, 1);
  lcd.print(" KARTINI OKUT ");
  
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  
  //Reading from the card
  String tag = "";
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    tag.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  tag.toUpperCase();
  
  //Checking the card
  if (tag.substring(1) == "1A A6 74 63") //change here the UID of the card/cards that you want to give access
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("ERISIM IZNI VERILDI");
    lcd.setCursor(0, 1);
    lcd.print("  KAPI ACILDI");
    digitalWrite(relayPin, HIGH);
    delay(3000);
    digitalWrite(relayPin, LOW);
    lcd.clear();
  }

  else
  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  YETKISIZ KART");
    lcd.setCursor(0, 1);
    lcd.print("Erisim Izni Yok");
    digitalWrite(buzzerPin, HIGH);
    delay(3000);
    digitalWrite(buzzerPin, LOW);
    lcd.clear();
  }

  
}

thanks.

I would try

SPI.begin(SS_PIN);      // Init SPI bus

The interesting thing is that if I open the serial screen, the system is triggered and started working.

opening the serial monitor sends a reset via software. same thing as hitting the reset button

The interesting thing is that if I open the serial screen, the system is triggered and started working.

Opening the Serial Monitor application resets the Arduino.

 String tag = "";

There's your culprit. Stop using the String class!

There is NO reason to convert a byte array to a String, so you can compare it with another byte array converted to a String. Just compare the byte arrays.

thanks.

produced error message when I tried.
error:

no matching function for call to 'SPIClass::begin(const uint8_t&)'

PaulS:
Opening the Serial Monitor application resets the Arduino.

 String tag = "";

There's your culprit. Stop using the String class!

There is NO reason to convert a byte array to a String, so you can compare it with another byte array converted to a String. Just compare the byte arrays.

thanks.
like that ?

if(mfrc522.uid.uidByte[0] == 0x1A)
              {
                if(mfrc522.uid.uidByte[1] == 0xA6)
                {
                  if(mfrc522.uid.uidByte[2] == 0x74)
                  {
                    if(mfrc522.uid.uidByte[3] == 0x63)
                    { 
                        lcd.clear();
                        lcd.setCursor(0, 0);
                        lcd.print("ERISIM IZNI VERILDI");
                        lcd.setCursor(0, 1);
                        lcd.print("  KAPI ACILDI");
                        digitalWrite(relayPin, HIGH);
                        delay(3000);
                        digitalWrite(relayPin, LOW);
                        lcd.clear();
                    }
                  }
                }
              }

can-inlife:
like that ?

With memcmp() you could do it in one fell swoop.

dougp:
With memcmp() you could do it in one fell swoop.

or learn what && is for.

dougp:
With memcmp() you could do it in one fell swoop.

thanks.
I dont know enough information about it. but i wil work on.

PaulS:
or learn what && is for.

thanks.

i cut off connection with relay
and also lcd.

so i just try with serial screen. and do not create any problem.

so. i think. the problem is that : using RFID-RC522 and 16*2 LCD MONITOR together !
how can i fix it.