Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Arduino & Microcontrollers

Arduino RFID Tutorial: RC522 Module for Access Control

Arduino RFID Tutorial: RC522 Module for Access Control

March 11, 2026 /Posted byJayesh Jain / 0

RFID (Radio Frequency Identification) technology powers everything from office access badges to library book tracking and contactless payment systems. The RC522 RFID module is a 13.56 MHz reader that works beautifully with Arduino via SPI, and at its price point it is one of the best ways to add physical access control to a maker project. In this tutorial you will learn exactly how to wire, program, and extend the RC522 into a complete keycard door-lock system.

Table of Contents

  • How RFID Works at 13.56 MHz
  • RC522 Module Overview
  • Hardware Required
  • Wiring RC522 to Arduino
  • Installing the MFRC522 Library
  • Reading Card UIDs
  • Building an Access Control System
  • Writing Data to RFID Cards
  • Troubleshooting
  • FAQ

How RFID Works at 13.56 MHz

RFID systems consist of two parts: a reader (the RC522 module) and transponders (cards, key fobs, or stickers). The reader generates an electromagnetic field at 13.56 MHz. When a compatible transponder enters this field (typically within 3–5 cm for passive tags), it harvests energy from the field to power its own tiny chip and transmits back a unique identifier.

The RC522 uses the ISO/IEC 14443A standard, which covers common MIFARE cards and fobs. A MIFARE Classic 1K card contains 1 kilobyte of EEPROM organised into 16 sectors, each with 4 blocks of 16 bytes. This storage lets you write custom data — usernames, access levels, timestamps — beyond just reading the factory UID.

Why 13.56 MHz instead of 125 kHz? The higher frequency enables faster data transfer, supports encryption (MIFARE Classic uses a proprietary Crypto1 algorithm), and allows more sophisticated multi-block read/write operations.

Recommended: Arduino Uno R3 Beginners Kit — comes with the Arduino Uno, breadboard, and jumper wires needed to get started with this RC522 tutorial immediately.

RC522 Module Overview

The MFRC522 IC from NXP Semiconductors is the heart of this module. The breakout board typically includes:

  • Operating frequency: 13.56 MHz
  • Supported standards: ISO 14443A (MIFARE Classic, MIFARE Ultralight, NTAG)
  • Interface: SPI (primary), I2C and UART also supported
  • Operating voltage: 2.5V–3.3V (logic) — not 5V tolerant!
  • SPI speed: Up to 10 Mbit/s
  • Read range: up to 5 cm (card-dependent)
  • IRQ pin: Can trigger interrupts on card detection

Critical note: The RC522 operates at 3.3V logic. On a 5V Arduino Uno, the SPI MOSI and SCK signals at 5V can damage the RC522 over time. Use a logic level converter on those lines, or power the Arduino from 3.3V, or — as many makers do — simply rely on the 3.3V tolerance of the RC522 inputs (which are weakly 5V tolerant in practice but not guaranteed). For a production system, always use a level converter.

Hardware Required

  • Arduino Uno, Nano, or Mega
  • RC522 RFID reader module
  • MIFARE Classic 1K cards or key fobs (usually included with the RC522 kit)
  • Jumper wires (female-to-male recommended)
  • Breadboard
  • Optional: 5V relay module + 12V solenoid lock for actual door control
  • Optional: LED (green + red) and buzzer for feedback

Wiring RC522 to Arduino

The RC522 uses SPI. Arduino Uno’s hardware SPI pins are on digital pins 10–13:

RC522 Pin Arduino Uno Pin Notes
SDA (SS) 10 Chip select
SCK 13 SPI clock
MOSI 11 Master out slave in
MISO 12 Master in slave out
IRQ Unconnected Optional interrupt
GND GND
RST 9 Reset pin
3.3V 3.3V Do NOT connect to 5V
Recommended: Arduino Mega 2560 R3 Board — if you want to combine RFID with a keypad, OLED display, and relay module in one build, the Mega’s extra pins and memory make it the right choice.

Installing the MFRC522 Library

  1. Open the Arduino IDE.
  2. Go to Sketch → Include Library → Manage Libraries.
  3. Search for MFRC522.
  4. Install the library by GithubCommunity (author: miguelbalboa).

This library abstracts all low-level SPI communication with the RC522 and provides high-level functions for UID reading, authentication, and block read/write on MIFARE cards.

Reading Card UIDs

The simplest and most common use case is reading the 4-byte or 7-byte UID from a MIFARE card. Every card has a globally unique UID burned in at manufacture. Here is the sketch:

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

#define SS_PIN  10
#define RST_PIN  9

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  Serial.println("Scan a MIFARE card...");
}

void loop() {
  // Look for a new card
  if (!mfrc522.PICC_IsNewCardPresent()) return;

  // Select one of the cards
  if (!mfrc522.PICC_ReadCardSerial()) return;

  // Print UID to Serial Monitor
  Serial.print("UID tag: ");
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  }
  Serial.println();

  mfrc522.PICC_HaltA();       // Halt the card
  mfrc522.PCD_StopCrypto1();  // Stop encryption on PCD
}

Upload the sketch, open Serial Monitor at 9600 baud, and tap your MIFARE card or fob against the antenna. You should see output like: UID tag: A3 4F 12 7B. Note this value — you will need it to whitelist cards for access control.

Building an Access Control System

Now for the real project: a system that grants or denies access based on registered card UIDs, activates a relay (for a door lock or alarm), and gives LED + buzzer feedback.

Additional Wiring

  • Green LED: anode → D5 (via 220Ω resistor), cathode → GND
  • Red LED: anode → D6 (via 220Ω resistor), cathode → GND
  • Buzzer: positive → D7, negative → GND
  • Relay module IN → D4 (controls the door lock)

Sketch: Multi-Card Access Control

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

#define SS_PIN   10
#define RST_PIN   9
#define GREEN_LED 5
#define RED_LED   6
#define BUZZER    7
#define RELAY     4

MFRC522 mfrc522(SS_PIN, RST_PIN);

// Authorised card UIDs — replace with your own
const byte allowedUIDs[][4] = {
  {0xA3, 0x4F, 0x12, 0x7B},   // Card 1 (admin)
  {0xDE, 0xAD, 0xBE, 0xEF},   // Card 2 (user)
};
const int numAllowed = sizeof(allowedUIDs) / 4;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED,   OUTPUT);
  pinMode(BUZZER,    OUTPUT);
  pinMode(RELAY,     OUTPUT);
  digitalWrite(RELAY, LOW);
  Serial.println("Access Control Ready");
}

bool isAuthorised(byte *uid, byte size) {
  if (size != 4) return false;
  for (int i = 0; i < numAllowed; i++) {
    bool match = true;
    for (int j = 0; j < 4; j++) {
      if (uid[j] != allowedUIDs[i][j]) { match = false; break; }
    }
    if (match) return true;
  }
  return false;
}

void grantAccess() {
  Serial.println("ACCESS GRANTED");
  digitalWrite(GREEN_LED, HIGH);
  digitalWrite(RELAY, HIGH);  // Unlock door
  tone(BUZZER, 1000, 200);
  delay(3000);                // Keep door unlocked for 3 seconds
  digitalWrite(RELAY, LOW);
  digitalWrite(GREEN_LED, LOW);
}

void denyAccess() {
  Serial.println("ACCESS DENIED");
  digitalWrite(RED_LED, HIGH);
  tone(BUZZER, 300, 500);
  delay(1000);
  digitalWrite(RED_LED, LOW);
}

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent()) return;
  if (!mfrc522.PICC_ReadCardSerial()) return;

  if (isAuthorised(mfrc522.uid.uidByte, mfrc522.uid.size)) {
    grantAccess();
  } else {
    denyAccess();
  }

  mfrc522.PICC_HaltA();
  mfrc522.PCD_StopCrypto1();
}

Replace the UID values in allowedUIDs with the actual UIDs you read from your cards in the previous step. The relay activates for 3 seconds on access grant — enough time to open a door. Adjust as needed.

Recommended: Arduino Nano 33 IoT with Header — add Wi-Fi to your access control system to log card swipes to a cloud dashboard or receive instant mobile notifications on access attempts.

Writing Data to RFID Cards

Beyond reading UIDs, you can write custom data to MIFARE Classic 1K cards. Each card has 16 sectors with 4 blocks of 16 bytes each. Block 0 of sector 0 contains the UID (factory-locked). Use blocks 1–2 of any sector for your custom data.

Authentication First

MIFARE sectors are protected by 6-byte keys (Key A and Key B). Factory default Key A is FF FF FF FF FF FF. Always authenticate before reading or writing a block:

MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;

MFRC522::StatusCode status = mfrc522.PCD_Authenticate(
  MFRC522::PICC_CMD_MF_AUTH_KEY_A,
  blockAddr,   // e.g. block 4
  &key,
  &mfrc522.uid
);
if (status != MFRC522::STATUS_OK) {
  Serial.println("Auth failed");
  return;
}

Write a 16-Byte Block

byte dataBlock[16] = {
  'Z','b','o','t','i','c','.','i','n',
  0,0,0,0,0,0,0
};
status = mfrc522.MIFARE_Write(4, dataBlock, 16);
if (status != MFRC522::STATUS_OK) {
  Serial.println("Write failed");
}

This kind of data writing lets you store user names, access levels, or encrypted tokens directly on the card — useful for offline access control where no network lookup is possible.

Recommended: Multifunction Shield for Arduino Uno / Leonardo — provides LEDs, a buzzer, and a 4-digit display on a single shield, saving you breadboard wiring for the access control feedback circuit.

Troubleshooting

Card Not Detected

  • Confirm 3.3V power — powering the RC522 from 5V can damage it.
  • Check SPI wiring — MOSI/MISO are commonly swapped by accident.
  • Ensure the SS (SDA) pin matches the pin number in your sketch.
  • Test with mfrc522.PCD_DumpVersionToSerial(); to verify the module responds via SPI.

Intermittent Reads

  • Keep SPI wires short and away from power wires.
  • Add a 100nF bypass capacitor between 3.3V and GND near the RC522.
  • Ensure no other SPI devices share the bus without proper chip-select management.

Authentication Fails on Write

  • The card may have been previously configured with a non-default key. Use a MIFARE key recovery tool or a fresh card.
  • Ensure you are authenticating the correct block number and sector.

Frequently Asked Questions

Can I use RC522 with ESP8266 or ESP32?

Yes. Both run at 3.3V, making them even better partners for the RC522. Use hardware SPI pins: on ESP8266, SPI is on GPIO 14 (SCK), 13 (MOSI), 12 (MISO), and 15 (SS). On ESP32, default SPI pins are 18 (SCK), 23 (MOSI), 19 (MISO), and 5 (SS). Include the same MFRC522 library — it works unchanged.

How many cards can I register in the access control sketch?

With the UID array approach shown above, you are limited by SRAM. Arduino Uno has 2KB SRAM — storing 100 × 4-byte UIDs uses only 400 bytes, so you can comfortably store hundreds of UIDs. For thousands of users, consider storing UIDs in EEPROM or an external SD card.

Is MIFARE Classic secure enough for real access control?

MIFARE Classic’s Crypto1 cipher was cracked in 2008. For low-security applications (home, workshop, hobby), it is fine. For professional installations, use MIFARE DESFire EV2/EV3 or NTAG424 DNA cards with AES-128 encryption. The RC522 does not support DESFire — you would need a PN532 or ACR122U reader.

Can the RC522 detect multiple cards simultaneously?

The ISO 14443A anti-collision algorithm allows the RC522 to detect multiple cards in the field, but it reads them one at a time using the anti-collision loop. The MFRC522 library handles single-card scenarios by default. For multi-card enumeration, use PICC_HaltA() after processing each card to move to the next.

What is the maximum read range of the RC522?

Typically 3–5 cm with the standard PCB antenna. The read range depends heavily on the transponder (cards read further than small key fobs), antenna orientation, and metal objects nearby which detune the antenna. For longer range (up to 30 cm), you would need a high-gain antenna and a different reader IC like the MFRC630.

Build Your RFID Project Today

The RC522 RFID module is one of the most rewarding components to work with on Arduino — the combination of physical interaction (tapping a card) and digital response makes projects feel tangible and impressive. Whether you are securing a workshop, building a library book tracker, or creating an IoT-connected attendance system, the RC522 + Arduino combination delivers reliable results.

Explore the full range of Arduino boards and modules at zbotic.in — everything you need for your RFID project is available with fast delivery across India.

Tags: access control, Arduino, mfrc522, rc522, rfid, SPI, tutorial
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Raspberry Pi VPN Server: WireG...
blog raspberry pi vpn server wireguard setup in 30 minutes 595061
blog raspberry pi opencv lane detection for autonomous cars 595063
Raspberry Pi OpenCV Lane Detec...

Related posts

Svg%3E
Read more

Arduino Batch Programming: Flash Multiple Boards Quickly

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Based Radar System with Ultrasonic Sensor

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Automatic Plant Monitor: Sunlight, Moisture, Temperature

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Lie Detector: GSR Sensor Polygraph Project

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading
Svg%3E
Read more

Arduino Metal Detector: Build a Treasure Finder

April 1, 2026 0
Table of Contents Introduction Components and Hardware Setup Wiring Diagram and Connections Complete Code with Explanation Customization and Improvements Troubleshooting... Continue reading

Add comment Cancel reply

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

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now