💳 How to connect RFID reader RC522 to Arduino

💳 How to connect RFID reader RC522 to Arduino

Daniil Zhuk
In this article, we will look at the connection to the Arduino of the RC522 RFID card reader and keyfobs operating at 13.56 MHz.

We will need:
  • Arduino (or compatible board);
  • RFID reader RC522 (purchased here);
  • a wireless RFID tag (included with the link above) or a contactless metro ticket/ground transportation;
  • breadboard;
  • connecting wires (such);

Instructions for connecting the reader RFID-RC522 wireless tags to the Arduino

Description of RFID reader RC522

RFID-RC522 module is made on the chip MFRC522 of NXP. This chip provides two-way wireless (up to 6 cm) communication at a frequency of 13.56 MHz.

Chip MFRC522 supports the following connection options:

Interface Transmission speed
SPI (Serial Peripheral Interface, Serial Peripheral Interface) up to 10 Mbps;
I2C two-wire interface up to 3400 kbaud in High-speed mode,
up to 400 kbaud in Fast mode;
serial UART (analog RS232) up to 1228.8 kbaud.

Using this module, you can record and read data from various RFID tags: keyfobs from intercoms, plastic pass cards and tickets for metro and ground transportation, as well as NFC tags that are gaining popularity.

RFID is short for "Radio Frequency IDentification" and is translated as "radio frequency identification."
NFC is “Near field communication”, “near field communication” or “near contactless communication”.

Connection diagram of RFID-RC522 to Arduino

Connect the RFID-RC522 module to the Arduino via an SPI interface according to the above scheme.

The module power supply is provided with voltage from 2.5 to 3.3 V. The remaining outputs are connected to the Arduino as:

Pin RC522 Pin Arduino
RST D9
SDA (SS) D10
MOSI D11
MISO D12
SCK D13

Do not forget also that the Arduino has a special ICSP connector for working on the SPI interface. Its pinout is also shown in the illustration. You can connect the RST, SCK, MISO, MOSI and GND pins of the RC522 module to the ICSP connector on the Arduino.

Library for working with RFID Arduino

Chip MFRC522 has fairly extensive functionality. You can get acquainted with all the possibilities by studying her passport (datasheet). We will use one of the ready-made libraries written for the Arduino to work with the RC522 to explore the capabilities of this device. Download it and unpack it into the directory.
 Arduino IDE \ libraries \

After that, run the Arduino IDE development environment.

Sketch for reading information recorded on the RFID tag

Now let's open the sketch from the examples: Sample File MFRC522 DumpInfo and load it into the Arduino memory.

This sketch determines the type of device attached to the reader and reads the data recorded on the RFID tag or card, and then displays it to the serial port.

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

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

MFRC522 mfrc522(SS_PIN, RST_PIN); 

void setup() {
	Serial.begin(9600); 
	SPI.begin(); 
	mfrc522.PCD_Init();
}

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

	if ( ! mfrc522.PICC_ReadCardSerial()) {
		return; 
	}

	mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}

The text of the sketch is well commented.

For a more complete acquaintance with the library, examine the files MFRC522.h and MFRC522.cpp from the RFID-master directory.

Data dump from RFID tags

Start the serial port monitor with the keyboard shortcut Ctrl + Shift + M, via the Tools menu or the button with the magnifying glass. Now we attach a subway ticket or any other RFID tag to the reader. The serial monitor will show the data recorded on the RFID tag or ticket.

For example, in my case, a unique ticket number, date of purchase, validity period, number of trips left, and official information are encrypted here. We will analyze in one of the future articles, what is recorded on the maps of the metro and land transport.

Note


Yes, using the RFID-RC522 module, you can record data on a metro ticket. But make no mistake, each card has a non-rewritable write cycle counter, so “adding” trips to the subway will not work - it will be immediately detected and the map will be rejected by the turnstile :) up to 4 kb - possible. And the ways to use it are limited only by your imagination.

Add a comment

* Comments must be approved before being displayed.