RFID (Radio-Frequency Identification) technology has gained significant popularity in various industries due to its ability to track and identify objects using radio waves. One of the most commonly used RFID modules with Arduino is the RC522. This blog post will explore the functionalities of the Arduino RFID RC522 module and guide you on how to read and write RFID tags.
The RC522 module is a low-cost RFID reader/writer module that operates on 13.56MHz radio frequency. It is widely used in applications like access control systems, attendance systems, and inventory management.
The module consists of a tag antenna, a contactless smart card reader, and an integrated circuit (IC) that manages the communication between the reader and the tags. The RC522 module supports various types of RFID tags, including MIFARE Classic 1K, MIFARE Classic 4K, and MIFARE Ultralight.
Before we begin reading and writing RFID tags, let's connect the RC522 module to Arduino. Here's a simple wiring diagram:
Arduino | RC522 Module
------------------------
3.3V | 3.3V
GND | GND
10 | SDA(SS)
9 | RST
13 | SCK
11 | MOSI
12 | MISO
Ensure that the connections are made correctly to avoid any issues with communication between Arduino and the RC522 module.
Now that we have the RC522 module connected to our Arduino, let's start reading RFID tags. We will use the MFRC522 library, which provides easy-to-use functions for interacting with the RC522 module.
First, make sure you have the MFRC522 library installed in your Arduino IDE. Once that's done, let's write a simple program to read and display the UID (Unique Identifier) of the RFID tag:
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Reset pin
#define SS_PIN 10 // Slave select pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create an instance of the MFRC522 class
void setup() {
Serial.begin(9600); // Initialize serial communications
SPI.begin(); // Initialize SPI bus
mfrc522.PCD_Init(); // Initialize MFRC522
Serial.println("Scan an RFID tag");
}
void loop() {
// Check if a new RFID tag has been detected
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
// Read the UID of the tag
String uid = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
uid += String(mfrc522.uid.uidByte[i] < 0x10 ? "0" : "");
uid += String(mfrc522.uid.uidByte[i], HEX);
}
Serial.print("UID: ");
Serial.println(uid);
mfrc522.PICC_HaltA(); // Stop reading the current tag
}
}
Upload the code to your Arduino, open the serial monitor, and bring an RFID tag close to the RC522 module. You should see the UID being displayed on the serial monitor.
In addition to reading RFID tags, the RC522 module also allows you to write data to compatible RFID tags. This feature can be useful for applications like access control or storing user-specific information.
Let's modify our previous program to write a simple text to an RFID tag:
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Reset pin
#define SS_PIN 10 // Slave select pin
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create an instance of the MFRC522 class
void setup() {
Serial.begin(9600); // Initialize serial communications
SPI.begin(); // Initialize SPI bus
mfrc522.PCD_Init(); // Initialize MFRC522
Serial.println("Scan an RFID tag");
}
void loop() {
// Check if a new RFID tag has been detected
if (mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
// Write a text to the tag
byte data[] = {'H', 'e', 'l', 'l', 'o', '!', '\0'};
MFRC522::StatusCode status;
status = mfrc522.MIFARE_Write(4, data, sizeof(data));
if (status == MFRC522::STATUS_OK) {
Serial.println("Data written successfully");
} else {
Serial.println("Error writing data");
}
mfrc522.PICC_HaltA(); // Stop reading the current tag
}
}
Upload the modified code to your Arduino, and follow the same steps as before. When you bring an RFID tag close to the RC522 module, the program will write the text "Hello!" to the tag. You can then read the written data by accessing the corresponding sector of the tag.
Congratulations, you have learned how to use the Arduino RFID RC522 module to read and write RFID tags. RFID technology has endless possibilities for various applications, from security systems to inventory management. Understanding how to work with RFID modules opens the door to countless projects and opportunities. Start exploring and experimenting with RFID technology to elevate your Arduino projects to new levels!
Android 12
Dual SIM card slots
2G/3G/4G/5G
2.4G/5G WiFi 802.11ax Wi-Fi6
Bluetooth 5.1 +BLE
4GB+64GB 6GB+128GB 8GB+256GB (Optional)
MediaTek Dimensity 900
LCD 6-inch IPS
QR / bar code scanner(optional)
Corning GG3 reinforced glass cover
NFC, Magnetic(optional)
Finger Print
·Powerful, Durable and Enterprise-Ready
·Seamless Device and Data Management
·Rugged and Powerful Handheld Computer for Business
·Cost-Saving Bulk Deals for Large Volume Purchases
We’re here to help tailor our comprehensive business solutions to your specific needs.
Our tablet devices are equipped with advanced 5G modules that support various network bands and protocols, which allows you to enjoy fast and stable internet access anytime and anywhere.
We have been focusing on the production of intelligent mobile devices for 15 years, and we have a deep understanding of the industry trends and customer needs. We can provide you with high-quality products that meet your expectations and requirements.
We have a professional and responsive customer service team that can solve any problems you encounter within 24 hours. You can also contact our engineers directly for technical support and guidance.
We can customize your tablet devices according to your specifications and preferences. You can choose the size, color, logo, software, hardware and accessories of your tablet devices. We will offer you the best solution that suits your budget and needs.
We have a wide range of tablet devices for you to choose from, with different features, functions and prices. Our professional sales team will recommend the most suitable and cost-effective products for you based on your needs and preferences.
We have a professional R&D and design team that can develop innovative and unique tablet devices for you. We have 15 years of experience in software and hardware development, and we can create solutions that satisfy your customers and the market.Don’t miss this opportunity to get the best 5G tablet device for your business or personal use. Contact us today and get a free quote and sample!