I am working on a little RFID project but I am having one tiny problem.
I have a RC522 RFID Module connected to an Arduino UNO and I want to be able to read TAGS and then compare the read ID to a string.
The ID will get stored into a byte array with the size of 4.
For instance...
byte readTAG[4];
will hold...
{ C3, 7D, DF, C7 }
I now want to take this array and convert it into a String such as...
"C37DDFC7"
This way...I could do operations such as
if(readTag == "12345678") {
// Do something...
}
How would I go about doing this?
Thanks in advance!
Here is my code:
#include <MFRC522.h>
#include <SPI.h>
int RST_PIN = 9;
int SDA_PIN = 10;
byte readCard[4];
MFRC522 mfrc522(SDA_PIN, RST_PIN);
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
ReadTAG();
}
// Lese TAG aus und gebe die ID im Serial Monitor aus.
void ReadTAG() {
// Wenn ein neuer TAG vorhanden ist UND erfolgreich gelesen werden konnte, dann Lese TAG aus.
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
for (int i = 0; i < 4; i++) {
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println();
// Wenn der TAG ausgelesen wurde dann stoppe das Lesen da er sonnst das gleiche TAG vielemale ausließt.
mfrc522.PICC_HaltA();
}
}