Offices and hotels use RFID cards to open doors. In this project you build the same system: the RC522 reader identifies each card by its unique ID. Cards on your list switch on a green "access granted" light, and any other card makes the red light flash.
What you need
- UNO R3 board and USB cable
- RC522 RFID module and S50 card
- Green LED and red LED
- 2 resistors, 220 Ω
- Breadboard and jumper wires (all from the UNO R3 Starter Kit)
Important: 3.3 V only
The RC522 runs on 3.3 V. Connect its 3.3V pin to the UNO's 3V3 pin, never to 5V. If your RC522 came without pins attached, solder the pin header first.
Wiring

| From | To |
|---|---|
| RC522 SDA | UNO pin 10 |
| RC522 SCK | UNO pin 13 |
| RC522 MOSI | UNO pin 11 |
| RC522 MISO | UNO pin 12 |
| RC522 IRQ | Not connected |
| RC522 GND | GND (breadboard − rail) |
| RC522 RST | UNO pin 9 |
| RC522 3.3V | UNO 3V3 |
| UNO pin 5 | 220 Ω resistor, then the green LED's long leg |
| UNO pin 6 | 220 Ω resistor, then the red LED's long leg |
| Both LEDs' short legs | GND (breadboard − rail) |
Build it step by step
- Install the MFRC522 library (by GithubCommunity) in Tools → Manage Libraries.
- Wire the reader and the two LEDs as in the diagram. Double-check that the reader is on 3V3.
- Upload the code and open the Serial Monitor at 9600 baud.
- Hold your card on the reader. The Serial Monitor shows its ID, ready to copy, for example
{0x3A, 0x7F, 0x12, 0xC4}. - Paste that line into the
allowedlist in the code and upload again. - Tap your card: the green LED lights. Any other card or tag makes the red LED flash.
The code
#include <SPI.h>
#include <MFRC522.h>
const int SS_PIN = 10;
const int RST_PIN = 9;
const int GREEN_LED = 5;
const int RED_LED = 6;
MFRC522 rfid(SS_PIN, RST_PIN);
// Paste the IDs of the cards you want to allow (shown in the Serial Monitor)
byte allowed[][4] = {
{0x00, 0x00, 0x00, 0x00}
};
const int ALLOWED_COUNT = sizeof(allowed) / sizeof(allowed[0]);
void printUid() {
Serial.print("Card ID: {");
for (byte i = 0; i < rfid.uid.size; i++) {
Serial.print("0x");
if (rfid.uid.uidByte[i] < 0x10) Serial.print("0");
Serial.print(rfid.uid.uidByte[i], HEX);
if (i < rfid.uid.size - 1) Serial.print(", ");
}
Serial.println("}");
}
bool isAllowed() {
if (rfid.uid.size != 4) return false;
for (int c = 0; c < ALLOWED_COUNT; c++) {
bool match = true;
for (byte i = 0; i < 4; i++) {
if (rfid.uid.uidByte[i] != allowed[c][i]) {
match = false;
break;
}
}
if (match) return true;
}
return false;
}
void setup() {
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
Serial.println("Tap a card on the reader");
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
printUid();
if (isAllowed()) {
Serial.println("Access granted");
digitalWrite(GREEN_LED, HIGH);
delay(2000);
digitalWrite(GREEN_LED, LOW);
} else {
Serial.println("Access denied");
for (int i = 0; i < 3; i++) {
digitalWrite(RED_LED, HIGH);
delay(200);
digitalWrite(RED_LED, LOW);
delay(200);
}
}
rfid.PICC_HaltA(); // stop reading this card
rfid.PCD_StopCrypto1();
}
How it works
The RC522 talks to the UNO over SPI, a fast connection that uses the clock (SCK), data in and out (MOSI and MISO) and a select line (SDA). When a card comes close, the reader powers it through its antenna coil and reads its unique ID. The sketch compares that ID with every entry in allowed, byte by byte, and lights the matching LED.
Make it your own
- Add the servo from the code-lock project to open a real latch for allowed cards.
- Use the active buzzer from the kit for a short beep on every scan.
- Count how many times each allowed card was used.
Troubleshooting
- Nothing happens when you tap the card: check the SPI wires (pins 10 to 13) and that the reader gets 3.3 V.
- "Access denied" for your own card: copy the ID exactly as shown, including all four bytes.
- Compile error about MFRC522.h: the library isn't installed.
Learn the basics first
New to these parts? These lessons explain them step by step: Set up the Arduino IDE and blink an LED and Read a 4×4 keypad.
0 comments