- Automobiles & Motorcycles
- Beauty & Personal Care
- Business Services
- Chemicals
- Construction & Real Estate
- Consumer Electronics
- Electrical Equipment & Supplies
- Electronic Components & Supplies
- Energy
- Environment
- Excess Inventory
- Fashion Accessories
- Food & Beverage
- Furniture
- Gifts & Crafts
- Hardware
- Health & Medical
- Home & Garden
- Home Appliances
- Lights & Lighting
- Luggage, Bags & Cases
- Machinery
- Measurement & Analysis Instruments
- Mechanical Parts & Fabrication Services
- Minerals & Metallurgy
- Office & School Supplies
- Packaging & Printing
- Rubber & Plastics
- Security & Protection
- Service Equipment
- Shoes & Accessories
- Sports & Entertainment
- Telecommunications
- Textiles & Leather Products
- Timepieces, Jewelry, Eyewear
- Tools
- Toys & Hobbies
- Transportation
What is the purpose of the RFID module?
What is RFID Module and How Does it Works
RFID or Radio Frequency Identification System is a technology widely used in different industries. You might not be aware of what is RFID and how it works but you might have already experienced it in modern supermarkets where there is an automated checkout system. It is the RFID technology that lets you easily walk out from the billing section without requiring you to enter each items price manually before checkout. Lets understand more about this technology and some important technical aspects.
If you are looking for more details, kindly visit our website.
Table of Contents
1. Introduction
2. Elements of RFID Module
3. How does RFID Work?
4. Applications of RFID Modules
INTRODUCTION
A popular method for storing and retrieving data in devices with radio frequency capabilities is radio frequency identification or RFID. RFID systems typically include one or more RF tags, an RF reader, and a database. RFID Modules can even be used in various Raspberry Pi Projects as well.
Devices can exchange information without making physical contact Using radio frequency identification (RFID). In this blog, let us dive in and understand what this technology is, how it operates, and how you can use it.
ELEMENTS OF RFID MODULE
The two essential parts of an RFID system, also known as a radio frequency identification system, are:
- A tag that is affixed to the object that needs to be identified
- A reader who scans the tag.
A reader is made up of an antenna that produces a high-frequency electromagnetic field and a radio frequency module. In contrast, tags are often passive devices (it does not have a battery). It is made up of an antenna for receiving and transmitting signals as well as a microchip for processing and storing information.
An electromagnetic field is produced by the reader when the tag is brought close to it. As a result, electrons pass through the antenna of the tag and energize the chip. The chip then reacts by sending the reader another radio signal containing the information it has previously saved.
A computer or microcontroller receives the data that the reader has collected and interpreted from this backscatter.
Instead of continually checking to see if a card is nearby, the RC522 RFID module can be designed to emit an interrupt, alerting us when a tag approaches it. The RFID tags have unique identifiers, which the reader can use to identify them in the database. RFID tags can be active or passive. Meaning,
They either require external power (active)
Or
They are powered by the reader upon scanning (passive).
While active RFID tags are utilized for asset tracking in wider spaces over greater distances and for road tolls, passive RFID tags are most frequently employed for shipment tracking, inventory management, and security access.
HOW DOES RFID WORK?
The key component of Radio Frequency Identification System is a microelectronic component, typically a microchip that contains information. It can store a lot of data despite often being quite small. How does the tag interact with readers when they lack a power source of their own? Here, electromagnetic plays a role.
When a passive tag is in close proximity to a reader, the readers antenna sends electromagnetic energy to the tag. The tags antenna is made of conductive material, which when electromagnetic waves strike causes an electric current to flow, powering the tags integrated circuit.
After then, the tag turns on and begins transmitting data. The readers task is to translate the signal received from the tag into useful information.
APPLICATIONS of RFID MODULES
Here are some of the popular applications of RFID modules.
- Logistics & Inventories: RFID tags are frequently used in large shipments of commodities, such as retail products, to track the location, composition, and movement of goods. One of the biggest users of this technology for tracking product shipments is Wal-Mart.
- Passport: RFID tags are included in passports in a number of nations. These tags are used to retain personal data ASW (including a passport holders photo) and keep tabs on travelers who enter and leave the country.
- Identification: Both people and animals can have RFID chips implanted to track their travels, grant access to restricted areas, or aid in the recovery of lost pets.
- E payment- Highway Tollgate: RFID technology is used by highway toll payment systems, including E-Z Pass in the eastern states, to electronically collect tolls from passing vehicles. Cars use the E-Z Travel lane to pass through the toll booth without stopping, and the toll is automatically debited from a pre-paid card.
- Libraries: Libraries utilize RFID tags in books and other materials to keep track of inventory and circulation, store product details (such as titles and authors), and prevent theft. RFID technology makes it possible to check books in and out as well as do time-consuming activities like shelf inventory swiftly and effectively because tags can be read without having to touch the object.
Hope you got a detailed understanding of what is RFID and how it works. We also have blog posts on similar interesting and highly useful technologies like Accelerometers, IR Sensors, and PIR Sensors. Take a look at them and double up your knowledge.
Have a good day!
Marini
Marini is the Senior Robotics Trainer at Guruface Academy. She holds a Master's Degree (MS) in Electronics and is an experienced Instructor with a demonstrated history of Training students across the Globe in Various Robotics platforms. Marini is also a Professional Stem Educator with sound knowledge of Electronics, Coding, Robotics, Artificial Intelligence, etc.
What is RFID? How It Works? Interface RC522 with Arduino
Gone are the days when people waited in long checkout lines at the grocery store, thanks to RFID technology. With an RFID based walk-through automatic checkout solution, you can fill up your cart and walk right out the door. You no longer need to wait for someone to ring each item in your cart one by one; Now with the help of RFID tags attached to the items, every item in the cart will be detected and ringed almost instantly.
For most of our RFID based Arduino projects, the RC522 RFID reader/writer module is a great choice. It is low power, low cost, very rugged, easy to interface and extremely popular among hobbyists.
What is RFID technology and how does it work?
An RFID or radio frequency identification system consists of two main components, a tag attached to the object to be identified, and a reader that reads the tag.
A reader consists of a radio frequency module and an antenna that generates a high frequency electromagnetic field. Whereas the tag is usually a passive device (it does not have a battery). It consists of a microchip that stores and processes information, and an antenna for receiving and transmitting a signal.
When the tag is brought close to the reader, the reader generates an electromagnetic field. This causes electrons to move through the tags antenna and subsequently powers the chip.
The chip then responds by sending its stored information back to the reader in the form of another radio signal. This is called a backscatter. The reader detects and interprets this backscatter and sends the data to a computer or microcontroller.
Hardware Overview
The RC522 RFID module based on the MFRC522 IC from NXP is one of the cheapest RFID options you can get online for less than four dollars. It usually comes with an RFID card tag and a key fob tag with 1KB of memory. And the best part is that it can write a tag that means you can store any message in it.
The RC522 RFID reader module is designed to create a 13.56MHz electromagnetic field and communicate with RFID tags (ISO A standard tags).
The reader can communicate with a microcontroller over a 4-pin SPI with a maximum data rate of 10 Mbps. It also supports communication over I2C and UART protocols.
The RC522 RFID module can be programmed to generate an interrupt, allowing the module to alert us when a tag approaches it, instead of constantly asking the module Is there a card nearby?.
The modules operating voltage ranges from 2.5 to 3.3V, but the good news is that the logic pins are 5-volt tolerant, so we can easily connect it to an Arduino or any 5V logic microcontroller without using a logic level converter.
Technical Specifications
Here are the specifications:
Frequency Range13.56 MHz ISM BandHost InterfaceSPI / I2C / UARTOperating Supply Voltage2.5 V to 3.3 VMax. Operating Current13-26mAMin. Current(Power down)10µALogic Inputs5V TolerantRead Range5 cmFor more details, please refer below datasheet.
RC522 RFID Module Pinout
The RC522 module has a total of 8 pins that connect it to the outside world. The connections are as follows:
VCC supplies power to the module. This can be anywhere from 2.5 to 3.3 volts. You can connect it to the 3.3V output from your Arduino. But remember that connecting it to the 5V pin will probably destroy your module!
RST is an input for reset and power-down. When this pin goes low the module enters power-down mode. In which the oscillator is turned off and the input pins are disconnected from the outside world. Whereas the module is reset on the rising edge of the signal.
GND is the ground pin and needs to be connected to the GND pin on the Arduino.
IRQ is an interrupt pin that alerts the microcontroller when an RFID tag is in the vicinity.
MISO / SCL / Tx pin acts as master-in-slave-out when SPI interface is enabled, as serial clock when I2C interface is enabled and as serial data output when the UART interface is enabled.
MOSI (Master Out Slave In) is the SPI input to the RC522 module.
SCK (Serial Clock) accepts the clock pulses provided by the SPI bus master i.e. Arduino.
SS / SDA / Rx pin acts as a signal input when the SPI interface is enabled, as serial data when the I2C interface is enabled and as a serial data input when the UART interface is enabled. This pin is usually marked by encasing the pin in a square so that it can be used as a reference to identify other pins.
Wiring an RC522 RFID Module to an Arduino
Now that we know everything about the module, lets start connecting it to our Arduino!
First connect the VCC pin on the module to 3.3V and the GND pin to ground on the Arduino. Pin RST can be connected to any digital pin on the Arduino. In our case, it is connected to digital pin #5. The IRQ pin is left unconnected because the Arduino library we are going to use does not support it.
Now we are left with the pins that are used for SPI communication. Since RC522 modules require a lot of data transfer, they will give the best performance when connected to the hardware SPI pins on the microcontroller. For Arduino boards such as the UNO/Nano V3.0, these pins are digital 13 (SCK), 12 (MISO), 11 (MOSI) and 10 (SS).
If you are using a different Arduino than the boards mentioned above, please check the Arduinos official documentation before proceeding.
The following table lists the pin connections:
RC522 ModuleArduinoVCC3.3VGNDGNDRST5MISO / SCL / Tx12MOSI11SCK13SS / SDA / Rx10The image below shows how to connect the RC522 module to the Arduino.
Once you have connected everything you are ready to go!
Library Installation
Communicating with an RC522 RFID module is a lot of work, but luckily for us there is a library called the MFRC522 library that makes reading and writing RFID tags simple.
This library is not included in the Arduino IDE, so you will need to install it first.
To install the library navigate to Sketch > Include Libraries > Manage Libraries Wait for Library Manager to download the library index and update the list of installed libraries.
Filter your search by typing mfrc522. Look for the library by GithubCommunity. Click on that entry, and then select Install.
Arduino Code Reading an RFID Tag
Once you have installed the library, open the Examples submenu and choose MFRC522 > DumpInfo example sketch.
This sketch just reads the tag and displays the information stored in it. This sketch can be very handy before trying out any new tags!
Go to the beginning of the sketch and make sure RST_PIN is initialized correctly, in our case we are using digital pin #5 so change it to
5.
Now upload the sketch and open Serial Monitor. As you bring the tag closer to the module, youll get something like the following. Do not move the tag until all the information is displayed.
It displays all the useful information about the tag including the tags Unique ID (UID), memory size, and the entire 1K memory.
MIFARE Classic 1K Memory Layout
The tags 1K memory is organized into 16 sectors (from 0 to 15). Each sector is further divided into 4 blocks (blocks 0 to 3). And each block can store 16 bytes of data (from 0 to 15).
This of course tells us that we have :
16 sectors x 4 blocks x 16 bytes of data = bytes = 1K memory
The entire 1K of memory, along with sectors, blocks, and data, is highlighted below.
Here is the 3D representation of the MIFARE Classic 1K memory map layout.
3D Representation of MIFARE Classic 1K Memory Map LayoutThe last block of each sector is called a Sector Trailer. It contains information called Access Bits that provide read and write access to the remaining blocks in the sector. This means that only 3 blocks of each sector (Blocks #0, #1 and #2) are actually writable, in other words only 48 bytes per sector are available for use.
Also Block #0 of Sector #0 is called Manufacturer Block which contains IC Manufacturer data and Unique Identifier (UID). The manufacturer block is highlighted in red.
Warning:
Remember that overwriting the manufacturer block is very risky and can permanently lock the card.
Arduino Code Writing an RFID Tag
Assuming that you have successfully read an RFID tag, we will move on to our next experiment. The following sketch demonstrates writing custom data to an RFID tag. Before we start a detailed analysis of it, give Sketch a try.
#include <SPI.h>
//include the SPI bus library
#include <MFRC522.h>
//include the RFID reader library
#define SS_PIN 10 //slave select pin
#define RST_PIN 5 //reset pin
MFRC522 mfrc522
(SS_PIN, RST_PIN); // instatiate a MFRC522 reader object.
MFRC522::MIFARE_Key key; //create a MIFARE_Key struct named 'key', which will hold the card information
//this is the block number we will write into and then read.
int
block=2
;
byte blockcontent[16
] = {"Last-Minute-Engg"
}; //an array with 16 bytes to be written into one of the 64 card blocks is defined
//byte blockcontent[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //all zeros. This can be used to delete a block.
//This array is used for reading out a block.
byte readbackblock[18
];
void
setup
()
{
Serial.begin
(); // Initialize serial communications with the PC
SPI.begin
(); // Init SPI bus
mfrc522.PCD_Init
(); // Init MFRC522 card (in case you wonder what PCD means: proximity coupling device)
Serial.println
("Scan a MIFARE Classic card"
);
// Prepare the security key for the read and write functions.
for
(byte i = 0
; i < 6
; i++) {
key.keyByte[i] = 0xFF
; //keyByte is defined in the "MIFARE_Key" 'struct' definition in the .h file of the library
}
}
void
loop
()
{
// Look for new cards
if
( ! mfrc522.PICC_IsNewCardPresent
()) {
return
;
}
// Select one of the cards
if
( ! mfrc522.PICC_ReadCardSerial
())
{
return
;
}
Serial.println
("card selected"
);
//the blockcontent array is written into the card block
writeBlock
(block, blockcontent);
//read the block back
readBlock
(block, readbackblock);
//uncomment below line if you want to see the entire 1k memory with the block written into it.
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
//print the block contents
Serial.print
("read block: "
);
for
(int
j=0
; j<16
; j++)
{
Serial.write
(readbackblock[j]);
}
Serial.println
(""
);
}
//Write specific block
int
writeBlock
(int
blockNumber, byte arrayAddress[])
{
//this makes sure that we only write into data blocks. Every 4th block is a trailer block for the access/security info.
int
largestModulo4Number=blockNumber/4
*4
;
int
trailerBlock=largestModulo4Number+3
;//determine trailer block for the sector
if
(blockNumber > 2
&& (blockNumber+1
)%4
== 0
){Serial.print
(blockNumber);Serial.println
(" is a trailer block:"
);return
2
;}
Serial.print
(blockNumber);
Serial.println
(" is a data block:"
);
//authentication of the desired block for access
byte status = mfrc522.PCD_Authenticate
(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
if
(status != MFRC522::STATUS_OK) {
Serial.print
("PCD_Authenticate() failed: "
);
Serial.println
(mfrc522.GetStatusCodeName
(status));
return
3
;//return "3" as error message
}
//writing the block
status = mfrc522.MIFARE_Write
(blockNumber, arrayAddress, 16
);
//status = mfrc522.MIFARE_Write(9, value1Block, 16);
if
(status != MFRC522::STATUS_OK) {
Serial.print
("MIFARE_Write() failed: "
);
Serial.println
(mfrc522.GetStatusCodeName
(status));
return
4
;//return "4" as error message
}
Serial.println
("block was written"
);
}
//Read specific block
int
readBlock
(int
blockNumber, byte arrayAddress[])
{
int
largestModulo4Number=blockNumber/4
*4
;
int
trailerBlock=largestModulo4Number+3
;//determine trailer block for the sector
//authentication of the desired block for access
byte status = mfrc522.PCD_Authenticate
(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
if
(status != MFRC522::STATUS_OK) {
Serial.print
("PCD_Authenticate() failed (read): "
);
Serial.println
(mfrc522.GetStatusCodeName
(status));
return
3
;//return "3" as error message
}
//reading a block
byte buffersize = 18
;//we need to define a variable with the read buffer size, since the MIFARE_Read method below needs a pointer to the variable that contains the size...
status = mfrc522.MIFARE_Read
(blockNumber, arrayAddress, &buffersize);//&buffersize is a pointer to the buffersize variable; MIFARE_Read requires a pointer instead of just a number
if
(status != MFRC522::STATUS_OK) {
Serial.print
("MIFARE_read() failed: "
);
Serial.println
(mfrc522.GetStatusCodeName
(status));
return
4
;//return "4" as error message
}
Serial.println
("block was read"
);
}The output on the serial monitor will look something like this.
RoyalRay contains other products and information you need, so please check it out.
Code Explanation:
The sketch begins by including the MFRC522 and SPI libraries, defining the Arduino pins to which the RC522 is connected, and instantiating the MFRC522 reader object.
#include <SPI.h>
//include the SPI bus library
#include <MFRC522.h>
//include the RFID reader library
#define SS_PIN 10 //slave select pin
#define RST_PIN 5 //reset pin
MFRC522 mfrc522
(SS_PIN, RST_PIN); // instatiate a MFRC522 reader object.
MFRC522::MIFARE_Key key;//create a MIFARE_Key struct named 'key', which will hold the card information
After this we define a block in which we are going to store our data. Here Sector #0 Block #2 is selected. Remember to never select block #3 of any sector. Writing in a Sector Trailer block can make the block unusable.
//this is the block number we will write into and then read.
int
block=2
;Next we define an array of 16 bytes called blockcontent, which holds the message we want to write to the block. When you want to delete a block you can set blockcontent to 0.
byte blockcontent[16
] = {"Last-Minute-Engg"
}; //an array with 16 bytes to be written into one of the 64 card blocks is defined
//byte blockcontent[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //all zeros. This can be used to delete a block.
Next we define an array of 18 bytes called readbackblock. We will use it to read back written content. Wait 18 bytes? Shouldnt it be 16 bytes? The answer is No. The MIFARE_Read method in the MFRC522 library requires a buffer at least 18 bytes long that holds 16 bytes of a block.
//This array is used for reading out a block.
byte readbackblock[18
];In setup, we initialize serial communication, the SPI library, and the MFRC522 object. We also prepare a security key for read and write operations. Here all six bytes of key are set to 0xFF.
Remember that newer cards have all six bytes of the key set to 0xFF. If you have a card that has been programmed by someone else, you will need to know the key in order to access the card. Store that key in a key variable then.
Serial.begin
(); // Initialize serial communications with the PC
SPI.begin
(); // Init SPI bus
mfrc522.PCD_Init
(); // Init MFRC522 card (in case you wonder what PCD means: proximity coupling device)
Serial.println
("Scan a MIFARE Classic card"
);
// Prepare the security key for the read and write functions.
for
(byte i = 0
; i < 6
; i++) {
key.keyByte[i] = 0xFF
; //keyByte is defined in the "MIFARE_Key" 'struct' definition in the .h file of the library
}In the loop, we look for the new card and select it for writing and reading purposes.
// Look for new cards
if
( ! mfrc522.PICC_IsNewCardPresent
()) {
return
;
}
// Select one of the cards
if
( ! mfrc522.PICC_ReadCardSerial
())
{
return
;
}
Serial.println
("card selected"
);Writing blocks is much easier now. We just call a custom function called writeBlock() which takes two parameters a block number to which we are interested in writing the data and the data itself.
//the blockcontent array is written into the card block
writeBlock
(block, blockcontent);To check whether the write operation was successful, we read back the block contents. For this we use a custom function called readBlock() which again takes two parameters the block number and the array to store the block content. If you want to see entire 1k memory you can call PICC_DumpToSerial() function.
//read the block back
readBlock
(block, readbackblock);
//uncomment below line if you want to see the entire 1k memory with the block written into it.
//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
Finally we print the contents of the readbackblock array on the serial monitor using a for loop.
//print the block contents
Serial.print
("read block: "
);
for
(int
j=0
; j<16
; j++)
{
Serial.write
(readbackblock[j]);
}
Serial.println
(""
);Arduino Project RFID Based Door Access Control System
Lets quickly create an Arduino project to demonstrate how a simple RC522 RFID reader module can be used to build a door access control system.
The program below scans the unique ID of each RFID tag. If the tags UID matches a predefined value (master tag) that is stored in the Arduino memory, access is granted. For unknown tags, access is denied. Awesome! Right?
This is how the output looks.
Door Lock Access Control Arduino Project OutputOf course this project can be expanded to open doors, switch relays, light LEDs, or anything else you can think of.
If youre not familiar with 16×2 character LCDs, consider reading the tutorial below.
Wiring
Before we upload the code and start scanning the tags, lets look at the wiring for the project.
Wiring RC522 RFID Reader Writer Module with Arduino UNO & 16×2 Character LCDLets try the sketch below.
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#define RST_PIN 9
#define SS_PIN 10
byte readCard[4
];
String MasterTag = "20CE"
; // REPLACE this Tag ID with your Tag ID!!!
String tagID = ""
;
// Create instances
MFRC522 mfrc522
(SS_PIN, RST_PIN);
LiquidCrystal lcd
(7
, 6
, 5
, 4
, 3
, 2
); //Parameters: (rs, enable, d4, d5, d6, d7)
void
setup
()
{
// Initiating
SPI.begin
(); // SPI bus
mfrc522.PCD_Init
(); // MFRC522
lcd.begin
(16
, 2
); // LCD screen
lcd.clear
();
lcd.print
(" Access Control "
);
lcd.setCursor
(0
, 1
);
lcd.print
("Scan Your Card>>"
);
}
void
loop
()
{
//Wait until new tag is available
while
(getID
())
{
lcd.clear
();
lcd.setCursor
(0
, 0
);
if
(tagID == MasterTag)
{
lcd.print
(" Access Granted!"
);
// You can write any code here like opening doors, switching on a relay, lighting up an LED, or anything else you can think of.
}
else
{
lcd.print
(" Access Denied!"
);
}
lcd.setCursor
(0
, 1
);
lcd.print
(" ID : "
);
lcd.print
(tagID);
delay
();
lcd.clear
();
lcd.print
(" Access Control "
);
lcd.setCursor
(0
, 1
);
lcd.print
("Scan Your Card>>"
);
}
}
//Read new tag if available
boolean getID
()
{
// Getting ready for Reading PICCs
if
( ! mfrc522.PICC_IsNewCardPresent
()) { //If a new PICC placed to RFID reader continue
return
false;
}
if
( ! mfrc522.PICC_ReadCardSerial
()) { //Since a PICC placed get Serial and continue
return
false;
}
tagID = ""
;
for
( uint8_t i = 0
; i < 4
; i++) { // The MIFARE PICCs that we use have 4 byte UID
//readCard[i] = mfrc522.uid.uidByte[i];
tagID.concat
(String
(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
}
tagID.toUpperCase
();
mfrc522.PICC_HaltA
(); // Stop reading
return
true;
}Code Explanation:
The program is quite simple. In the beginning we include the required libraries, define the Arduino pins, create instances of LCD and MFRC522 objects and define the master tag.
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#define RST_PIN 9
#define SS_PIN 10
byte readCard[4
];
String MasterTag = "20CE"
; // REPLACE this Tag ID with your Tag ID!!!
String tagID = ""
;
// Create instances
MFRC522 mfrc522
(SS_PIN, RST_PIN);
LiquidCrystal lcd
(7
, 6
, 5
, 4
, 3
, 2
); //Parameters: (rs, enable, d4, d5, d6, d7)
In the setup, we initialize the SPI interface, the MFRC522 object, and the LCD. After that we print the welcome message on the LCD.
void
setup
()
{
// Initiating
SPI.begin
(); // SPI bus
mfrc522.PCD_Init
(); // MFRC522
lcd.begin
(16
, 2
); // LCD screen
lcd.clear
();
lcd.print
(" Access Control "
);
lcd.setCursor
(0
, 1
);
lcd.print
("Scan Your Card>>"
);
}In the loop, we wait until the new tag is scanned. After scanning we compare the unknown tag ID with the master ID. If both match, access is granted else access is denied.
void
loop
()
{
//Wait until new tag is available
while
(getID
())
{
lcd.clear
();
lcd.setCursor
(0
, 0
);
if
(tagID == MasterTag)
{
lcd.print
(" Access Granted!"
);
// You can write any code here like opening doors, switching on a relay, lighting up an LED, or anything else you can think of.
}
else
{
lcd.print
(" Access Denied!"
);
}
lcd.setCursor
(0
, 1
);
lcd.print
(" ID : "
);
lcd.print
(tagID);
delay
();
lcd.clear
();
lcd.print
(" Access Control "
);
lcd.setCursor
(0
, 1
);
lcd.print
("Scan Your Card>>"
);
}
}The most important code here is the getID() custom function. Once it scans the new card, inside the for loop it converts the 4 bytes of the uid into a string and concatenates to form a single string.
boolean getID
()
{
// Getting ready for Reading PICCs
if
( ! mfrc522.PICC_IsNewCardPresent
()) { //If a new PICC placed to RFID reader continue
return
false;
}
if
( ! mfrc522.PICC_ReadCardSerial
()) { //Since a PICC placed get Serial and continue
return
false;
}
tagID = ""
;
for
( uint8_t i = 0
; i < 4
; i++) { // The MIFARE PICCs that we use have 4 byte UID
//readCard[i] = mfrc522.uid.uidByte[i];
tagID.concat
(String
(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
}
tagID.toUpperCase
();
mfrc522.PICC_HaltA
(); // Stop reading
return
For more UHF RFID Printer Moduleinformation, please contact us. We will provide professional answers.
true;
}
Next
None
If you are interested in sending in a Guest Blogger Submission,welcome to write for us!
Comments
0