MDM331AID/Experiment 7
Experiment: RFID-Based Identification System
Aim
To design an RFID-based identification system that reads tag information and displays the tag ID on a monitoring system, demonstrating short-range communication technology in IoT.
Objectives
- To understand RFID technology and its role in IoT.
- To interface an RFID reader with an Arduino UNO.
- To read the unique identification number (UID) of an RFID tag.
- To display the tag ID on the Arduino IDE Serial Monitor.
Components Required
| Sr. No. | Component | Quantity |
|---|---|---|
| 1 | Arduino UNO | 1 |
| 2 | MFRC522 RFID reader module | 1 |
| 3 | RFID tags or cards compatible with the reader | 1 or more |
| 4 | USB cable | 1 |
| 5 | Patch cords | As required |
Theory
Radio Frequency Identification (RFID) is a wireless identification technology that uses radio waves to exchange information between an RFID reader and an RFID tag.
An RFID system generally consists of:
- RFID tag: Stores identification information. Passive tags obtain operating energy from the reader's electromagnetic field.
- RFID reader: Communicates with the tag and retrieves its identification information.
- Controller: Processes the information received from the reader. In this experiment, the Arduino UNO acts as the controller.
- Monitoring system: Displays the received tag ID. In this experiment, the Arduino IDE Serial Monitor is used.
The MFRC522 reader communicates with the Arduino UNO using the SPI (Serial Peripheral Interface) protocol. When a compatible RFID tag is brought close to the reader, the reader detects the tag and retrieves its UID. The Arduino then displays the UID on the Serial Monitor.
RFID is a short-range communication technology. The reading distance depends on the reader, tag, antenna, operating conditions and tag type.
Note: The UID is used here for demonstration and identification only. UID-based checking alone is not a secure authentication mechanism.
Pin Connections
The following connections assume an MFRC522 RFID module and an Arduino UNO.
| RFID Module Pin | Arduino UNO Pin | Description |
|---|---|---|
| SDA / SS | D10 | SPI chip select |
| SCK | D13 | SPI clock |
| MOSI | D11 | SPI data from Arduino to reader |
| MISO | D12 | SPI data from reader to Arduino |
| RST | D9 | Reset |
| 3.3V | 3.3V (Connect to 5V if system not working) | Power supply |
| GND | GND | Ground |
| IRQ | Not connected | Not required for this program |
Connection Diagram
Connect the MFRC522 RFID reader to the Arduino UNO according to the pin connection table.
The USB cable connects the Arduino UNO to the computer. The computer runs the Arduino IDE and displays the received tag ID through the Serial Monitor.
Program
Install the MFRC522 library using the Arduino IDE Library Manager before uploading the program.
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 rfid(SS_PIN, RST_PIN);
void setup()
{
Serial.begin(9600);
SPI.begin();
rfid.PCD_Init();
Serial.println("RFID Identification System");
Serial.println("Place an RFID tag near the reader.");
}
void loop()
{
// Check whether a new tag is present
if (!rfid.PICC_IsNewCardPresent())
{
return;
}
// Read the tag serial number
if (!rfid.PICC_ReadCardSerial())
{
return;
}
Serial.print("Tag UID: ");
for (byte i = 0; i < rfid.uid.size; i++)
{
if (rfid.uid.uidByte[i] < 0x10)
{
Serial.print("0");
}
Serial.print(rfid.uid.uidByte[i], HEX);
if (i < rfid.uid.size - 1)
{
Serial.print(":");
}
}
Serial.println();
// Stop communication with the current tag
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
delay(500);
}
Code Explanation
- SPI.begin(): Initializes SPI communication between the Arduino UNO and the RFID reader.
- rfid.PCD_Init(): Initializes the MFRC522 RFID reader.
- PICC_IsNewCardPresent(): Checks whether a new RFID tag is present in the reader's field.
- PICC_ReadCardSerial(): Reads the UID of the detected RFID tag.
- rfid.uid.size: Gives the number of bytes in the UID.
- Serial.print(): Displays the UID in hexadecimal format on the Serial Monitor.
- PICC_HaltA(): Stops communication with the selected tag.
- PCD_StopCrypto1(): Stops the reader's Crypto1 authentication state.
Procedure
- Connect the MFRC522 RFID reader to the Arduino UNO according to the pin connection table.
- Verify the power supply and logic-level compatibility of the RFID module.
- Connect the Arduino UNO to the computer using a USB cable.
- Open the Arduino IDE.
- Install the MFRC522 library using the Library Manager.
- Select the appropriate Arduino UNO board and COM port.
- Copy the program into the Arduino IDE.
- Compile and upload the program to the Arduino UNO.
- Open the Serial Monitor and set the baud rate to 9600.
- Bring a compatible RFID tag or card close to the RFID reader.
- Observe the UID displayed on the Serial Monitor.
- Repeat the experiment with different tags and compare the displayed UIDs.
Observations and Output
The following is an illustrative example of the expected Serial Monitor output. Actual UIDs will depend on the RFID tags used.
RFID Identification System Place an RFID tag near the reader. Tag UID: 23:8A:4F:19 Tag UID: 6B:21:CD:07 Tag UID: 23:8A:4F:19
| Sr. No. | RFID Tag | Observed UID |
|---|---|---|
| 1 | Tag 1 | Record the UID displayed |
| 2 | Tag 2 | Record the UID displayed |
| 3 | Tag 3 | Record the UID displayed |
Result
The RFID reader was interfaced with the Arduino UNO using SPI communication. The system read the UIDs of compatible RFID tags and displayed the identification information on the Serial Monitor, demonstrating short-range wireless identification.
Viva Questions
- What is RFID?
- What are the main components of an RFID system?
- What is the difference between an RFID reader and an RFID tag?
- What is the purpose of the UID in an RFID tag?
- Which communication protocol is used between the MFRC522 and Arduino UNO?
- What is SPI communication?
- What factors affect the reading range of an RFID system?
- What is the difference between passive and active RFID tags?
- Why is UID-only identification not considered secure authentication?