Hello there guys. It’s your hardware friend Kayode. Hope you have been making and creating. Well if your answer is yes, am quite elated because you have been practicing. Today I want to introduce the concept of RFID.
What is RFID? RFID stands for Radio Frequency Identification. Transfer of data is done using electromagnetic fields over a short distance. RFID has become so popular in recent years. It is used in places like malls to identify goods, in offices and homes for access control, for identification of animals if they get lost and on vehicles for toll collection. They are even used in hospitals to tag disposable equipment in operating rooms to ensure that no foreign objects are left inside patients. An RFID system consists majorly of two components;
- RFID TAG: The tags come in all kinds of shapes and sizes and can be made so small that they can be injected into humans or even animals. They transmit a unique serial data to the reader using electromagnetic fields. Each tag has its own UID (Unique identification). RFID tags are of two types.
- PASSIVE TAGS: These tags have no battery and are powered by the electromagnetic field created by the reader. They contain a coil and an electronic microchip.
- ACTIVE TAGS: These tags have their own power source. This means that they are battery assisted They wait for an external source to wake them up and then use their own power source to transmit, giving a greater range.
- RFID READER: The radio is a transceiver. It sends a signal to the tag and also reads its response. A reader consists of an antenna coil, radio frequency module and a control unit. The antenna coil is responsible for generating a high-frequency electromagnetic field.
PRINCIPLE OF OPERATION OF RFID
As stated earlier, the reader consists of a control unit, radio frequency module and an antenna coil. The coil generates a high-frequency electromagnetic field. When the tag is brought close to the reader, voltage due to electromagnetic induction is generated at the coil of the tag. This voltage is used to power the microchip in the tag.
When the tag is powered, it can now retrieve data from the reader and can also send to it. The tag makes use of a method known as load manipulation. Turning on and off a load at the antenna of the tag will affect the rate at which power is consumed at the antenna of the reader. This can be measured as voltage drop. The changes in the voltage can then be captured as a series of ones and zeros. That’s how transmission takes place between the tag and reader.
MFRC22 RFID READER AND MIFARE TAG
For this project, we will make use of the MFRC522 RFID reader which uses SPI protocol to communicate with the Arduino. The reader has the following features;
- MFRC522 chip based board
- Operating frequency: 56MHz
- Supply voltage: 3.3V
- Current: 13-26mA
- Range: Approximately 3cm
- SPI interface
The RFID tags we will be using are based on the MIFARE protocol.
MFRC522 LIBRARY DOWNLOAD
We will need the above-mentioned library for our project. Follow the steps below;
- Download the MFRC522 library here
- Unzip the library
- Install it in the Arduino IDE
- Finally, restart the Arduino IDE
OBTAINING THE UNIQUE IDENTIFICATION OF THE TAGS
Setup the circuit as shown below.
The MFRC522 library comes preloaded with some examples. Go to File>Examples>MFRC522>Dumpinfo and upload the code. Open the serial monitor to obtain tag UID. Move the card close to the card until all information is displayed as shown below.
The card UID is indicated in green. Please write it down as we will use it later. The tag has 1KB of memory divided into 16 sectors (0-15) and each sector has 4 blocks. Each sector is protected by two keys, A and B.
We will need the following components in order to build our door access system
CIRCUIT FOR DOOR ACCESS CONTROL SYSTEM
The wiring and circuit of the project is shown below;
READER PIN-OUT————————–TO ARDUINO
NOTE: Do not power the reader with 5V. You will fry the reader
The pulse pin of the servomotor is connected to digital pin 6, Vcc pin to 5V and GND to GND of Arduino.
OPERATION OF THE ACCESS CONTROL SYSTEM
For our project, we have two tags registered. If a registered tag is brought close to the RFID module, the card is read and accepted and the name of the user is also displayed on the serial monitor alongside the UID of the tag. The servo motor which acts as our lock opens the door for three seconds and then actuates back to its initial position.
We will do a little breakdown of the code and I will leave you with the code at the end. First, we will include the libraries for RFID, SPI, and servo motor. We will also define and declare variables we need for the code and create instances of the libraries. We will also create two arrays to store the tag UID and username. I just felt like fooling around that’s why I used Eden Hazard’s name alongside my name. LOL…..
In the setup section, we start serial communication and also initiate SPI and MFRC522 communication. The pin to which the servo is attached is also specified.
In the loop section, we first look for new tags. If a new tag is available, it is selected and then the UID of the tag is stored and then compared with the already registered tags. If they correspond, access is granted and the door is opened. If the tag does not correspond, access is denied.
This function is used to unlock the door for 3 seconds.
The last function in the code is used to lock the door
That’s all about the code. Find the full source code below.
If you do things right you should see something like the screenshot shown below
That will be all guys. Let me know if you have any questions. Till next time, keep creating.