RFID access control

Tap the RFID card from your kit to unlock: a green light for cards you allow, a red warning for everyone else.
  • Level:Intermediate
  • Duration: 1 h
  • Ages 12+
  • Platform: Arduino
Community project EEMENTOR team
RFID access control – EEMENTOR STEM™ project

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

Breadboard wiring diagram: RFID access control
Breadboard view. Check each connection against the wiring table below.
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

  1. Install the MFRC522 library (by GithubCommunity) in Tools → Manage Libraries.
  2. Wire the reader and the two LEDs as in the diagram. Double-check that the reader is on 3V3.
  3. Upload the code and open the Serial Monitor at 9600 baud.
  4. Hold your card on the reader. The Serial Monitor shows its ID, ready to copy, for example {0x3A, 0x7F, 0x12, 0xC4}.
  5. Paste that line into the allowed list in the code and upload again.
  6. 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

Leave a comment

Please note, comments need to be approved before they are published.

Build it yourself

Get the parts used in this project, tested by our engineers.

UNO R3 Starter Kit | Arduino IDE Compatible | Free Tutorials $56.00

Shop the parts

More projects

  • Pulse visualiser

    • Level:Intermediate
    • Duration: 45 min
    • Platform: Arduino

    by EEMENTOR team

  • Flame alarm

    • Level:Beginner
    • Duration: 40 min
    • Platform: Arduino

    by EEMENTOR team

Community projects

Built something awesome? Share it.

Send us your project and we'll feature it in the hub, credited to you, so other makers can learn from it.

  1. Sign in and tell us about your build
  2. Our team reviews your submission
  3. We publish it in the hub, credited to you