Build an RFID Access Demo
SensorsSecurityInputs
Tap a card, unlock something -- the exact same technology behind a hotel key card, built and coded by you.
6 real parts included
Total for this kit: 1,735.00 ฿
Doesn't include any order discount you may get at checkout.
What you'll need
ESP32-C3 SuperMini Development Board — Wi-Fi & Bluetooth, USB-C
670.00 ฿
RC522 RFID Reader Kit — with Card & Keyfob
305.00 ฿
Active Buzzer Module — 12mm
235.00 ฿
830-Point Solderless Breadboard
125.00 ฿
Jumper Wire Kit — Male-Male, Male-Female, Female-Female
220.00 ฿
USB-C Data & Charging Cable — 1m
180.00 ฿
Wiring Diagram
Starter Code
#include <SPI.h>
#include <MFRC522.h>
#define SPI_SCK_PIN 4 // ESP32-C3 default hardware SPI pins - adjust to match your board's silkscreen if different
#define SPI_MISO_PIN 5
#define SPI_MOSI_PIN 6
#define RFID_SS_PIN 7 // RC522 SDA/SS - any free digital GPIO
#define RFID_RST_PIN 10 // RC522 RST - any free digital GPIO
#define BUZZER_PIN 2 // Active buzzer signal - any digital output GPIO
MFRC522 mfrc522(RFID_SS_PIN, RFID_RST_PIN);
// Add the real UIDs of your own cards/keyfobs here after reading them from
// Serial on first boot (see the scanned UID printout). Each UID is the byte
// sequence MFRC522 reports for that tag.
byte authorizedUIDs[][4] = {
{0xDE, 0xAD, 0xBE, 0xEF}, // placeholder - replace with your card's real UID
};
const int NUM_AUTHORIZED = sizeof(authorizedUIDs) / sizeof(authorizedUIDs[0]);
void printUID(byte *uid, byte size) {
for (byte i = 0; i < size; i++) {
Serial.print(uid[i] < 0x10 ? " 0" : " ");
Serial.print(uid[i], HEX);
}
Serial.println();
}
bool isAuthorized(byte *uid, byte size) {
if (size != 4) return false;
for (int i = 0; i < NUM_AUTHORIZED; i++) {
bool match = true;
for (int j = 0; j < 4; j++) {
if (authorizedUIDs[i][j] != uid[j]) { match = false; break; }
}
if (match) return true;
}
return false;
}
void beepGranted() {
digitalWrite(BUZZER_PIN, HIGH);
delay(400);
digitalWrite(BUZZER_PIN, LOW);
}
void beepDenied() {
for (int i = 0; i < 3; i++) {
digitalWrite(BUZZER_PIN, HIGH);
delay(100);
digitalWrite(BUZZER_PIN, LOW);
delay(100);
}
}
void setup() {
Serial.begin(115200);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
SPI.begin(SPI_SCK_PIN, SPI_MISO_PIN, SPI_MOSI_PIN, RFID_SS_PIN);
mfrc522.PCD_Init();
Serial.println("RFID Access Demo ready - scan a card or keyfob");
Serial.println("Scanned UIDs print below - copy your own into authorizedUIDs[]");
}
void loop() {
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.print("Scanned UID:");
printUID(mfrc522.uid.uidByte, mfrc522.uid.size);
if (isAuthorized(mfrc522.uid.uidByte, mfrc522.uid.size)) {
Serial.println("Access granted");
beepGranted();
} else {
Serial.println("Access denied");
beepDenied();
}
mfrc522.PICC_HaltA();
mfrc522.PCD_StopCrypto1();
delay(1000); // avoid re-triggering instantly on the same tag
}Not sure about a step? Ask us