Hello all,
This is my first post on this forum, because I have a problem that I can really not fix by myself.
I ordered a bunch of Mifare S50 tags from the internet. They were 1 euro a piece, and perfectly suit my needs for a NFC Tag. But something very strange is going on with those tags and my NFC Reader I ordered from AliExpress.
When I initially got the cards, they were all being scanned and their UID was recognized by the reader. After 1 day one of the S50 tags could not be read anymore; no matter how long I hold it to the reader or how often I take it off and put it back against it, it will not be scanned. It did not fall from a great height nor did I try to overwrite the tag, etc.
I've been looking on the internet for quite some time now but nobody has asked this before. Here is my code:
#include <SPI.h>
#include <MFRC522.h> // Library for Mifare RC522 Devices
#define SS_PIN 10
#define RST_PIN 9
const int ledGND = 0;
const int buzzer = 2;
const int RED = 3;
const int relay = 4;
const int BLUE = 5;
const int GREEN = 6;
const int ledValue = 20;
const int keys = 12;
const byte keyArray[keys][4] = {}; // This array contains all the keys UID, but removed here for security purposes
byte readCard[4];
int sum = 0;
int allowed = 0;
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, LOW);
digitalWrite(relay, LOW);
allLEDOff();
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
rgbLED(3, 500);
buzz(10, 50);
redLEDOff();
greenLEDOff();
blueLEDOn();
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return 0;
}
//Serial.print("{");
for (int i = 0; i < 4; i++) {
readCard[i] = mfrc522.uid.uidByte[i];
//Serial.print(readCard[i]);
//Serial.print(", ");
}
//Serial.println("},");
mfrc522.PICC_HaltA();
checkNumber(readCard);
}
void allLEDOff() {
redLEDOff();
greenLEDOff();
blueLEDOff();
}
void whiteLEDOn() {
redLEDOn();
greenLEDOn();
blueLEDOn();
}
void rgbLED(int repeat, int ttw) {
for( int i = 0 ; i < repeat ; i++ ) {
redLEDOn();
delay( ttw / 3);
redLEDOff();
greenLEDOn();
delay( ttw / 3);
greenLEDOff();
blueLEDOn();
delay( ttw / 3);
blueLEDOff();
}
}
void checkNumber(byte readArray[4] ) {
for(int i = 0; i < keys; i++) {
for(int j = 0; j < 4; j++) {
if ( readArray[j] == keyArray[i][j] ) {
sum++;
}
}
if(sum == 4) {
allowAccess();
}
sum = 0;
}
if(!allowed)
disallowAccess();
allowed = 0;
}
void allowAccess() {
allowed = 1;
blueLEDOff();
greenLEDOn();
buzz(2, 100);
openRelay( relay );
delay(500);
greenLEDOff();
blueLEDOn();
}
void disallowAccess() {
blueLEDOff();
redLEDOn();
buzz(1,650);
redLEDOff();
blueLEDOn();
}
void greenLEDOn() {
analogWrite(GREEN, ledValue);
}
void greenLEDOff() {
analogWrite(GREEN, ledGND);
}
void redLEDOn() {
analogWrite(RED, ledValue);
}
void redLEDOff() {
analogWrite(RED, ledGND);
}
void blueLEDOn() {
analogWrite(BLUE, ledValue);
}
void blueLEDOff() {
analogWrite(BLUE, ledGND);
}
void buzz(int repeat, int ttw) {
for(int i = 0; i < repeat; i++) {
digitalWrite(buzzer, HIGH);
delay( ttw );
digitalWrite(buzzer, LOW);
delay(ttw);
}
}
void openRelay( int output ) {
digitalWrite(output, HIGH);
delay(500);
digitalWrite(output, LOW);
}
Basically the checkNumber function is the one that compairs the scanned UID to the known UIDs. The tag gets scanned in the loop function.
All other tags are working fine, just not that single one. Strange thing is, I can perfectly scan it with my phone, but not with the reader.
Has anyone else encountered this before and knows how to fix the tag? I'm using the MFRC522 Library from GitHub - miguelbalboa/rfid: Arduino RFID Library for MFRC522.
Lukkie1998