A lot of people are familiar with the cards used to pay transport fare in buses. That system is based on RFID Code technology.
RFID stands for Radio Frequency Identification. It works in a way which allows data to be transferred from an RFID card to the RFID reader.
Objective
The purpose of this experiment is to give you the idea on how to use the RFID system in the circuit, how to connect it to an Arduino microcontroller board and how you can get access to the cards and visualize the data from it.
Component Knowledge
What is an RFID Card?
An RFID (Radio Frequency Identification) card is an electronic device used for wireless identification and data transfer. It contains a small chip and antenna that allow it to communicate with an RFID reader. RFID technology is widely used in access control systems, inventory management, transportation, and more.
How Does an RFID Card Work?
When an RFID card comes close to an RFID reader, the reader sends an electromagnetic signal to the card. The card uses the energy from this signal to power its internal chip, which sends back a unique identification number (UID) to the reader.
Figure: RFID Card
- RFID Card System Components
- RFID Card/Tag: This is the device containing a unique ID and, sometimes, stored data.
- RFID Reader: A device that sends a signal to the RFID card and reads the data transmitted by the card.
- Microcontroller/Processing Unit: Processes the data received from the RFID reader.
- Pin Identification of an RFID Reader (e.g., RC522)
The RFID card itself doesn’t have any external pins, but the RFID reader that communicates with it does. A common RFID reader used in conjunction with microcontrollers like Arduino is the RC522 module, which has the following pins:
- VCC: Power supply pin (usually 3.3V or 5V, depending on the reader).
- GND: Ground pin.
- RST: Reset pin for the module.
- SDA (SS): Serial Data pin, also known as the Slave Select pin. This is used for SPI communication.
- SCK: Serial Clock pin, used for SPI communication.
- MOSI: Master Out Slave In pin, for sending data to the RFID reader.
- MISO: Master In Slave Out pin, for receiving data from the RFID reader.
- IRQ: Interrupt pin, used for triggering events (optional).
An RFID card is used for wireless identification, working in conjunction with an RFID reader. The RFID reader communicates with the card, sending power and receiving data wirelessly. Testing the system usually involves using a microcontroller like an Arduino, where the card’s unique ID is read and displayed. The RFID reader has multiple pins for communication, typically using SPI protocol, and it can be tested using proper wiring and code.
- What is an RFID Reader? An RFID Reader is an electronic device that reads data stored on RFID (Radio Frequency Identification) tags or cards. It does this by emitting a radio signal that activates the RFID tag and retrieves the information stored in the tag’s microchip. RFID readers are commonly used in access control systems, inventory tracking, payment systems, and identification verification.
Figure: Arduino RC522 RFID Card reader module Kit/Keychain
There are different types of RFID readers based on the frequency range they operate in, such as low-frequency (LF), high-frequency (HF), and ultra-high-frequency (UHF). The most commonly used RFID reader in hobby electronics and microcontroller projects is the RC522 reader module, which operates in the HF range.
- Pin Identification of an RFID Reader (e.g., RC522)
Figure: RFID reader pin out
An RFID reader, such as the RC522 module, uses SPI communication to connect with a microcontroller like an Arduino. Here’s a description of the pins on an RFID reader:
- VCC: Power supply pin, usually connected to 3.3V (some models can also work with 5V).
- GND: Ground pin, which needs to be connected to the ground of the microcontroller.
- RST: Reset pin, used to reset the module if needed.
- SDA (SS): Serial Data or Slave Select pin, used to select the device for SPI communication.
- SCK: Serial Clock pin, which provides the clock signal for SPI communication.
- MOSI: Master Out Slave In pin, where data is sent from the microcontroller to the RFID reader.
- MISO: Master In Slave Out pin, where data is received by the microcontroller from the RFID reader.
- IRQ: Interrupt pin (optional), can be used to trigger an event when the reader detects an RFID card.
- How to Test an RFID Reader
1. Testing with an Arduino
The most common way to test an RFID reader like the RC522 is by connecting it to an Arduino or similar microcontroller and reading the UID (unique identification number) of an RFID tag or card.
Steps to Test the RFID Reader with Arduino:
- Wiring: Connect the RFID reader to the Arduino as follows:
- VCC to 3.3V on the Arduino (some modules may work with 5V).
- GND to Ground on the Arduino.
- SDA (SS) to Pin 10 on the Arduino.
- SCK to Pin 13.
- MOSI to Pin 11.
- MISO to Pin 12.
- RST to Pin 9.
- Upload Code: Use the MFRC522 library in Arduino to read the RFID card’s UID. Here’s a simple example:
- Run Test: After uploading the code to the Arduino, open the Serial Monitor in the Arduino IDE. Place an RFID card near the reader, and the card’s unique ID will be displayed on the serial monitor in hexadecimal format.
2. Testing with a Multimeter
While a multimeter cannot directly test the RFID reader’s functionality (since it deals with digital signals), it can be used to verify if the module is getting power and if the communication lines are functioning properly.
- Check Power (VCC and GND): Set the multimeter to measure DC voltage. Place the multimeter’s probes on the VCC and GND pins of the reader while it’s connected to a power source. You should see 3.3V or 5V depending on your power source.
- Check Continuity (SCK, MOSI, MISO): Check the connections of the SPI communication pins to ensure there is continuity between the microcontroller and RFID reader.
3. Using an Oscilloscope
For a more advanced test, an oscilloscope can be used to monitor the data signals on the SPI lines (MOSI, MISO, SCK, and SDA). This will show you the actual communication between the RFID reader and the microcontroller, which can help in debugging any issues with signal transmission.
Summary
An RFID Reader communicates wirelessly with RFID tags or cards to retrieve stored data. The RC522 RFID reader is commonly used in microcontroller projects. It connects to a microcontroller via SPI communication and has several pins, including VCC, GND, SDA, SCK, MOSI, MISO, and RST. You can test the RFID reader using an Arduino and code to verify that it’s reading RFID tags correctly. Additionally, you can use a multimeter to check power and continuity or an oscilloscope to analyze data signals.
Now is the time to give access to the cards that we want. The following codes helps you to know the card’s unique details which we will use. Once you have done uploading the following codes you have to open the serial monitor and copy the code in “card UID”. Those are the tag’s unique code.
Materials to use
- RFID card
- RFID card reader
- Jumper wires
- Arduino microcontroller
- Breadboard
Circuit diagram
Figure: RFID-RC522 connection to the voltage source and arduino
Figure: Components used to make connection on the board
Arduino Codes
Code knowledge
Let’s break down this Arduino code used to interface with an RFID card reader (MFRC522) and read data from RFID cards using SPI communication.
In this block, #include
#include
This block is about pin definition. #define RST_PIN 9 Defines pin 9 of the Arduino as the Reset (RST) pin for the MFRC522 RFID reader.
#define SS_PIN 10 Defines pin 10 as the Slave Select (SS) pin. This is used to enable communication between the RFID reader and the Arduino.
This is about object declaration. MFRC522 mfrc522(SS_PIN, RST_PIN); Creates an object named mfrc522 of the MFRC522 class. The object is configured to use the defined SS_PIN (10) and RST_PIN (9) for communicating with the RFID reader.
This function initializes the RFID reader and prepares the Arduino to communicate with it. In this function, each line is explained here below:
- Serial.begin(9600);: Initializes serial communication between the Arduino and your PC at a baud rate of 9600. This allows the Arduino to send information to the Serial Monitor.
- while (!Serial);: This line waits for the serial connection to be ready (primarily useful on boards like Arduino Leonardo that may take a moment to initialize the Serial connection).
- SPI.begin();: Starts the SPI communication. This is crucial since the MFRC522 uses SPI to communicate with the Arduino.
- mfrc522.PCD_Init();: Initializes the MFRC522 RFID reader. This prepares the RFID reader to start interacting with RFID cards or tags.
- delay(4);: A brief delay (4 ms) to ensure the RFID reader is properly initialized.
- mfrc522.PCD_DumpVersionToSerial();: This command dumps information about the RFID reader to the Serial Monitor, such as the model, version, and supported features. It is useful for debugging and confirming that the reader is working properly.
- Serial.println(F(“Scan PICC to see UID, SAK, type, and data blocks…”));: Prints a message to the Serial Monitor, prompting the user to scan an RFID card. F() macro: Saves this string in Flash memory (PROGMEM) rather than RAM, which is useful for memory optimization in microcontrollers.
The loop() function continuously checks if a new RFID card is detected and, if so, reads and outputs the card’s information to the Serial Monitor.
- The function if (!mfrc522.PICC_IsNewCardPresent()): checks if a new RFID card is present near the reader. If no card is detected, the function immediately exits (return), and the loop starts over. This prevents further processing when no card is present.
- If a new card is detected, the function if (!mfrc522.PICC_ReadCardSerial()) attempts to read the card’s UID (Unique Identifier). If it fails to read the card for some reason, the loop exits with a return, skipping further steps.
- When the card is successfully read the function the mfrc522.PICC_DumpToSerial(&(mfrc522.uid)) function dumps the card’s information (such as its UID, SAK, type, and data blocks) to the Serial Monitor. The mfrc522.uid object contains the UID of the RFID card.
Results
No physical visible output, as this is purely a serial monitor-based program. All results are displayed via the serial monitor connected to the PC.
- At Startup: When the RFID reader initializes, the serial monitor will show details about the RFID reader, such as its firmware version.
- When a Card is Detected: If a valid RFID card is placed near the reader, the following details are displayed: UID, SAK, card type, and memory data blocks.
Figure: Serial monitor showing details of the valid card