Hello
I'm using a MFRC522 module to read the UID of some RFID stickers. The stickers I got cheaply from Ebay where they are described as "Ntag213 NFC Tags Sticker 13.56 MHZ ISO 14443A Universal Lable RFID Tag"
Most of the time, the module reads the UID correctly, but occasionally there is an error in one (or more) of the bytes. I can't detect any particular pattern - for example no tag seems more error prone.
I'm using an Arduino pro mini so everything is at 3.3V
Below is the code I'm using. (As you can see I'm summing the bytes so I can quickly see if there is a discrepancy).
Is there anything I can do to improve the reading accuracy? Could the quality of the tags be an issue?
#include <MFRC522.h>
#include <SPI.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class
MFRC522::MIFARE_Key key;
void setup() {
Serial.begin(9600);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
delay(100);
}
void loop() {
rfid.PCD_Init(); // Init MFRC522
delay(100);
if( rfid.PICC_IsNewCardPresent())
{
readRFID();
}
delay(1000);
}
void readRFID()
{
rfid.PICC_ReadCardSerial();
Serial.println();
int cardtotal=0;
for (int i = 0; i <7; i++) {
Serial.print(rfid.uid.uidByte[i]);
Serial.print(" ");
cardtotal=cardtotal+(rfid.uid.uidByte[i]);
}
Serial.print("cardtotal = ");
Serial.println(cardtotal);
// Halt PICC
rfid.PICC_HaltA();
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
}