Built-in project · Arduino Uno R3

RC522 RFID reader (SS 10, RST 9), on an Arduino Uno

An RC522 RFID reader on the SPI pins with SDA (SS) on pin 10 and RST on pin 9: hold a card to it and the MFRC522 library prints the card’s ID. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $33. On Mokxi they're free.

RC522 RFID reader (SS 10, RST 9) · Arduino Uno R3live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

What you'll learn

  • How SPI uses MOSI, MISO, SCK and chip select
  • Reading a card's UID with the MFRC522 library
  • Why some parts need 3.3 V
  • Formatting bytes as hex
  • Difficulty: Beginner
  • Time: About 15 minutes
  • Board: Arduino Uno R3
  • Parts: 3

How it works

An RC522 reader talks to the Uno over SPI, the bus on pins 11, 12 and 13. The SDA pin, on pin 10, is the chip-select line that picks this reader. RST goes to pin 9.

Every card has a serial number called a UID, and the reader can read it without knowing anything else about the card. The loop checks for a new card, then reads its UID.

It prints the UID bytes as hex, with a leading zero when needed. Then it halts the card so the same card is not read again and again. The reader runs on 3.3 V, never 5 V.

Parts list

3 parts, plus the jumper wires. They retail for about $33; on Mokxi they're free.

Kits that can build it

These 3 starter kits have every part in the circuit. Each kit's page lists what else it can build.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
RFID reader, MFRC522 pin GNDArduino Uno R3 pin GND
RFID reader, MFRC522 pin SCKArduino Uno R3 pin 13
RFID reader, MFRC522 pin MISOArduino Uno R3 pin 12
RFID reader, MFRC522 pin MOSIArduino Uno R3 pin 11
RFID reader, MFRC522 pin SDAArduino Uno R3 pin 10
RFID reader, MFRC522 pin RSTArduino Uno R3 pin 9
RFID reader, MFRC522 pin 3.3VArduino Uno R3 pin 3V3

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// RC522 RFID reader: hold a card to it and see its ID.
//
//   RC522 SDA (SS) -> pin 10    RC522 SCK  -> pin 13
//   RC522 MOSI     -> pin 11    RC522 MISO -> pin 12
//   RC522 RST      -> pin 9     RC522 3.3V -> 3.3V   GND -> GND
//
// The reader talks SPI, the bus on pins 11, 12 and 13 that every SPI part on
// an Uno shares. SDA is the chip-select line that picks this reader. Every
// card carries a serial number, its UID, which the reader can read without
// knowing anything else about the card.
//
// The RC522 runs on 3.3 V. Never wire its supply to 5 V.
//
// Click the reader and pick a card to hold to it.

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

const int SS_PIN = 10;
const int RST_PIN = 9;

MFRC522 reader(SS_PIN, RST_PIN);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  reader.PCD_Init();
  Serial.println("Mokxi Uno: RC522 on SS 10 and RST 9. Hold a card to the reader.");
}

void loop() {
  if (!reader.PICC_IsNewCardPresent()) return;
  if (!reader.PICC_ReadCardSerial()) return;
  Serial.print("Card UID:");
  for (byte i = 0; i < reader.uid.size; i++) {
    Serial.print(reader.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(reader.uid.uidByte[i], HEX);
  }
  Serial.println();
  reader.PICC_HaltA();
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

It starts the serial port at 9600 and the SPI bus with SPI.begin. Then reader.PCD_Init starts the RC522 chip and it prints a message asking you to hold a card to the reader.

void setup() {
  Serial.begin(9600);
  SPI.begin();
  reader.PCD_Init();
  Serial.println("Mokxi Uno: RC522 on SS 10 and RST 9. Hold a card to the reader.");
}

loop sketch.ino

It returns early if there is no new card or the card cannot be read. Otherwise it prints "Card UID:" and each byte in hex, adding a zero before small values. Finally it halts the card with reader.PICC_HaltA.

void loop() {
  if (!reader.PICC_IsNewCardPresent()) return;
  if (!reader.PICC_ReadCardSerial()) return;
  Serial.print("Card UID:");
  for (byte i = 0; i < reader.uid.size; i++) {
    Serial.print(reader.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(reader.uid.uidByte[i], HEX);
  }
  Serial.println();
  reader.PICC_HaltA();
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The reader gets damaged or acts oddly. This project
    Power it from the 3V3 pin, not 5V. The RC522 runs on 3.3 V.
  • No card ever shows up. This project
    Check SDA is on pin 10, RST on pin 9 and SCK, MISO and MOSI on pins 13, 12 and 11.
  • The reader is damaged or behaves oddly on 5 V power. RFID reader
    The MFRC522 runs on 3.3 V only. Power it from the 3.3 V pin, never 5 V. Ideally divide 5 V signals from an Uno down for SCK, MOSI and SS.
  • No card is detected. RFID reader
    Check SDA (SS), RST, SCK, MOSI and MISO against your board's SPI pins and the constructor in your code. It reads 13.56 MHz cards only, not 125 kHz key fobs.
  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.