Skip to content
Home > Components > Sensors > MFRC522 RFID Reader

MFRC522 RFID Reader

A popular SPI-based module for reading and writing 13.56MHz contactless smart cards and tags.

Component Preview

MFRC522 RFID ReaderRC522

The MFRC522 communicates over SPI and reads the unique UID from Mifare Classic RFID cards and key fobs. Each card has a different UID that your sketch can use to grant or deny access. In OpenHW Studio, right-click the component during simulation to configure card presence and edit the UID.

SensorsRFIDSPI

Overview

Radio Frequency Identification (RFID) uses electromagnetic fields to automatically identify and track tags attached to objects. The MFRC522 operates at 13.56 MHz.

CAUTION

Voltage Warning: The MFRC522 requires 3.3V power. Connecting its VCC pin to 5V will permanently damage the chip! (The logic pins are generally 5V tolerant, but the power pin is not).

Pin Reference

PinTypeDescription
3V3powerPower Supply (3.3V ONLY).
RSTdigitalReset Pin. Connect to Arduino D9.
GNDpowerGround. Connect to Arduino GND.
IRQdigitalInterrupt Request. Usually left unconnected.
MISOdigitalSPI Master In Slave Out. Connect to Arduino D12.
MOSIdigitalSPI Master Out Slave In. Connect to Arduino D11.
SCKdigitalSPI Clock. Connect to Arduino D13.
SDAdigitalSPI Chip Select (SS). Connect to Arduino D10.

Configurable Attributes

AttributeTypeDefaultDescription
cardUIDstringDE AD BE EFThe UID returned when a card is presented. Format as space-separated hex bytes.
cardPresentbooleanfalseToggle card presence during simulation. You can also do this via the right-click menu.

Wiring Diagram (Arduino Uno)

  1. Connect 3V3 to Arduino 3.3V (NOT 5V).
  2. Connect GND to Arduino GND.
  3. Connect RST to Arduino D9.
  4. Connect SDA to Arduino D10.
  5. Connect MOSI to Arduino D11.
  6. Connect MISO to Arduino D12.
  7. Connect SCK to Arduino D13.

Wiring Diagram

Example Arduino Code

Install the MFRC522 library by GithubCommunity before running this code.

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

#define RST_PIN  9
#define SS_PIN   10

MFRC522 rfid(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  
  // Initialize the MFRC522 module
  rfid.PCD_Init();
  
  Serial.println("Hold card near reader...");
}

void loop() {
  // Look for new cards
  if (!rfid.PICC_IsNewCardPresent()) {
    return;
  }
  
  // Select one of the cards
  if (!rfid.PICC_ReadCardSerial()) {
    return;
  }
  
  // Print the UID
  Serial.print("UID:");
  for (byte i = 0; i < rfid.uid.size; i++) {
    Serial.print(rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(rfid.uid.uidByte[i], HEX);
  }
  Serial.println();
  
  // Halt PICC to stop reading the same card repeatedly
  rfid.PICC_HaltA();
}

Simulation Notes

  • In OpenHW Studio, right-click the component during simulation to configure card presence and edit the UID. A glowing ripple animation on the module indicates when a card is actively being detected.

Released under the MIT License.