Skip to content

Identification / RFID · Arduino Uno guide

Interfacing RC522 RFID/NFC Reader Module with Arduino Uno

A 3.3 V SPI reader for 13.56 MHz cards, fobs and stickers: read UIDs, build a card allow-list, and read or write MIFARE and NTAG memory.

Updated November 16, 2026 Arduino C++MFRC522Also forESP32

What is the RC522?

The RC522 is the little blue board that turns a card or key fob into a password. Built around NXP's MFRC522 chip, it creates a 13.56 MHz magnetic field, wakes any ISO/IEC 14443A tag that comes within a few centimetres, and hands your microcontroller the tag's unique ID over SPI, fast enough that a tap feels instant.

It can also read and write the memory inside MIFARE Classic and NTAG tags, which is why it sits behind so many door locks, attendance systems, tool check-outs and "tap to start" gadgets. This page explains how it works, what every pin does, which tags it can and cannot read, and the mistakes that cost people an evening. When you are ready to build, jump to the Arduino Uno guide or the ESP32 guide.

Specifications

Frequency
13.56 MHz
Supply voltage
3.3 V
Interface
SPI
Typical range
3-5 cm
Standard
ISO/IEC 14443A
Chip
NXP MFRC522
Chip supply range
2.5 V to 3.6 V
Tags it can talk to
MIFARE Mini / 1K / 4K, Ultralight, NTAG, DESFire (UID)
Max SPI clock
10 Mbit/s
Other chip interfaces
I2C, UART (not broken out on this module)
Supply current, TX on
60 mA typical, 100 mA max
Power-down current
5 µA max (RST held low)
Logic level
3.3 V
FIFO buffer
64 bytes
Crystal
27.12 MHz
Board size
about 60 × 40 mm
Header
8 pins, 2.54 mm pitch
Usually included
1 MIFARE Classic 1K card + 1 key fob

Chip figures come from the NXP MFRC522 datasheet. Range, board size and the included tags are typical for the common blue module and vary by seller. NXP quotes up to 50 mm for the chip with a suitable antenna; the tiny PCB loop on this board and a credit-card tag give 3-5 cm in practice.

Pinout

PinNameDescription
1SDASPI chip select (SS / NSS), active LOW. The silkscreen says SDA because the same pin is the I2C data line on the bare chip.
2SCKSPI clock, driven by the microcontroller.
3MOSISPI data from the microcontroller to the reader.
4MISOSPI data from the reader back to the microcontroller.
5IRQInterrupt output from the chip. Optional; the common libraries poll instead, so leave it unconnected.
6GNDGround. Must be shared with the microcontroller.
7RSTReset / power-down. LOW puts the chip into hard power-down, a rising edge restarts it. Any free digital pin works.
83.3VSupply input, 3.3 V only. Never connect this to 5 V.

Pin order is the order printed on the board, left to right.

Wiring & code

Setting up RC522 with Arduino Uno

Library

MFRC522 by GithubCommunity (miguelbalboa)

Arduino IDE > Sketch > Include Library > Manage Libraries > search "MFRC522" > install "MFRC522" by GithubCommunity

Library guide

This guide takes an RC522 from a bag of parts to a working card reader on an Arduino Uno in about twenty minutes. You will build the four required 5 V-to-3.3 V signal dividers, check that the reader is alive, read the UID of a card, create an allow-list that lights a green or red LED, and write text into a MIFARE Classic card before reading it back. The wiring, resistor values and sketches are kept consistent throughout the guide.

What you need

ItemQtyNote
Arduino Uno R3 (or Nano, or Uno R4)1Any board with hardware SPI on D11, D12 and D13 uses the wiring below unchanged
RC522 module1Usually sold with a MIFARE 1K card and a key fob
Jumper wires8Female-to-male if your module header is soldered, male-to-male for a breadboard
LED (green) and LED (red)1 eachOptional, for the allow-list sketch
220 Ω resistors2One per LED
USB cable1For power and upload
100 µF capacitor1Optional, across 3V3 and GND near the module if reads drop out
1 kΩ resistors4Series resistors for SS, SCK, MOSI and RST voltage dividers
2 kΩ resistors4Pull-down resistors for the four 5 V to 3.3 V dividers

Build time about 20 minutes. Difficulty: beginner.

Wiring

Component pinArduino Uno pinNote
SDA (SS)D10Chip select. Uno D10 output must pass through a 1 kΩ series / 2 kΩ to GND divider before RC522 SDA (SS).
SCKD13Uno D13 SCK output: use a 1 kΩ series / 2 kΩ to GND divider before the RC522.
MOSID11Uno D11 MOSI output: use a 1 kΩ series / 2 kΩ to GND divider before the RC522.
MISOD12Direct connection. RC522 MISO is a 3.3 V output read by the Uno.
RSTD9Uno D9 RST output: use a 1 kΩ series / 2 kΩ to GND divider before the RC522.
GNDGNDConnect grounds directly; all four dividers share this ground.
3.3V3V3Power. Use the 3V3 pin, never 5V

IRQ stays unconnected. For SS, SCK, MOSI and RST, build four separate dividers: Uno pin → 1 kΩ → RC522 signal; the RC522-side node also connects through 2 kΩ to GND. MISO is direct.

Why these pins? On the Uno, SPI lives on three fixed hardware pins: D11 (MOSI), D12 (MISO) and D13 (SCK). Only the chip-select (D10) and reset (D9) are free to move. If you use a Mega 2560, the hardware SPI pins are different (50 MISO, 51 MOSI, 52 SCK, 53 SS), so rewire to those.

Optional LEDs for the allow-list sketch

Component pinArduino Uno pinNote
Green LED anode (+)D7Through a 220 Ω resistor; cathode to GND
Red LED anode (+)D6Through a 220 Ω resistor; cathode to GND

Warning

Power the RC522 from a regulated 3.3 V supply only—never from the Uno 5 V pin. The Uno 3V3 output is rated for 50 mA. The MFRC522 datasheet lists 60 mA typical / 100 mA maximum for the transmitter supply under a continuous-wave test condition; that figure is not a universal measurement of total current drawn by every RC522 breakout. Actual module current depends on the board, antenna and operating mode. Because the Uno 3V3 pin has limited headroom, use a separate regulated 3.3 V supply if the module is unstable or its measured current exceeds the available budget; connect the grounds together. A 100 µF capacitor close to the module can help with supply dips.

The 5 V question

The Uno's outputs swing to 5 V; the RC522 is a 3.3 V part. Plenty of tutorials connect them directly and it usually keeps working; some even describe the signal pins as "5 V tolerant". We have not found that guarantee for a 3.3 V-powered MFRC522, so we treat 5 V signalling as unproven and out of spec. If you want a permanent build, only the lines the Uno sends need attention.

Which lines need level shifting

LineDirectionNeeds shifting?Simple fix
SS (D10)Uno to RC522YesDivider: 1 kΩ in series, 2 kΩ to GND
SCK (D13)Uno to RC522YesSame divider
MOSI (D11)Uno to RC522YesSame divider
RST (D9)Uno to RC522YesSame divider
MISO (D12)RC522 to UnoNoA 3.3 V signal is read as HIGH by the Uno (threshold is about 3 V)

A 1 kΩ + 2 kΩ divider turns 5 V into about 3.3 V. At SPI speeds the library uses it is fast enough. A 4-channel logic level converter does the same job more neatly.

Install the library

  1. 1In the Arduino IDE open Sketch > Include Library > Manage Libraries (or press Ctrl+Shift+I).
  2. 2Search for MFRC522 and install the one by GithubCommunity (the library by miguelbalboa). Version 1.4.12 is current at the time of writing.
  3. 3Choose Tools > Board > Arduino Uno and select the correct Port.
  4. 4Open the Serial Monitor at 115200 baud after every upload.

Tip

Tutorials that tell you to download a ZIP from GitHub are out of date: the library is in the Library Manager now, so you also get automatic update prompts.

Sketch 1 - Is the reader alive?

Always start here. It does not need a card; it only asks the chip for its firmware version over SPI. If this works, your wiring, power and SS/RST pins are right, and any later problem is about tags or code, not hardware.

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

constexpr uint8_t SS_PIN  = 10;   // RC522 "SDA" pin = SPI chip select
constexpr uint8_t RST_PIN = 9;

MFRC522 rfid(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  delay(4);                         // some modules need a moment after init

  rfid.PCD_DumpVersionToSerial();   // prints e.g. "Firmware Version: 0x92 = v2.0"

  byte v = rfid.PCD_ReadRegister(MFRC522::VersionReg);
  if (v == 0x00 || v == 0xFF) {
    Serial.println(F("No answer from the reader. Check 3.3 V, GND and the SS/SCK/MOSI/MISO/RST wires."));
  } else {
    Serial.println(F("Reader is alive. Now try Sketch 2 and tap a card."));
  }
}

void loop() {}

You should see a firmware version of 0x92 (v2.0) or 0x91 (v1.0). Clone chips often report something else and still work. A value of 0x00 or 0xFF means nothing is answering: go to the troubleshooting flowchart below.

Sketch 2 - Read any card's UID

This is the sketch you will reuse in almost every RFID project. PICC_IsNewCardPresent() asks "is a card in the field?", PICC_ReadCardSerial() reads its UID, and the two calls at the end tell the card to stand down so it is not read again and again while it sits on the reader.

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

constexpr uint8_t SS_PIN  = 10;
constexpr uint8_t RST_PIN = 9;

MFRC522 rfid(SS_PIN, RST_PIN);

// Prints a UID as AA:BB:CC:DD (always two hex digits per byte).
void printUid(const MFRC522::Uid &uid) {
  for (byte i = 0; i < uid.size; i++) {
    if (i) Serial.print(':');
    if (uid.uidByte[i] < 0x10) Serial.print('0');
    Serial.print(uid.uidByte[i], HEX);
  }
}

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  Serial.println(F("Tap a card, fob or sticker..."));
}

void loop() {
  // Both calls must succeed: "a card is in the field" and "I read its serial".
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;

  MFRC522::PICC_Type type = rfid.PICC_GetType(rfid.uid.sak);
  Serial.print(F("UID: "));
  printUid(rfid.uid);
  Serial.print(F("  (")); Serial.print(rfid.uid.size); Serial.print(F(" bytes)  type: "));
  Serial.println(rfid.PICC_GetTypeName(type));

  rfid.PICC_HaltA();        // park this card so it is not re-read in a loop
  rfid.PCD_StopCrypto1();   // clear any authentication state
}

Tap each card, fob and sticker you own and note the UIDs it prints. A MIFARE Classic card normally shows 4 bytes (for example 39:C3:BB:99); NTAG stickers show 7. You will paste your own UIDs into the next sketch.

Sketch 3 - A card allow-list with green and red LEDs

This turns the reader into the heart of an access-control system: known cards light the green LED, everyone else gets the red one. Replace the two example UIDs with the ones you collected in Sketch 2.

The comparison uses memcmp on raw bytes instead of building strings. It is shorter, uses no heap memory and cannot be fooled by differences in upper and lower case.

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

constexpr uint8_t SS_PIN    = 10;
constexpr uint8_t RST_PIN   = 9;
constexpr uint8_t GREEN_LED = 7;
constexpr uint8_t RED_LED   = 6;

// Paste the UIDs that Sketch 2 printed for YOUR cards (4-byte UIDs).
const byte ALLOWED[][4] = {
  {0xDE, 0xAD, 0xBE, 0xEF},
  {0x12, 0x34, 0x56, 0x78},
};
constexpr size_t ALLOWED_COUNT = sizeof(ALLOWED) / sizeof(ALLOWED[0]);

MFRC522 rfid(SS_PIN, RST_PIN);

bool isAllowed(const MFRC522::Uid &uid) {
  if (uid.size != 4) return false;               // this list only stores 4-byte UIDs
  for (size_t i = 0; i < ALLOWED_COUNT; i++) {
    if (memcmp(uid.uidByte, ALLOWED[i], 4) == 0) return true;
  }
  return false;
}

void blink(uint8_t pin, uint16_t ms) {
  digitalWrite(pin, HIGH);
  delay(ms);
  digitalWrite(pin, LOW);
}

void setup() {
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  Serial.println(F("Access control ready. Tap a card."));
}

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

  if (isAllowed(rfid.uid)) {
    Serial.println(F("ACCESS GRANTED"));
    blink(GREEN_LED, 1000);
  } else {
    Serial.println(F("ACCESS DENIED"));
    blink(RED_LED, 400);
  }

  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}
Flowchart of the scan loop: check for a card, read its serial, compare against the allow-list, grant or deny, then halt the card

Tip

To open a real door, replace the green LED with a relay module or a servo. The logic does not change. The SolderHub Simulator has a servo 'gate' variant of this circuit you can try first.

Sketch 4 - Write text to a card and read it back

MIFARE Classic cards are tiny databases. This sketch authenticates with the factory key, writes 16 bytes into block 4 (the first data block of sector 1), reads them back and prints both the text and the hex. A static_assert at the top stops the sketch compiling if you pick block 0 or a sector trailer by accident.

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

constexpr uint8_t SS_PIN  = 10;
constexpr uint8_t RST_PIN = 9;
constexpr uint8_t BLOCK   = 4;     // first data block of sector 1

// Refuse to compile if someone changes BLOCK to something dangerous.
static_assert(BLOCK != 0 && (BLOCK % 4) != 3,
  "Pick a data block: not block 0 (manufacturer data) and not a sector trailer.");

MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;

void finish() {
  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}

void setup() {
  Serial.begin(115200);
  SPI.begin();
  rfid.PCD_Init();
  for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;   // factory default key
  Serial.println(F("Tap a MIFARE Classic card to write and read block 4."));
}

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

  MFRC522::PICC_Type type = rfid.PICC_GetType(rfid.uid.sak);
  if (type != MFRC522::PICC_TYPE_MIFARE_MINI &&
    type != MFRC522::PICC_TYPE_MIFARE_1K &&
    type != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Not a MIFARE Classic card, skipping."));
    finish();
    return;
  }

  // Every sector is locked by the key stored in its trailer block.
  const byte trailer = (BLOCK / 4) * 4 + 3;
  MFRC522::StatusCode st = rfid.PCD_Authenticate(
    MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailer, &key, &rfid.uid);
  if (st != MFRC522::STATUS_OK) {
    Serial.print(F("Auth failed: ")); Serial.println(rfid.GetStatusCodeName(st));
    finish();
    return;
  }

  // 16 bytes exactly: 15 characters + a zero.
  byte data[16] = {0};
  memcpy(data, "SolderHub RC522", 15);

  st = rfid.MIFARE_Write(BLOCK, data, 16);
  if (st != MFRC522::STATUS_OK) {
    Serial.print(F("Write failed: ")); Serial.println(rfid.GetStatusCodeName(st));
    finish();
    return;
  }
  Serial.println(F("Write OK"));

  byte buf[18];                       // 16 data bytes + 2 CRC bytes
  byte size = sizeof(buf);
  st = rfid.MIFARE_Read(BLOCK, buf, &size);
  if (st != MFRC522::STATUS_OK) {
    Serial.print(F("Read failed: ")); Serial.println(rfid.GetStatusCodeName(st));
    finish();
    return;
  }

  Serial.print(F("Block 4 text: "));
  for (byte i = 0; i < 16; i++) Serial.print(buf[i] >= 32 && buf[i] < 127 ? (char)buf[i] : '.');
  Serial.print(F("\nBlock 4 hex : "));
  for (byte i = 0; i < 16; i++) {
    if (buf[i] < 0x10) Serial.print('0');
    Serial.print(buf[i], HEX);
    Serial.print(' ');
  }
  Serial.println();

  finish();
}

Danger

Do not change BLOCK to 3, 7, 11 or any other trailer block (every fourth block counting from 3). Writing bad keys or access bits there locks the sector for good.

Troubleshooting on the Uno

Work through the flowchart from the top; each question rules out one layer of the problem.

Troubleshooting flowchart for the RC522: firmware version over SPI, UID on tap, block read or write, then stability under Wi-Fi or relay load, each with its fix

Uno-specific problems

  • Version 0x00 / 0xFF, or 'Communication failure'

    Cause
    Wiring, no 3.3 V, or SS/RST pin mismatch
    Fix
    Re-check the table above against your sketch's SS_PIN and RST_PIN; measure 3.3 V at the module
  • Works on USB, resets when a card is tapped

    Cause
    The Uno's 3V3 pin is overloaded
    Fix
    Separate 3.3 V regulator and a 100 µF capacitor, grounds joined
  • Nothing works on a Mega 2560

    Cause
    Hardware SPI is on 50-53, not 10-13
    Fix
    Use 50 (MISO), 51 (MOSI), 52 (SCK) and 53 or any pin for SS
  • Another SPI device (SD card, display) stops working

    Cause
    Two devices answering at once
    Fix
    Give every SPI device its own chip-select pin; keep only one LOW at a time
  • Compile error: MFRC522.h: No such file

    Cause
    Library not installed
    Fix
    Install 'MFRC522' by GithubCommunity from the Library Manager
  • Compile error: 'MFRC522::StatusCode' has not been declared

    Cause
    Old library version
    Fix
    Update the library to 1.4.x
  • Same card is reported over and over

    Cause
    Missing PICC_HaltA() / PCD_StopCrypto1()
    Fix
    Add both calls at the end of loop(), as in all sketches here

Arduino Uno FAQ

Does this work on an Uno R4, Nano or Pro Mini? Yes. They use the same SPI pins (D11, D12, D13), so the wiring and sketches work unchanged. A 3.3 V Pro Mini is a particularly good match because it needs no level shifting.

Can I use a different SS or RST pin? Yes. Change SS_PIN and RST_PIN in the sketch and move the wire. MOSI, MISO and SCK cannot move on an Uno because they are hardware SPI.

Can I run two RC522 readers on one Uno? Yes. Share SCK, MOSI, MISO and power, give each reader its own SS pin, and create two MFRC522 objects.

Why does the sketch print at 115200 baud? The reader can dump a lot of text quickly, and the library's own examples use 115200. Make sure the Serial Monitor matches.

How long can the wires be? Keep them as short as practical; under about 20 cm is comfortable. Long SPI wires are a classic cause of intermittent failures.

What should I try next? Add an LCD to show the card holder's name, a servo to open a gate, or a buzzer for feedback. The SolderHub Simulator has ready-made starting points for each.

Where next? Show who tapped on an LCD1602 I2C display or a 0.96" OLED, open a latch with an SG90 servo, or add feedback with a passive buzzer. Prefer Wi-Fi logging? Try the ESP32 guide.

Understanding the Uno sketches

Sketch 1 — reader check: SPI.begin() starts the Uno hardware SPI peripheral. The MFRC522 object uses D10 as chip select and D9 as reset. PCD_Init() configures the reader, and PCD_ReadRegister(VersionReg) reads its version register. A value of 0x00 or 0xFF is a useful sign that communication has failed, but a plausible version value alone does not prove that every tag operation will work.

Sketch 2 — UID reading: PICC_IsNewCardPresent() checks for a newly detected card; PICC_ReadCardSerial() retrieves its serial/UID. uid.size tells the sketch how many UID bytes were received, so the print function does not assume every card has a four-byte UID. The loop prints each byte in hexadecimal, padding values below 0x10 with a leading zero. PICC_HaltA() halts the selected card, while PCD_StopCrypto1() clears the reader authentication state.

Sketch 3 — LED allow-list: ALLOWED is an array of two example four-byte UIDs; replace them with values read from your own cards. isAllowed() first checks the UID length, then uses memcmp() to compare the raw bytes. This example intentionally rejects seven-byte UIDs rather than accidentally comparing only part of them. blink() turns on the selected LED for the requested duration and then turns it off. This example demonstrates program flow, not secure access control: see the security warning on the component page.

Sketch 4 — MIFARE Classic block access: The sketch first checks the detected card type, then calculates the sector trailer for block 4 and authenticates with Key A. It writes exactly 16 bytes to the data block and reads the block into an 18-byte buffer because the library reserves room for the 16 data bytes plus CRC bytes. The factory key FF FF FF FF FF FF is commonly used on new cards, but it is not safe to leave as a production credential. Use a spare test card: writing a block changes the card contents. The static assertion prevents selecting block 0 or a block whose number ends in 3, but this simple guard is intended for the example block in the small-sector layout; do not treat it as a general block allocator for every sector of a MIFARE Classic 4K card.

Keep learning

Related guides & projects