Page 1 of 1

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!

Help with MFRC522 R...
Clear all

[Solved] Help with MFRC522 RFID Reader: Reading Data and Detecting Card Removal

1 Posts
1 Users
Joined: 1 second ago
Posts: 0
Topic starter  

Hello everyone,

I'm working on a project using the MFRC522 RFID reader with Arduino, and I've encountered a couple of challenges that I'm hoping to get some advice on. My project involves detecting an RFID card, reading a nickname stored in a specific block on the card, and accurately detecting when the card is removed from the reader. I'm using the MFRC522 library for this purpose.

1. Reading a Nickname from a Block: I've successfully managed to read the UID of the card and can authenticate with a specific block to attempt reading data. However, I'm specifically interested in reading a "nickname" (a simple string) stored in one of the blocks. Here's the relevant part of my code:

// Authentication and reading block code snippet
if (mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid)) == MFRC522::STATUS_OK) {
    byte buffer[18];
    byte size = sizeof(buffer);
    if (mfrc522.MIFARE_Read(block, buffer, &size) == MFRC522::STATUS_OK) {
        // Code to process and print the data
    } else {
        Serial.println(F("Failed to read block"));
} else {
    Serial.println(F("Authentication failed"));

I can read the block, but I'm having trouble ensuring the data read is correctly interpreted as a string and displayed without including non-printable characters or padding.

2. Detecting Card Removal: My second challenge is reliably detecting when a card is removed from the reader. I attempted to implement a simple presence check, but I'm encountering false "Card Removed" messages even when the card is still present. I'm looking for a reliable way to detect card removal without false triggers.


  • Does anyone have suggestions on how to properly read and interpret a string from a block of data on an RFID card using the MFRC522 library?
  • What are the best practices for reliably detecting the removal of an RFID card with the MFRC522 reader?

Any advice, code snippets, or pointers to relevant resources would be greatly appreciated. I'm relatively new to working with RFID in Arduino projects, so detailed explanations or examples would be especially helpful.

Thank you in advance for your help!