RFID accepting all cards

I'm pretty new to Arduino and RFID, and I just finished up with my code and once I tested it, it accepted all the cards rather then just the one I authorized

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

// Define RFID RC522 pins
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define servo motor and LED pins
Servo myservo;

const int redLedPin = 6;
const int greenLedPin = 7;

// Define variables
boolean doorLocked = true; // Initially, the door is locked

void setup() {
  Serial.begin(9600);  // Start the communication with your computer
  SPI.begin();         // Initialize the SPI communication.
  mfrc522.PCD_Init();  // Initialize the RFID reader.
  byte firmwareVersion = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("Firmware Version: 0x");
Serial.println(firmwareVersion, HEX);
if (firmwareVersion == 0x92) {
  Serial.println("RC522 v2.0 detected.");
} else if (firmwareVersion == 0x91 || firmwareVersion == 0x90) {
  Serial.println("RC522 v1.0 detected.");
} else {
  Serial.println("Unknown firmware version. Check connections.");
}

  delay(5);
  Serial.println("Hold your card close to the reader...");
  Serial.println();

  myservo.attach(3); // Attach servo to pin 3
  myservo.write(0);  // Close the door (servo at 0 degrees)

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  // Check for RFID card
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    // Read the RFID card's UID
    Serial.print("Card ID: ");
    String cardUID = ""; // Store the card's ID
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""); // Format the ID with leading zeros
      Serial.print(mfrc522.uid.uidByte[i], HEX);              // Print the ID in hexadecimal
      cardUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(mfrc522.uid.uidByte[i], HEX); // Concatenate the ID in hexadecimal
    }
    cardUID.toUpperCase(); // Convert to uppercase

    // Check if the card UID matches the authorized card
    if (cardUID = "662F3A 03") {
      // Unlock the door and indicate with green LED
      digitalWrite(7, HIGH);
      myservo.write(90); // Open the door (servo at 90 degrees)
      delay(2000);       // Keep the door open for 2 seconds
      myservo.write(0);  // Close the door (servo at 0 degrees)
      digitalWrite(7, LOW);
      Serial.println("Access granted. Welcome!");
      Serial.println();
      delay(3000); // Wait for a few seconds
    } else {
      // Unauthorized card, indicate with red LED
      digitalWrite(6, HIGH);
      delay(1000); // Show red LED for 1 second
      digitalWrite(6, LOW);
      Serial.println("Access denied. Unauthorized card.");
      delay(3000); // Wait for a few seconds
    }

    mfrc522.PICC_HaltA(); // Halt the card
  }

Can you guys check it out please?
Thx

This is an assignment (=), not a compare (==).

ok I'll try that out

the servo isn't turning now

Do you have the correct card number? Note that you have a space in the compare

PS
After you have updated your code, please post your updated code in a new post so we can see what you did.

here's the updated code, also that's the UID that used to pop up but now I'm using a different card and the UID is "B3 42 32 0E" now.

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

// Define RFID RC522 pins
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define servo motor and LED pins
Servo myservo;

const int redLedPin = 6;
const int greenLedPin = 7;

// Define variables
boolean doorLocked = true; // Initially, the door is locked

void setup() {
  Serial.begin(9600);  // Start the communication with your computer
  SPI.begin();         // Initialize the SPI communication.
  mfrc522.PCD_Init();  // Initialize the RFID reader.
  byte firmwareVersion = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("Firmware Version: 0x");
Serial.println(firmwareVersion, HEX);
if (firmwareVersion == 0x92) {
  Serial.println("RC522 v2.0 detected.");
} else if (firmwareVersion == 0x91 || firmwareVersion == 0x90) {
  Serial.println("RC522 v1.0 detected.");
} else {
  Serial.println("Unknown firmware version. Check connections.");
}

  delay(5);
  Serial.println("Hold your card close to the reader...");
  Serial.println();

  myservo.attach(3); // Attach servo to pin 3
  myservo.write(0);  // Close the door (servo at 0 degrees)

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  // Check for RFID card
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    // Read the RFID card's UID
    Serial.print("Card ID: ");
    String cardUID = ""; // Store the card's ID
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""); // Format the ID with leading zeros
      Serial.print(mfrc522.uid.uidByte[i], HEX);              // Print the ID in hexadecimal
      cardUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(mfrc522.uid.uidByte[i], HEX); // Concatenate the ID in hexadecimal
    }
    cardUID.toUpperCase(); // Convert to uppercase

    // Check if the card UID matches the authorized card
    if (cardUID == "B3 42 32 0E") {
      // Unlock the door and indicate with green LED
      digitalWrite(7, HIGH);
      myservo.write(90); // Open the door (servo at 90 degrees)
      delay(2000);       // Keep the door open for 2 seconds
      myservo.write(0);  // Close the door (servo at 0 degrees)
      digitalWrite(7, LOW);
      Serial.println("Access granted. Welcome!");
      Serial.println();
      delay(3000); // Wait for a few seconds
    } else {
      // Unauthorized card, indicate with red LED
      digitalWrite(6, HIGH);
      delay(1000); // Show red LED for 1 second
      digitalWrite(6, LOW);
      Serial.println("Access denied. Unauthorized card.");
      delay(3000); // Wait for a few seconds
    }

    mfrc522.PICC_HaltA(); // Halt the card
  }
}

Add after the above line a Serial.println(cardUID); do you see any spaces?

Edit: replaced Dutch text with English.

It's like watching someone complain "it's so dark out" when all they have to do is open their eyes and see how bright it is.

Print the values of things. See what's happening. Think about what you see. Fix the problem.

cardUID.toUpperCase(); // Convert to uppercase
Serial.println(cardUID);
Serial.println(cardUID == "B3 42 32 0E");

all of the cards are getting declined now and the UID is getting doubled

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

// Define RFID RC522 pins
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define servo motor and LED pins
Servo myservo;

const int redLedPin = 6;
const int greenLedPin = 7;

// Define variables
boolean doorLocked = true; // Initially, the door is locked

void setup() {
  Serial.begin(9600);  // Start the communication with your computer
  SPI.begin();         // Initialize the SPI communication.
  mfrc522.PCD_Init();  // Initialize the RFID reader.
  byte firmwareVersion = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("Firmware Version: 0x");
Serial.println(firmwareVersion, HEX);
if (firmwareVersion == 0x92) {
  Serial.println("RC522 v2.0 detected.");
} else if (firmwareVersion == 0x91 || firmwareVersion == 0x90) {
  Serial.println("RC522 v1.0 detected.");
} else {
  Serial.println("Unknown firmware version. Check connections.");
}

  delay(5);
  Serial.println("Hold your card close to the reader...");
  Serial.println();

  myservo.attach(3); // Attach servo to pin 3
  myservo.write(0);  // Close the door (servo at 0 degrees)

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  // Check for RFID card
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    // Read the RFID card's UID
    Serial.print("Card ID: ");
    String cardUID = ""; // Store the card's ID
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""); // Format the ID with leading zeros
      Serial.print(mfrc522.uid.uidByte[i], HEX);              // Print the ID in hexadecimal
      cardUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(mfrc522.uid.uidByte[i], HEX); // Concatenate the ID in hexadecimal
    }
    cardUID.toUpperCase(); // Convert to uppercase
    Serial.println(cardUID);
    Serial.println(cardUID == "B34232 0EB342320E");

    // Check if the card UID matches the authorized card
    if (cardUID == "") {
      // Unlock the door and indicate with green LED
      digitalWrite(7, HIGH);
      myservo.write(90); // Open the door (servo at 90 degrees)
      delay(2000);       // Keep the door open for 2 seconds
      myservo.write(0);  // Close the door (servo at 0 degrees)
      digitalWrite(7, LOW);
      Serial.println("Access granted. Welcome!");
      Serial.println();
      delay(3000); // Wait for a few seconds
    } else {
      // Unauthorized card, indicate with red LED
      digitalWrite(6, HIGH);
      delay(1000); // Show red LED for 1 second
      digitalWrite(6, LOW);
      Serial.println("Access denied. Unauthorized card.");
      delay(3000); // Wait for a few seconds
    }

    mfrc522.PICC_HaltA(); // Halt the card
  }
}

I ended up fixing it but the servo is still not turning

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

// Define RFID RC522 pins
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define servo motor and LED pins
Servo myservo;

const int redLedPin = 6;
const int greenLedPin = 7;

// Define variables
boolean doorLocked = true; // Initially, the door is locked

void setup() {
  Serial.begin(9600);  // Start the communication with your computer
  SPI.begin();         // Initialize the SPI communication.
  mfrc522.PCD_Init();  // Initialize the RFID reader.
  byte firmwareVersion = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("Firmware Version: 0x");
Serial.println(firmwareVersion, HEX);
if (firmwareVersion == 0x92) {
  Serial.println("RC522 v2.0 detected.");
} else if (firmwareVersion == 0x91 || firmwareVersion == 0x90) {
  Serial.println("RC522 v1.0 detected.");
} else {
  Serial.println("Unknown firmware version. Check connections.");
}

  delay(5);
  Serial.println("Hold your card close to the reader...");
  Serial.println();

  myservo.attach(3); // Attach servo to pin 3
  myservo.write(0);  // Close the door (servo at 0 degrees)

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  // Check for RFID card
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    // Read the RFID card's UID
    Serial.print("Card ID: ");
    String cardUID = ""; // Store the card's ID
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""); // Format the ID with leading zeros
      Serial.print(mfrc522.uid.uidByte[i], HEX);              // Print the ID in hexadecimal
      cardUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(mfrc522.uid.uidByte[i], HEX); // Concatenate the ID in hexadecimal
    }
    cardUID.toUpperCase(); // Convert to uppercase
    Serial.println(cardUID);
    Serial.println(cardUID == "B3 42 32 0E");

    // Check if the card UID matches the authorized card
    if (cardUID == "B3 42 32 0E") {
      // Unlock the door and indicate with green LED
      digitalWrite(7, HIGH);
      myservo.write(90); // Open the door (servo at 90 degrees)
      delay(2000);       // Keep the door open for 2 seconds
      myservo.write(0);  // Close the door (servo at 0 degrees)
      digitalWrite(7, LOW);
      Serial.println("Access granted. Welcome!");
      Serial.println();
      delay(3000); // Wait for a few seconds
    } else {
      // Unauthorized card, indicate with red LED
      digitalWrite(6, HIGH);
      delay(1000); // Show red LED for 1 second
      digitalWrite(6, LOW);
      Serial.println("Access denied. Unauthorized card.");
      delay(3000); // Wait for a few seconds
    }

    mfrc522.PICC_HaltA(); // Halt the card
  }
}

That makes no sense whatsoever to me, I'm afraid.

I would copy and paste the portion of the output that clearly illustrates why your program is not working, but you chose to use a screenshot instead of including it as text.

There were four things I suggested that you do to fix your program. You seem to have stopped after doing the first. So be it.

I'll send the text later today and what were the 4 things you suggested to fix it?

P.S
Sorry if I'm being dumb but I honestly do not get it all too much

18:23:39.241 -> Card UID: 43 51 C6 01
18:23:39.241 -> Card SAK: 08
18:23:39.286 -> PICC type: MIFARE 1KB
18:23:39.286 -> Sector Block   0  1  2  3   4  5  6  7   8  9 10 11  12 13 14 15  AccessBits
18:23:39.353 ->   15     63   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:39.419 ->          62   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:39.519 ->          61   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:39.585 ->          60   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:39.719 ->   14     59   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:39.752 ->          58   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:39.818 ->          57   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:39.918 ->          56   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:39.985 ->   13     55   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:40.118 ->          54   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.151 ->          53   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.251 ->          52   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.318 ->   12     51   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:40.417 ->          50   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.517 ->          49   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.551 ->          48   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.650 ->   11     47   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:40.717 ->          46   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.817 ->          45   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.883 ->          44   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:40.983 ->   10     43   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:41.050 ->          42   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.116 ->          41   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.216 ->          40   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.313 ->    9     39   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:41.383 ->          38   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.449 ->          37   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.549 ->          36   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.616 ->    8     35   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:41.715 ->          34   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.782 ->          33   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.848 ->          32   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:41.948 ->    7     31   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:42.015 ->          30   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.115 ->          29   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.182 ->          28   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.282 ->    6     27   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:42.348 ->          26   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.414 ->          25   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.514 ->          24   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.581 ->    5     23   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:42.680 ->          22   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.747 ->          21   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.847 ->          20   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:42.913 ->    4     19   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:43.047 ->          18   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.080 ->          17   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.146 ->          16   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.247 ->    3     15   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:43.313 ->          14   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.413 ->          13   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.479 ->          12   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.612 ->    2     11   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:43.646 ->          10   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.712 ->           9   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.812 ->           8   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:43.879 ->    1      7   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:43.978 ->           6   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:44.045 ->           5   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:44.178 ->           4   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:44.211 ->    0      3   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:44.311 ->           2   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:44.378 ->           1   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:44.444 ->           0   43 51 C6 01  D5 08 04 00  62 63 64 65  66 67 68 69  [ 0 0 0 ] 
18:23:44.557 -> 
18:23:56.342 -> Card UID: B3 42 32 0E
18:23:56.342 -> Card SAK: 08
18:23:56.375 -> PICC type: MIFARE 1KB
18:23:56.375 -> Sector Block   0  1  2  3   4  5  6  7   8  9 10 11  12 13 14 15  AccessBits
18:23:56.474 ->   15     63   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:56.541 ->          62   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:56.641 ->          61   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:56.707 ->          60   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:56.807 ->   14     59   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:56.874 ->          58   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:56.940 ->          57   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.040 ->          56   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.107 ->   13     55   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:57.207 ->          54   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.273 ->          53   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.373 ->          52   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.440 ->   12     51   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:57.573 ->          50   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.606 ->          49   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.672 ->          48   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.772 ->   11     47   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:57.839 ->          46   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:57.972 ->          45   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.005 ->          44   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.105 ->   10     43   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:58.172 ->          42   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.238 ->          41   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.371 ->          40   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.405 ->    9     39   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:58.504 ->          38   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.571 ->          37   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.671 ->          36   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.737 ->    8     35   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:58.837 ->          34   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.937 ->          33   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:58.970 ->          32   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.103 ->    7     31   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:59.137 ->          30   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.237 ->          29   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.303 ->          28   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.403 ->    6     27   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:59.470 ->          26   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.536 ->          25   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.636 ->          24   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.702 ->    5     23   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:23:59.802 ->          22   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.869 ->          21   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:23:59.969 ->          20   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.035 ->    4     19   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:24:00.135 ->          18   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.235 ->          17   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.268 ->          16   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.368 ->    3     15   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:24:00.435 ->          14   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.534 ->          13   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.601 ->          12   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.701 ->    2     11   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:24:00.767 ->          10   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.834 ->           9   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:00.934 ->           8   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:01.000 ->    1      7   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:24:01.100 ->           6   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:01.200 ->           5   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:01.267 ->           4   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:01.333 ->    0      3   00 00 00 00  00 00 FF 07  80 69 FF FF  FF FF FF FF  [ 0 0 1 ] 
18:24:01.433 ->           2   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:01.500 ->           1   00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  [ 0 0 0 ] 
18:24:01.599 ->           0   B3 42 32 0E  CD 08 04 00  62 63 64 65  66 67 68 69  [ 0 0 0 ] 
18:24:01.672 ->

Edit: Added in the output text

I messed with the code a bit and the serial monitor is now saying this

18:50:39.664 -> Firmware Version: 0xFF = (unknown)

18:50:39.696 -> WARNING: Communication failure, is the MFRC522 properly connected?

18:50:39.763 -> Scan PICC to see UID, SAK, type, and data blocks...

19:15:29.009 -> Firmware Version: 0xB2 = (unknown)

19:15:29.009 -> Scan PICC to see UID, SAK, type, and data blocks...

19:29:11.358 -> Firmware Version: 0xB2

19:29:11.358 -> Unknown firmware version. Check connections.

19:29:11.395 -> Hold your card close to the reader...

19:29:11.435 ->

19:29:13.779 -> Card ID: B34232 0EB342320E

19:29:13.779 -> 0

19:29:14.788 -> Access denied. Unauthorized card.

the updated code is

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

// Define RFID RC522 pins
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define servo motor and LED pins
Servo myservo;

const int redLedPin = 6;
const int greenLedPin = 7;

// Define variables
boolean doorLocked = true; // Initially, the door is locked

void setup() {
  Serial.begin(9600);  // Start the communication with your computer
  SPI.begin();         // Initialize the SPI communication.
  mfrc522.PCD_Init();  // Initialize the RFID reader.
  byte firmwareVersion = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("Firmware Version: 0x");
Serial.println(firmwareVersion, HEX);
if (firmwareVersion == 0x92) {
  Serial.println("RC522 v2.0 detected.");
} else if (firmwareVersion == 0x91 || firmwareVersion == 0x90) {
  Serial.println("RC522 v1.0 detected.");
} else {
  Serial.println("Unknown firmware version. Check connections.");
}

  delay(5);
  Serial.println("Hold your card close to the reader...");
  Serial.println();

  myservo.attach(3); // Attach servo to pin ~3
  myservo.write(0);  // Close the door (servo at 0 degrees)

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
  // Check for RFID card
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    // Read the RFID card's UID
    Serial.print("Card ID: ");
    String cardUID = ""; // Store the card's ID
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""); // Format the ID with leading zeros
      Serial.print(mfrc522.uid.uidByte[i], HEX);              // Print the ID in hexadecimal
      cardUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(mfrc522.uid.uidByte[i], HEX); // Concatenate the ID in hexadecimal
    }
    cardUID.toUpperCase(); // Convert to uppercase
    Serial.println(cardUID);
    Serial.println(cardUID == "B3 42 32 0E");

    // Check if the card UID matches the authorized card
    if (cardUID == "B3 42 32 0E") {
      // Unlock the door and indicate with green LED
      digitalWrite(7, HIGH);
      myservo.write(90); // Open the door (servo at 90 degrees)
      delay(2000);       // Keep the door open for 2 seconds
      myservo.write(0);  // Close the door (servo at 0 degrees)
      digitalWrite(7, LOW);
      Serial.println("Access granted. Welcome!");
      Serial.println();
      delay(3000); // Wait for a few seconds
    } else {
      // Unauthorized card, indicate with red LED
      digitalWrite(6, HIGH);
      delay(1000); // Show red LED for 1 second
      digitalWrite(6, LOW);
      Serial.println("Access denied. Unauthorized card.");
      delay(3000); // Wait for a few seconds
    }

    mfrc522.PICC_HaltA(); // Halt the card
  }
}

The servo turned a bit when I uploaded the code

There is a difference between the the first number (read from the card in the for-loop) and the second number. That is strange and I have no idea why that is happening.

Before you enter the for-loop to read the uid bytes, I would add the below

    Serial,print(F("There are "));
    Serial.print(mfrc522.uid.size);
    Serial.println(F(" uid bytes");)

This should print the number of uid bytes and might explain why you only have 3 bytes in the the first number.

That should be without the spaces between bytes in the String representation.

Another approach could be to directly compare the uid bytes against a valid card.

void loop()
{
  // Check for RFID card
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
  {
    // Read the RFID card's UID
    Serial.print("Card ID: ");

    byte validCard[] = { 0xB3, 0x42, 0x32, 0x0E };
    // if there is a mismatch in the number of bytes
    if (mfrc522.uid.size != sizeof(validCard))
    {
      Serial.println("OOPS");
    }
    else
    {
      // if the uid bytes match the card
      if (memcmp(mfrc522.uid.uidByte, validCard, sizeof(validCard)) == 0)
      {
        Serial.println("match");
      }
      // if the uid bytes do not match the card
      else
      {
        Serial.println("no match");
      }
    }

    mfrc522.PICC_HaltA();  // Halt the card
  }
}

I can not test as I don't have a reader/cards but it does compile.

It works now. THANKS SO MUCH

So what was the solution? Maybe post your updated sketch in a new reply.

If your problem is solved, you can mark it as such by clicking the little checkbox button under the most useful reply.

Heres the updated code

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

// Define RFID RC522 pins
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

// Define servo motor and LED pins
Servo myservo;

const int redLedPin = 6;
const int greenLedPin = 7;

// Define variables
boolean doorLocked = true; // Initially, the door is locked
int attemptCount = 0;      // Variable to track failed attempts
const int maxAttempts = 3; // Max number of attempts before lockout
const int lockoutTime = 30000; // Time in milliseconds to lock out the system

void setup() {
  Serial.begin(9600);  // Start the communication with your computer
  SPI.begin();         // Initialize the SPI communication.
  mfrc522.PCD_Init();  // Initialize the RFID reader.
  byte firmwareVersion = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print("Firmware Version: 0x");
Serial.println(firmwareVersion, HEX);
if (firmwareVersion == 0x92) {
  Serial.println("RC522 v2.0 detected.");
} else if (firmwareVersion == 0x91 || firmwareVersion == 0x90) {
  Serial.println("RC522 v1.0 detected.");
} else {
  Serial.println("Unknown firmware version. Check connections.");
}

  delay(5);
  Serial.println("Hold your card close to the reader...");
  Serial.println();

  myservo.attach(3); // Attach servo to pin ~3
  myservo.write(0);  // Close the door (servo at 0 degrees)

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
   // Check if the system is in lockout mode
  if (attemptCount >= maxAttempts) {
    Serial.println("Max attempts reached. Locking out for 30 seconds.");
    digitalWrite(redLedPin, HIGH); // Show red LED to indicate lockout
    delay(lockoutTime); // Wait for lockout time
    digitalWrite(redLedPin, LOW); // Turn off red LED after lockout time
    attemptCount = 0; // Reset attempt counter
    return; // Skip the rest of the loop until lockout is over
  }

  // Check for RFID card
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
    {
    // Read the RFID card's UID
    Serial.print("Card ID: ");

    // Print the number of UID bytes
    Serial.print(F("There are "));
    Serial.print(mfrc522.uid.size);
    Serial.println(F(" uid bytes"));

     byte validCard[] = { 0xB3, 0x42, 0x32, 0x0E };
    // if there is a mismatch in the number of bytes
    if (mfrc522.uid.size != sizeof(validCard))
     {
      Serial.println("OOPS");
     }
      else
     {
      // if the uid bytes match the card
      if (memcmp(mfrc522.uid.uidByte, validCard, sizeof(validCard))== 0)
      {
        Serial.println("match");
      }
      // if the uid bytes do not match the card
      else
      {
        Serial.println("no match");
      }
     }
    String cardUID = ""; // Store the card's ID
    for (byte i = 0; i < mfrc522.uid.size; i++) {
      Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : ""); // Format the ID with leading zeros
      Serial.print(mfrc522.uid.uidByte[i], HEX);              // Print the ID in hexadecimal
      cardUID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "") + String(mfrc522.uid.uidByte[i], HEX); // Concatenate the ID in hexadecimal
    }
    cardUID.toUpperCase(); // Convert to uppercase
    Serial.println(cardUID);
    Serial.println(cardUID == "B342320E");

    // Check if the card UID matches the authorized card
    if (cardUID == "B342320E") {
      // Unlock the door and indicate with green LED
      digitalWrite(7, HIGH);
      myservo.write(110); // Open the door (servo at 90 degrees)
      delay(2000);       // Keep the door open for 2 seconds
      myservo.write(15);  // Close the door (servo at 0 degrees)
      digitalWrite(7, LOW);
      Serial.println("Access granted. Welcome!");
      Serial.println();
      attemptCount = 0;  // Reset the attempt counter after successful access
      delay(3000); // Wait for a few seconds
    } else {
      // Unauthorized card, indicate with red LED
      digitalWrite(6, HIGH);
      delay(1000); // Show red LED for 1 second
      digitalWrite(6, LOW);
      Serial.println("Access denied. Unauthorized card.");
      attemptCount++; // Increment failed attempt counter
      delay(3000); // Wait for a few seconds
    }

    mfrc522.PICC_HaltA(); // Halt the card
  }
}
}

and I think the solution was

 byte validCard[] = { 0xB3, 0x42, 0x32, 0x0E };
    // if there is a mismatch in the number of bytes
    if (mfrc522.uid.size != sizeof(validCard))
    {
      Serial.println("OOPS");
    }
    else
    {
      // if the uid bytes match the card
      if (memcmp(mfrc522.uid.uidByte, validCard, sizeof(validCard)) == 0)
      {
        Serial.println("match");
      }
      // if the uid bytes do not match the card
      else
      {
        Serial.println("no match");
      }
    }

I don't think it was because you did not do anything with it (except for printing match / no match).

Your servo is still controlled by a modified version of the original code. I think that your solution was

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