Help with my first project: Simple RFID Scanner

IDE: Arduino 1.8.19
USB: 3.0

I was trying a more complicated RFID scanner project and was having no luck so I decided to see if I can get the bare bones to work.

I've tried several tutorials and am currently following this one:

Simple RFID Scanner

I've only gotten a true on the Serial Monitor for mfrc522.PICC_IsNewCardPreset() but this seems to hit if any object goes over the scanner. And it's very flakey.

I'm getting nothing with .PICC_WakeupA or PICC_RequestA or PICC_ReadCardSerial. The tags are not being scanned.

Here's an image of my Arduino set up. Sorry the wires are not the right colors but I'm certain it follows the diagram: My Project

The schematics can be found at the end of the article. I am limited to two links for this post.

#include <SPI.h>
#include <MFRC522.h>
 
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);  
 
void setup()
{
  Serial.begin(9600);  
  SPI.begin();      
  mfrc522.PCD_Init();  
  Serial.println("Approximate your card to the reader...");
  Serial.println();

}
void loop()
{
 
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  else {
    Serial.println("CARD");
  }


  byte bufferATQA[10];
  byte bufferSize = sizeof(bufferATQA);
  byte result;
  if(mfrc522.PICC_WakeupA(bufferATQA, &bufferSize))
  {
    Serial.println("not woke");
  }
 
  if(mfrc522.PICC_RequestA(bufferATQA, &bufferSize))
  {
    Serial.println("not request");
  }


 
  if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial())
  {
    Serial.println("IT WORKS");
  }
 
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
  Serial.println("no read card");
    return;
  }
 
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "29 C2 07 5E") // Make sure you change this with your own UID number
  {
    Serial.println("Authorised access");
    Serial.println();
    delay(3000);
  }
 
 else   {
    Serial.println(" Access denied");
    delay(3000);
  }
}

I would start with finding out when, exactly, mfrc522.PICC_IsNewCardPresent() returns true. You are calling it multiple times. If it doesn't return 'true' again until the card goes away and comes back or a different card is present then your second call will return false.

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

#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("Approximate your card to the reader...");
  Serial.println();
}

void loop()
{
  static int count = 0;
  if (mfrc522.PICC_IsNewCardPresent())
  {
    Serial.print("New Card Present ");
    Serial.println(count++);
  }
  else
  {
    count = 0;
  }
    
  delay(500);
}

What shows on Serial Monitor when you run this sketch and put a card on the reader?

Your code will get:

Approximate your card to the reader...

Sometimes if the pin connector is loose it will hit IsNewCardPresent()

New Card Present 0

I can't find any consistency that trips IsNewCardPresent. Sometimes it hits if an object passes over the scanner, sometimes when it is disconnected entirely.

If your RFID Reader doesn't detect a card when it is present and detects cards that are not present then SOMETHING is badly broken. Did the MRFC522 library come with an example program? If that example doesn't work, the problem is likely in the hardware (the wiring or your device). Triple-check that the wiring matches the example. If the wiring is correct and the example still doesn't work, it might be time to buy a new RFID reader. :frowning:

Okay, I think I got the example DumpInfo to work from File > Examples > MFRC522 > DumpInfo

Card UID: C9 46 C0 6E
Card SAK: 08
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
61 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
14 59 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
58 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
Etcetera

There were a few things that were messing me up here:

  1. It's very difficult to get a connection with the sensor without soldering. I had to push on it to make sure the initial connection was working.

  2. If the connection is lost at any point, it will no longer function and needs to be reset.

  3. Some of the RFID tags I have don't read. The blank ones that came with the sensor do but others that came from other devices (in my case a drawer lock) don't read.

This is to be expected as there are various different types of RFID systems.

This will be my next question then, perhaps requiring a new topic.

I have several kinds of RFID tags, but only one is readable with the Arduino MFRC522 code. Ultimately for my intended project I would like to be able to use these other tags. (As a new user I cannot include enough links to the Amazon page for these tags)

"Tag A" - White cards and blue key rings that came with the sensor. These are the only ones currently readable by the Arduino code.

"Tag B" - White cards and blue key rings that came with a drawer/cabinet lock. I expected these to be readable by the code but I was mistaken. Paul pointed out how use another RFID system. I don't NEED these to work but just found this distinction interesting.

"Tag C" - Yarongtech RFID Circle Sticker Tag 13.56 mhz These little stickers are not readable with the code. For my ideal project, I would like to use these stickers. I was not able to search for any Arduino code that works with these.

"Tag D" - Yarongtech RFID sticker 13.56 Mhz Paper tag Same as TAG C. These are probably the same as Tag C but in a different shape.

"Tag E" - 125 khz RFID Sticker, PVC Material 1mm Thick Coin These also do not work with the Arduino code. Interestingly, they DO work with the drawer lock (which is useful to me). If I could get these to work with Arduino, they would be preferable to the blue key fobs but Tag C is still ideal.

So does any code exist that will have my sensor read some of these other tags?

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