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.
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.
There were a few things that were messing me up here:
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.
If the connection is lost at any point, it will no longer function and needs to be reset.
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 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 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?