Arduino - RFID/NFC
In this tutorial, we are going to learn how to use RFID/NFC with Arduino. The RFID/NFC system includes two components: reader and tag. There are two popular RFID/NFC readers: RC522 and PN532 RFID/NFC reader. This tutorial focuses on RC522 RFID/NFC reader. PN532 RFID/NFC reader will be presented in an upcoming tutorial.
RC522 RFID/NFC reader (also called RFID-RC522 Module) can:
- Read the UID of RFID/NFC tag
- Change the UID of RFID/NFC tag (only if the tag is UID-writable)
- Write data to RFID/NFC tag
- Read data from RFID/NFC tag
In above capabilities, for Arduino, reading the UID is the most widely-used. This tutorial focuses on reading the UID of RFID/NFC tag. The other will be present in next tutorials
|1||×||Arduino UNO or Genuino UNO|
|1||×||USB 2.0 cable type A/B|
|1||×||RFID/NFC RC522 Kit (reader + tags)|
|1||×||(Optional) 9V Power Adapter for Arduino|
|1||×||(Optional) Screw Terminal Block Shield for Arduino|
About RFID-RC522 Module
RFID-RC522 Module Pinout
RFID-RC522 has 8 pins, some of them are common pins, the others are shared among three communication modes: SPI, I2C, UART. At a time, only one communication mode can be used. The pin are:
- GND pin: needs to be connected to GND (0V)
- VCC pin: needs to be connected to VCC (3.3)
- RST pin: is a pin for reset and power-down. When this pin goes low, hard power-down is enabled. On the rising edge, the module is reset.
- IRQ pin: is an interrupt pin that can alert the microcontroller when RFID tag comes into its vicinity.
- MISO/SCL/TX pin: acts as MISO when SPI interface is enabled, acts as SCL when I2C interface is enabled and acts as TX when UART interface is enabled.
- MOSI pin: acts as MOSI when SPI interface is enabled.
- SCK pin: acts as SCK when SPI interface is enabled
- SS/SDA/RX pin: acts as SS when SPI interface is enabled, acts as SDA when I2C interface is enabled and acts as RX when UART interface is enabled.
※ NOTE THAT:
- The order of pins can vary according to manufacturers. ALWAYS use the labels printed on the module. The above image shows the pinout of the module from DIYables manufacturer.
- Do not connect VCC pin to 5V pin. This will likely destroy your module.
- MFRC522 library supports only SPI mode. Therefore, this tutorial uses only SPI communication.
How RFID/NFC Works
RFID/NFC includes two components: reader and tag.
- The reader consists of a radio frequency module and an antenna which generates high frequency electromagnetic field.
- The tag is usually a passive device, which doesn’t need to have power source. The tag contains a microchip that stores and processes information, and an antenna to receive and transmit a signal. The tag is used to store the information: UID (Unique ID) and data.
To read the information on a tag, the tag must be in close proximity to the reader (does not require the direct line-of-sight). The reading processes:
- The reader generates an electromagnetic field which causes electrons to move through the tag’s antenna and subsequently power the chip.
- The chip inside the tag then responds by sending the requested information back to the reader in the form of another radio signal.
- The reader detects the signal and transform the signal into data
- Arduino reads the data from reader.
Wiring Diagram between RFID-RC522 Module and ESP32
This image is created using Fritzing. Click to enlarge image
If you use the male-to-female jumper wires, you can connect Arduino UNO directly to RFID-RC522 module. If you use the male-to-male jumper wires, you need to connect Arduino UNO to RFID-RC522 module via a breadboard
Wiring table of RFID/NFC RC522 Module and Arduino
Arduino RFID/NFC Code
- On Arduino IDE, Go to Tools Manage Libraries
- Search “MFRC522”, then find the library by GithubCommunity
- Click Install button to install MFRC522 library.
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to Arduino
- Open Serial Monitor
- Tap several RFID/NFC tags on RFID-RC522 module
- See UID on Serial Monitor
We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.