Seeeduino Xiao for RFID access control (RC522 reader)

Hi there,
first thing is you need to use the code tags above " </> "
paste it in there for it to look correct. Second whenever there’s a copy and paste from Internet examples the “xxx” quote marks are not ansi compatible, so errors will show up.
Here it is correctly posted.

//this is rev 30 but problem with LED not remaining on during card present

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MFRC522.h>
// OLED display configuration
#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 32  // OLED display height, in pixels
#define OLED_RESET -1  // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// RFID reader configuration
#define SS_PIN 3
#define RST_PIN 2
MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
// Pin configuration
const int whiteLED = 1;
const int cardAuthDelay = 2000;  // 2 seconds delay after card removal
String authorisedCard = "61877DEE";  // Replace with your card ID
void setup() {
  pinMode(whiteLED, OUTPUT);
  digitalWrite(whiteLED, LOW);
  Serial.begin(9600);  // Initialize serial communications
  SPI.begin();  // Init SPI bus
  mfrc522.PCD_Init();  // Init MFRC522
  delay(100);
  // Initialize OLED display with the I2C address (0x3C is common)
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;
  }
  display.display();
  delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print("Scan your card");
  display.display();
}

void loop() {
  // Look for new cards
  if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
    delay(50);
    return;
  }
  String cardID = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    cardID += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
    cardID += String(mfrc522.uid.uidByte[i], HEX);
 }
  cardID.toUpperCase();
  Serial.println(cardID);
  display.clearDisplay();
  display.setCursor(0, 0);
  if (cardID == authorisedCard) {
    display.print("Authorised");
    digitalWrite(whiteLED, HIGH);
    display.display();
    // Wait for the card to be removed
    while (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
      delay(50);
    }
    // Hold the LED on for an additional 2 seconds
    //delay(cardAuthDelay); // theo commented out
    digitalWrite(whiteLED, LOW);
  } else {
    display.print("Unauthorised");
    display.setCursor(0, 10);
    display.print("Speak to Theo");
    display.display();
    delay(2000);
  }
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Scan your card");
  display.display();
  mfrc522.PICC_HaltA();
}

Now about the code;
You should use a FLAG of some sort for card present test case. Set the flag to be true when it’s “Authorized” and test for it in your main LOOP or add function that Lights the LED that test for it to be True or false.
Note the polarity of the LED pin LOW lights the LED?
How the Device(reader is connected must be correct if you are getting the card present true, and I would NOT combine the test of card UUID and printing it, Seperate those to have a cleaner logic.
Post the picture of the connection if possible.
HTH
GL :slight_smile: PJ
:v: