#include <SPI.h>
#include <MFRC522.h>
// Define the pins
#define SS_PIN 22 // SDA Pin
#define RST_PIN 5 // RST Pin
// Create an instance of the MFRC522 class
MFRC522 rfid(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin(); // Initialize SPI bus
rfid.PCD_Init(); // Initialize MFRC522
Serial.println("Place your card/tag near the RFID reader...");
}
void loop() {
// Look for new RFID cards
if ( ! rfid.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! rfid.PICC_ReadCardSerial()) {
return;
}
// Print the UID of the card
Serial.print("UID tag: ");
String content = "";
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(rfid.uid.uidByte[i], HEX);
content.concat(String(rfid.uid.uidByte[i] < 0x10 ? " 0" : " "));
content.concat(String(rfid.uid.uidByte[i], HEX));
}
Serial.println();
// Halt PICC
rfid.PICC_HaltA();
}