#include <SPI.h>
#include <MFRC522.h>
//MFRC522 Arduino UNO
//----------------------------
//VCC ─────▶ 3.3V
//GND ─────▶ GND
//RST ─────▶ D9 (Handled internally by the MFRC522 library)
//SDA ─────▶ D10 (Handled internally by the MFRC522 library)
//MOSI ─────▶ D11 (configured automatically by SPI.begin())
//MISO ─────▶ D12 (configured automatically by SPI.begin())
//SCK ─────▶ D13 (configured automatically by SPI.begin())
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN);
void setup(){
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
}
void loop(){
if (!rfid.PICC_IsNewCardPresent()) return;
if (!rfid.PICC_ReadCardSerial() ) return;
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.print("Message : ");
content.toUpperCase();
if (content.substring(1) == "BD 31 15 2B") {
Serial.println("Authorized access");
} else {
Serial.println(" Access denied");
}
delay(3000);
}