RFID-RC522 UID Misread

Arduino: Nano

Modules: RTC DS3231, SD card Module, and RFID RC-522

I have been working on a project that will allow me to track time spent on projects by using RFID scanning to mark when I clock in and out of the workspace. I have built a prototype model which worked perfect, however when I built a secondary model in a case, the data file began being written without the UID number, instead this space is just filled with four zeros. However, there are some points in time where the UID number is listed correctly.

My intuition leads me to believe this is an issue with my wiring on this second model, as the second model was soldered together rather than using a breadboard, however I am uncertain how to test this in a logical way (maybe some use of a multimeter?). I will include below the code, fritzing drawing, and some of the erroneous data. I was hoping someone may point me in the right direction as to which connection is faulty, and more importantly how I can solve this problem for myself in the future.

#include <MFRC522.h> // for the RFID
#include <SPI.h> // for the RFID and SD card module
#include <SD.h> // for the SD card    
#include <RTClib.h> // for the RTC

// define pins for RFID
#define CS_RFID 10
#define RST_RFID 9
// define select pin for SD card module
#define CS_SD 4 

// Create a file to store the data
File myFile;

// Instance of the class for RFID

// Variable to hold the tag's UID
String uidString;

// Instance of the class for RTC
RTC_DS3231 rtc;

//Variable to hold user check in
int userCheckInHour;
int userCheckInMinute;

// Pins for LED
const int greenLED = 7;

void setup() {
  // Set LED as output
  pinMode(greenLED, OUTPUT);

  // Init Serial port
  while(!Serial); // for Leonardo/Micro/Zero
  // Init SPI bus
  // Init MFRC522 

  // Setup for the SD card
  Serial.print("Initializing SD card...");
  if(!SD.begin(CS_SD)) {
    Serial.println("initialization failed!");
  Serial.println("initialization done.");

  // Setup for the RTC  
  if(!rtc.begin()) {
    Serial.println("Couldn't find RTC");
  else {
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

void loop() {
  //look for new cards
  if(rfid.PICC_IsNewCardPresent()) {

void readRFID() {
  Serial.print("Tag UID: ");
  uidString = String(rfid.uid.uidByte[0]) + " " + String(rfid.uid.uidByte[1]) + " " + 
    String(rfid.uid.uidByte[2]) + " " + String(rfid.uid.uidByte[3]);
  // Light LED when a card is read
 digitalWrite(greenLED, HIGH);

void logCard() {
  // Enables SD card chip select pin
  // Open file
  myFile=SD.open("DATA.txt", FILE_WRITE);

  // If the file opened ok, write to it
  if (myFile) {
    Serial.println("File opened ok");
    myFile.print(", ");   
    // Save time on SD card
    DateTime now = rtc.now();
    myFile.print(now.year(), DEC);
    myFile.print(now.month(), DEC);
    myFile.print(now.day(), DEC);
    myFile.print(now.hour(), DEC);
    myFile.println(now.minute(), DEC);
    // Print time on Serial monitor
    Serial.print(now.year(), DEC);
    Serial.print(now.month(), DEC);
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.println(now.minute(), DEC);
    Serial.println("sucessfully written on SD card");

    // Save check in time;
    userCheckInHour = now.hour();
    userCheckInMinute = now.minute();
  else {
    Serial.println("error opening data.txt");  
  // Disables SD card chip select pin  


137 33 197 99, 2021/6/9,19:4
0 0 0 0, 2021/6/9,19:49
137 33 197 99, 2021/6/9,19:53
137 33 197 99, 2021/6/9,19:53
137 33 197 99, 2021/6/9,19:53
137 33 197 99, 2021/6/9,19:53
137 33 197 99, 2021/6/9,19:53
0 0 0 0, 2021/6/10,11:8

FYI this is a variation of the project linked below:

check the returned value of this call


if ( rfid.PICC_ReadCardSerial()) {
  // here you know read was a success 

1 Like

Thank you! Is there any chance you could explain why the UID is not registering without this line, but the chip will still scan?

The scanner might see or think to see a card but then the signal might be too weak or the data corrupted and the read fails.