How to Use the RFID RC522 Module with Arduino Uno: Door Lock and Card Reader

Intro

You tap a card to enter your hostel, to mark attendance at the office, or to open a metro gate — and the door opens without a key, a password or a fingerprint. The technology behind that tap is RFID, and the cheapest way to learn it is a small blue board called the RC522.

The RC522 is a 13.56 MHz RFID reader module built around the NXP MFRC522 chip. It reads the cards and key fobs that come in the box, each with its own unique ID number, and it talks to an Arduino over the SPI bus. In this guide, you will build a card door lock: tap the right card and a green LED lights up with a short beep; tap any other card and a red LED lights up with a double beep. The Arduino prints every card’s ID on the Serial Monitor, so you can see exactly what the reader sees.

You will learn how RFID works, why the module must run on 3.3 V and never on 5 V, how SPI wiring works, how the MFRC522 library reads a card, and how to write lock code that never blocks with delay(). The project is a solid base for a final-year project — an attendance system, a hostel door lock, or a library issue counter all start from this exact circuit.

Components Required

PartQuantityPurposePrice
RC522 RFID Reader Module (MFRC522, 13.56 MHz)1Reads RFID cards and key fobsAvailable on order — WhatsApp
Arduino Uno R3 DIP1Runs the MFRC522 library and the door lock codeRs 1,200
MB102 solderless breadboard, 830 points1Holds the LEDs, resistors and buzzer without solderingRs 250
Active Piezo Buzzer 3V–12V1Beeps for access granted and deniedRs 35
5 mm LED (green)1Lights up when the right card is tappedRs 6
5 mm LED (red)1Lights up when a wrong card is tappedRs 6
220 Ω resistor2Protect the two LEDs from too much currentAvailable on order — WhatsApp
40-pin male-to-male jumper wires10Connects the module, LEDs and buzzer to the UnoRs 180

The priced parts come to about Rs 1,677. The RC522 module and the 220 Ω resistors are available on order — message us on WhatsApp for the current price. The module normally comes with one white S50 card and one blue key fob in the box, so you have two tags to test with from day one.

How RFID Works

RFID stands for Radio Frequency Identification. The system has two halves: a reader and a tag. The tag — the white card or the blue key fob — is passive, which means it has no battery at all. Inside it is a tiny chip and a flat coil antenna printed on the card.

When you hold the card near the reader, the reader’s antenna sends out a 13.56 MHz radio field. That field does two jobs at once: it powers the tag’s chip through the coil, and it carries the reader’s question. The powered chip answers by sending back its UID — a unique identification number, 4 bytes long for the S50 cards that come with the module. The reader checks that number and decides what to do. The whole exchange takes a fraction of a second, and it works through a wallet, a pocket or a thin plastic case, as long as the card is within about 3 cm of the reader.

The RC522 is a high-frequency (HF) reader. It only understands 13.56 MHz cards that follow the ISO/IEC 14443 A standard — the MIFARE family. It cannot read 125 kHz low-frequency tags, and it cannot read a phone’s NFC payment cards in the way a payment terminal does, even though the frequency is the same. Knowing that limit saves you a confusing afternoon: if a tag does not read at all, it is usually the wrong frequency, not a broken module.

The 3.3 V rule: the one thing you must not get wrong

The MFRC522 chip runs on 2.5 V to 3.3 V. The RC522 module takes its power from the Arduino Uno’s 3.3V pin — and only from that pin. Connecting the module’s 3.3V pin to the Uno’s 5V pin will damage the chip. The signal pins (SDA, SCK, MOSI, MISO, RST) connect directly to the Uno’s digital pins as shown in the wiring table; that is the standard wiring from the MFRC522 library examples. Power is the only part where a mistake is expensive: 3.3 V, always.

Key specifications of the MFRC522 chip (NXP MFRC522 datasheet, Rev. 3.9):

SpecificationValue
Operating frequency13.56 MHz
StandardISO/IEC 14443 A / MIFARE and NTAG
Supported cardsMIFARE Mini, MIFARE 1K, MIFARE 4K, MIFARE Ultralight, MIFARE DESFire EV1, MIFARE Plus
Host interfacesSPI up to 10 Mbit/s, I2C up to 400 kBd, UART up to 1228.8 kBd
Power supply2.5 V to 3.3 V
FIFO buffer64 bytes send and receive
Transfer speedUp to 848 kBd in both directions
Typical operating distanceUp to 50 mm, depending on antenna size and tuning
Crystal27.12 MHz
Extra featuresCRC coprocessor, internal self-test, programmable timer

The RC522 module built around this chip adds a printed antenna on the board, a 3.3 V regulator circuit and an 8-pin header. Module facts: about 60 × 39 mm, draws 13–26 mA while reading, and reads a card or fob from about 0 to 30 mm away. Keep metal away from the antenna area — a metal plate under the module shortens the range sharply.

RC522 Module Pinout and Wiring with Arduino Uno

The module has eight pins in a row, labelled on the board. Two of the names are easy to misread: SDA on this module means Slave Select (the SPI chip-select line), not the I2C SDA line — and IRQ is a pin the basic library examples never use, so it stays unconnected.

RC522 module pinMeaningArduino Uno pinWire colour used here
SDASPI chip select (Slave Select)D10Yellow
SCKSPI clockD13Blue
MOSISPI data, Arduino to moduleD11Orange
MISOSPI data, module to ArduinoD12Purple
IRQInterrupt output — not used here— (leave unconnected)—
GNDGroundGNDBlack
RSTReset — restarts the reader chipD9Teal
3.3VPower — 3.3 V ONLY, never 5 V3.3VRed

On the Uno, the SPI bus lives on fixed pins: MOSI is always D11, MISO is always D12 and SCK is always D13. Those three cannot move. SDA (chip select) and RST can be any digital pins — this guide uses D10 and D9, which is the MFRC522 library’s default example wiring.

The lock’s outputs sit on the MB102 breadboard with the Uno.

Lock partConnection
Green LED anode (+)D7, through a 220 Ω resistor
Green LED cathode (−)GND
Red LED anode (+)D8, through a 220 Ω resistor
Red LED cathode (−)GND
Active buzzer +D6
Active buzzer −GND

Each resistor goes between its Arduino pin and its LED anode. The buzzer in this guide is the active type, which sounds when its pin is HIGH — a passive buzzer looks the same but needs a tone() signal, so check which type you have first.

RFID RC522 door lock circuit diagram with Arduino Uno

Library Installation

This project needs two libraries. SPI is built into the Arduino IDE. The RFID library is installed from the Library Manager:

  1. In the Arduino IDE, open Sketch > Include Library > Manage Libraries.
  2. Search for “MFRC522” and install the one by GithubCommunity (the library by miguelbalboa).
  3. Restart the IDE if the examples do not appear.

The library talks to the module over SPI, reads the card’s UID, and handles the ISO 14443 A framing and error checking for you.

Complete Arduino Code

/*
  RFID RC522 Door Lock with Arduino Uno
  Tap a card on the RC522 reader. The reader sends the card's
  UID (a 4-byte unique ID) to the Arduino, which compares it
  with the authorised UID:
  - Right card: green LED lights for 2 seconds, one short beep.
  - Wrong card: red LED lights for 2 seconds, two short beeps.
  Every card's UID is printed on the Serial Monitor, so you can
  find your own card's UID and put it in AUTHORIZED_UID below.

  HOW TO SET YOUR OWN CARD:
  1. Upload this sketch with the placeholder UID.
  2. Tap your card and read the UID printed on the Serial Monitor.
  3. Replace the four numbers in AUTHORIZED_UID with your card's
     UID and upload again. Your card now opens the lock.

  All timing uses millis() - there is no delay() anywhere in
  loop(), so the reader keeps scanning while the LEDs are lit.

  Wiring:
    RC522 SDA  -> D10    (yellow)
    RC522 SCK  -> D13    (blue)
    RC522 MOSI -> D11    (orange)
    RC522 MISO -> D12    (purple)
    RC522 RST  -> D9     (teal)
    RC522 3.3V -> 3.3V   (red - NEVER 5V)
    RC522 GND  -> GND    (black)
    Green LED anode (+) -> D7 through a 220 ohm resistor
    Red LED anode (+)   -> D8 through a 220 ohm resistor
    LED cathodes (-) -> GND
    Active buzzer + -> D6, buzzer - -> GND
*/

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN 9          // RC522 RST
#define SS_PIN 10          // RC522 SDA (SPI chip select)
#define GREEN_LED_PIN 7    // Green LED anode through a 220 ohm resistor
#define RED_LED_PIN 8      // Red LED anode through a 220 ohm resistor
#define BUZZER_PIN 6       // Active buzzer + (sounds on HIGH)

// REPLACE these four numbers with your own card's UID, read from
// the Serial Monitor. The UID is printed in hex, two digits per
// byte, for example: 0xA3, 0x7F, 0x2B, 0x91
const byte AUTHORIZED_UID[4] = {0x12, 0x34, 0x56, 0x78};

const unsigned long SIGNAL_MS = 2000;   // LEDs stay lit for 2 seconds
const unsigned long BEEP_MS = 150;      // Length of one beep

MFRC522 mfrc522(SS_PIN, RST_PIN);

unsigned long signalEnd = 0;
unsigned long lastBeepToggle = 0;
bool buzzerOn = false;
int beepsLeft = 0;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(GREEN_LED_PIN, LOW);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(BUZZER_PIN, LOW);
  Serial.println("RFID Door Lock ready");
  Serial.println("Tap a card on the reader");
}

void loop() {
  unsigned long now = millis();

  // Switch the signal LEDs off once their 2 seconds are up.
  if (signalEnd != 0 && now >= signalEnd) {
    digitalWrite(GREEN_LED_PIN, LOW);
    digitalWrite(RED_LED_PIN, LOW);
    signalEnd = 0;
  }

  // Beep pattern, also non-blocking: while beeps remain, the
  // buzzer toggles every 150 ms. One beep for granted, two for denied.
  if (beepsLeft > 0) {
    if (now - lastBeepToggle >= BEEP_MS) {
      lastBeepToggle = now;
      if (buzzerOn) {
        digitalWrite(BUZZER_PIN, LOW);
        buzzerOn = false;
        beepsLeft--;
      } else {
        digitalWrite(BUZZER_PIN, HIGH);
        buzzerOn = true;
      }
    }
  } else if (buzzerOn) {
    digitalWrite(BUZZER_PIN, LOW);
    buzzerOn = false;
  }

  // No new card, or the card could not be read: wait for the next tap.
  if (!mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  if (!mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  // Print the card's UID in hex, two digits per byte.
  Serial.print("Card UID: ");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    if (mfrc522.uid.uidByte[i] < 0x10) {
      Serial.print("0");
    }
    Serial.print(mfrc522.uid.uidByte[i], HEX);
    Serial.print(" ");
  }
  Serial.println();

  // Compare the card's UID with the authorised UID, byte by byte.
  bool granted = true;
  if (mfrc522.uid.size != 4) {
    granted = false;
  } else {
    for (byte i = 0; i < 4; i++) {
      if (mfrc522.uid.uidByte[i] != AUTHORIZED_UID[i]) {
        granted = false;
        break;
      }
    }
  }

  if (granted) {
    Serial.println("ACCESS GRANTED");
    digitalWrite(GREEN_LED_PIN, HIGH);
    digitalWrite(RED_LED_PIN, LOW);
    beepsLeft = 1;
  } else {
    Serial.println("ACCESS DENIED");
    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(GREEN_LED_PIN, LOW);
    beepsLeft = 2;
  }
  signalEnd = now + SIGNAL_MS;
  lastBeepToggle = now;

  // Tell the card to stop answering so the same tap is not read
  // again and again while the card is still on the reader.
  mfrc522.PICC_HaltA();
}

Code Explanation

The two #define lines name the pins so the code reads like the wiring table — SS_PIN 10 is the RC522’s SDA pin, RST_PIN 9 is its reset pin. The MFRC522 object is created with those two pins, and the authorised UID is stored as four bytes you replace with your own card’s UID.

setup() opens the Serial port at 9600, starts the SPI bus, and initialises the reader with PCD_Init(). The LED and buzzer pins are set as outputs, all starting LOW, and two lines tell you the lock is ready.

loop() does three jobs, all on millis() timing. First, it switches the signal LEDs off once their 2 seconds are up. Second, it runs the beep pattern: while beeps remain, the buzzer toggles every 150 ms — one beep for a granted card, two for a denied one — and it is forced silent when the pattern ends.

Third, it watches for a card. PICC_IsNewCardPresent() returns true only when a new card enters the field, and PICC_ReadCardSerial() reads the card’s UID into mfrc522.uid. If either fails, the loop returns early and keeps waiting — no blocking, no delay. When a card is read, the UID is printed in hex with a leading zero for small bytes, so a byte like 0x07 prints as “07” and not “7”. Then the code compares the UID with AUTHORIZED_UID byte by byte: any single byte different means denied. Finally, PICC_HaltA() tells the card to stop answering, so one tap is read exactly once even if you leave the card on the reader.

The one thing you will definitely change is AUTHORIZED_UID. Upload the sketch as it is, tap your card, read the UID from the Serial Monitor, paste those four numbers into the array, and upload again. From then on, only that card opens the lock.

Demonstration: Expected Serial Monitor Output

If you have never uploaded code before, see our guide on how to upload code in Arduino Uno.

Upload the code, then open the Serial Monitor with Tools > Serial Monitor and set the baud rate to 9600. You should see:

RFID Door Lock ready
Tap a card on the reader

Now tap the white card that came with the module. The green or red LED lights for 2 seconds, the buzzer beeps, and the Serial Monitor shows something like this — your card’s numbers will be different:

Card UID: A3 7F 2B 91
ACCESS DENIED

That is expected on the first run: the placeholder UID does not match your card. Copy the four numbers from your card, put them in AUTHORIZED_UID as 0xA3, 0x7F, 0x2B, 0x91, upload again, and tap the same card:

Card UID: A3 7F 2B 91
ACCESS GRANTED

Tap the blue key fob instead, and it is denied again — it has a different UID. That is the whole lock: the reader does not know names, only numbers, and the Arduino decides by the number.

Troubleshooting

  1. The card is not detected at all. Hold the card flat on the reader, within 3 cm, and keep it still for a second. A card waved past quickly is often missed. Also check the 3.3 V wire: the module’s power LED should be lit, and the module must be on 3.3V, never 5V.
  2. “MFRC522.h: No such file or directory” when compiling. The library is not installed. Install “MFRC522” by GithubCommunity from Sketch > Include Library > Manage Libraries — the error message names the missing file, so install the library that provides it.
  3. The UID prints but the lock always says ACCESS DENIED. The UID in AUTHORIZED_UID does not match your card. Copy the four numbers exactly as the Serial Monitor prints them, including leading zeros, and write them as hex with the 0x prefix: a printed “07” becomes 0x07, not 7 and not 0x7.
  4. The same tap is read many times in a row. That happens if PICC_HaltA() is missing or the card is left on the reader while the code loops. The sketch already calls PICC_HaltA() after each read — check it is still there if you edited the code.
  5. The reader works once, then stops responding. The module’s reset line may be loose — check the RST wire on D9. Also check that the module is powered from 3.3V: a module fed from 5V can behave strangely before it fails completely.
  6. The code compiles but nothing prints on the Serial Monitor. Check the baud rate — it must be 9600, the same as Serial.begin(9600) — and that you selected Arduino Uno and the right COM port under Tools.
  7. The LED works but the buzzer never sounds. Check the polarity: the + pin goes to D6 and the − pin to GND. Also check the type — this guide uses an active buzzer, which sounds on a plain HIGH signal, while a passive buzzer needs tone() and stays silent on digitalWrite().
  8. A phone or a metro card does nothing. That is expected: the RC522 only reads 13.56 MHz ISO 14443 A / MIFARE cards. Phones and transport cards use different protocols on the same frequency, and 125 kHz tags are a different frequency entirely.

Project Ideas and FYP Ideas Using an RFID RC522 Module

  1. Attendance system for a classroom or office. Add an LCD1602 to show each student’s name against their card UID, and log the UID with the time to the Serial Monitor — or to an SD card module for a proper register. A relay can mark late entries separately.
  2. Hostel room door lock. Add a relay module and a solenoid lock so the right card actually opens the door, with the red LED and buzzer for wrong cards. Add a push button inside so the door opens from the inside without a card.
  3. Library book issue counter. Stick a tag on each book and give every student a card: tap the student card, then the book tag, and the Arduino records the issue. Two readers, one Arduino — the second reader needs its own SDA pin.
  4. RFID parking barrier. A card tap lifts a servo-driven barrier arm for authorised cars and logs the entry time. The same lock code drives the servo instead of the green LED.
  5. Prepaid canteen card. Store a balance for each UID in the Arduino’s memory, deduct a fixed amount per tap, and show the remaining balance on an LCD. Resetting balances needs a master card — a good extension for a final-year report.
  6. Exam hall entry check. Each student’s card is checked against a list of registered UIDs before entry, with a buzzer for unregistered cards. The list can live in the code for a small hall or on an SD card for a large one.

Frequently Asked Questions

What is the RFID RC522 module price in Pakistan?

The RC522 module is available on order from QKZee Technologies — message us on WhatsApp at +92-302-8577025 for the current price. The rest of this project costs about Rs 1,677 with the parts listed above.

Does the RC522 need a library?

Yes. Install “MFRC522” by GithubCommunity from the Library Manager. SPI itself is built into the Arduino IDE and needs no install.

Can the RC522 read my phone or my metro card?

No, not usefully. The RC522 only reads 13.56 MHz ISO 14443 A / MIFARE cards. Phones and transport cards use different protocols, and 125 kHz tags are a different frequency entirely.

Can someone copy my RFID card?

A MIFARE Classic card’s UID can be read by any reader, so a plain UID check is not real security — it is a learning lock, not a bank vault. Real access systems also check the card’s encrypted data blocks, which this guide does not cover. For a student project or a hostel room, the UID check is the right starting point.

How far away does the RC522 read a card?

About 0 to 30 mm — the card must be held close to the reader, almost touching it. Metal near the antenna shortens the range further.

Why must the RC522 run on 3.3 V?

The MFRC522 chip’s supply range is 2.5 V to 3.3 V. Powering it from 5 V will damage it. Use the Uno’s 3.3V pin, and only that pin.

Conclusion

You have built a working card lock from a reader, a tag and a few lines of code — and you have learned the three things that matter: the 13.56 MHz field that powers a passive tag and reads its UID, the SPI bus that connects the reader to the Arduino, and the honest limits, that a UID check is identification and not encryption, and that the module must never see 5 V power. The same circuit grows into bigger projects: add a relay and it opens a real door, add an LCD and it greets each student by name, add an SD card and it keeps an attendance register.

Components for this project are available at QKZee Technologies, with nationwide Cash on Delivery across Pakistan. Message us on WhatsApp at +92-302-8577025 to order the RC522 module and the rest of the parts, or visit our shop at https://qkzeetech.com/shop-2/.

If you missed them, our HC-SR04 ultrasonic sensor guide, our DHT11 temperature and humidity guide, our relay module guide and our MQ-2 gas sensor guide build on the same wiring and millis() skills.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *