100% found this document useful (1 vote)
253 views

ESP32 RFID Live MySQL

The document discusses RFID technology and how it works. It explains that RFID uses radio waves to automatically identify tags attached to objects. An RFID tag contains a radio transponder that transmits data like an identification number to an RFID reader when triggered by its signal. The document also provides details about an RFID module and its applications.

Uploaded by

Taoufik Zaim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
253 views

ESP32 RFID Live MySQL

The document discusses RFID technology and how it works. It explains that RFID uses radio waves to automatically identify tags attached to objects. An RFID tag contains a radio transponder that transmits data like an identification number to an RFID reader when triggered by its signal. The document also provides details about an RFID module and its applications.

Uploaded by

Taoufik Zaim
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

-: Internet of Things – The IoT World :-

ESP32 Live Recording RFID Data

Aim: Understanding RFID tags and card reader and developing a project to show RFID tags
information Live on a web dashboard. Also, the card information should be stored in MySQL
database.

Assumption(s):

1. You already have gone through our ESP32 SPIFFS session and installed ESP32 Sketch Data
Upload plugin to your Arduino IDE. If not, please DO NOT proceed until you've done this.

Understanding Radio-frequency identification (RFID)

Long gone are the days when people used to stand and wait in long checkout lines at the grocery
store. Thanks to the Radio Frequency IDentification (RFID) technology. With this RFID based walk-
through automatic checkout solution, you can fill up your cart and walk right out the door. No
longer will you have to wait as someone rings up each item in your cart one at a time. Instead, the
RFID tags attached to items will communicate with RFID reader that will detect every item in the
cart and ring each up almost instantly.

Panasonic and Trial Company, Inc. together conducted a demonstration experiment of the
industry's first "RFID based walk-through automatic checkout solution" featuring Trial's "RFID
tagging," which manages manufacturing and distribution data.

You can quickly watch the demo of this solution here: https://youtu.be/TF8HAhUN_p4

What is RFID technology and how does it work?

RFID belongs to a group of technologies referred to as Automatic Identification and Data


Capture (AIDC). AIDC methods automatically identify objects, collect data about them, and enter
those data directly into computer systems with little or no human intervention. RFID methods
utilize radio waves to accomplish this.

Let’s first understand below two terminologies:

 Transceiver: A transceiver is a device that can both transmit and receive signals
 Transponder: A transponder is a component with a processor programmed to monitor
incoming signals and with a preprogrammed reply in the communication network
The transceiver and transponder are different and they are not interchangeable.

Radio-frequency identification (RFID) uses electromagnetic fields to automatically identify and


track tags attached to objects. An RFID tag consists of a tiny radio transponder; a radio receiver
and transmitter. When triggered by an electromagnetic interrogation pulse from a nearby
Page 205 of 221
-: Internet of Things – The IoT World :-

RFID reader device, the tag transmits digital data, usually an identifying inventory number, back
to the reader. This number can be used to inventory goods.

There are two types:

1. Passive tags are powered by energy from the RFID reader's interrogating radio waves.
2. Active tags are powered by a battery and thus can be read at a greater range from the RFID
reader; up to hundreds of meters.
Unlike a barcode, the tag doesn't need to be within the line of sight of the reader, so it may be
embedded in the tracked object. RFID is one method of automatic identification and data capture.

Thus we see RFID or Radio Frequency Identification system consists of two main components:

1. Transponder or tag attached to an object to be identified


2. Transceiver or interrogator or Reader. The one who reads the transponder data
Note: Such system makes sure that the used frequency must fall within the permissible range or
necessary license need to be purchased from the governing body. E.g. the RFID RC522 Module
operates 13.56MHz which is industrial (ISM) band and hence can be used without any license
problem.

A Reader consists of a Radio Frequency module and an antenna which generates high frequency
electromagnetic field. On the other hand, the tag is usually a passive device, meaning it doesn’t
contain a battery. Instead it contains a microchip that stores and processes information, and an
antenna to receive and transmit a signal. You can understand this from below diagram:

Page 206 of 221


-: Internet of Things – The IoT World :-

Reading Information:

To read the information encoded on a tag, it is placed in close proximity to the Reader (does not
need to be within direct line-of-sight of the reader). A Reader generates an electromagnetic field
which causes electrons to move through the tag’s antenna and subsequently power the chip. See
below diagram:

The powered chip inside the tag then responds by sending its stored information back to the
reader in the form of another radio signal. This is called backscatter (In physics, backscatter (or
backscattering) is the reflection of waves, particles, or signals back to the direction from which
they came). The backscatter, or change in the electromagnetic/RF wave, is detected and
interpreted by the reader which then sends the data out to a computer or microcontroller.

Thus we can say that RFID refers to a technology whereby digital data encoded in RFID tags or
smart labels are captured by a reader via radio waves. RFID is similar to barcoding in that data from
a tag or label are captured by a device that stores the data in a database. RFID, however, has
several advantages over systems that use barcode asset tracking software. The most notable is
that RFID tag data can be read outside the line-of-sight, whereas barcodes must be aligned with
an optical scanner. Also an RFID tag can hold much more data about an item than a barcode can.
In addition, RFID tags are not susceptible to the damages that may be incurred by barcode labels,
like ripping and smearing.

RFID Applications:

 Inventory management
 Asset tracking
 Personnel tracking
 Controlling access to restricted areas

Page 207 of 221


-: Internet of Things – The IoT World :-

 ID Badging
 Supply chain management

RFID Module - RC522

The RC522 RFID module based on MFRC522 IC from NXP is one of the most inexpensive RFID
options that we can get online very cheap. This module usually comes with a RFID card tag and
RFID key tag having 1KB memory. And best of all, it can write a tag, so you can store your some
sort of secret message in it. The complete module looks like below:

The RC522 RFID Reader module is designed to create a 13.56MHz electromagnetic field that it
uses to communicate with the RFID tags (ISO 14443A standard tags). The reader can communicate
with a microcontroller over a 4-pin Serial Peripheral Interface (SPI) with a maximum data rate of
10Mbps. It also supports communication over I2C and UART protocols.

The module comes with an interrupt pin which can be connected to our microcontroller. It alerts
our microcontroller when a tag comes nearby. It is handy because instead of constantly asking the
RFID module “is there a card in view yet?” the module will alert the microcontroller when a tag
comes into its vicinity.

RC522 Features:

 Integrated MF RC522 IC
 13.56MHz RFID module
Page 208 of 221
-: Internet of Things – The IoT World :-

 Operating voltage: 2.5V to 3.3V


 Communication : SPI, I2C protocol, UART
 Supported card types: mifare1 S50, mifare1 S70 MIFARE Ultralight, mifare Pro, MIFARE
DESFire
 Maximum Data Rate: 10Mbps
 Read Range: 5cm
 Current Consumption: 13-26mA
 Power down mode consumption (Min. Current): 10uA (min)
 14443A compatible transponder signals
 ISO14443A frames and error detection
 Supports rapid CRYPTO1 encryption algorithm, terminology validation MIFARE products
 MFRC522 support MIFARE series of high-speed non-contact communication, two-way data
transmission rate
 Suitable for Smart meters and portable handheld devices
 Low cost, and ideal for user equipment development
 Can be directly loaded into the various reader molds, very convenient
RC522 RFID Module Pinout:

Let’s understand the pins in details:

Supplies power for the module. This can be anywhere from 2.5 to 3.3
VCC volts. You can connect it to 3.3V output from your Raspi. Remember
connecting it to 5V pin will likely destroy your module!

Page 209 of 221


-: Internet of Things – The IoT World :-

This is an input for Reset and power-down. When this pin goes low, hard
power-down is enabled. This turns off all internal current sinks including
RST
the oscillator and the input pins are disconnected from the outside
world. On the rising edge, the module is reset.

It is the Ground Pin and needs to be connected to GND pin on your


GND
Raspi.

This is an interrupt pin that can alert the microcontroller i.e. your
IRQ
ESP/Raspi when RFID tag comes into its vicinity.

This pin acts as Master-In-Slave-Out when SPI interface is enabled, acts


as serial clock when I2C interface is enabled and acts as serial data
MISO/SCL/TX
output when UART interface is enabled. Please go through the previous
sessions for more on SPI, I2C or UART.

MOSI This is Master-Out-Slave-In pin for SPI interface.

This is the Serial Clock. It accepts clock pulses provided by the SPI bus
SCK
Master i.e. ESP/Raspi.

This pin acts as Chip Select when SPI interface is enabled, acts as Serial
Data Line when I2C is enabled and acts as serial data receiver when
SS/SDA/RX
UART is enabled. This pin is usually marked by encasing the pin in a
square so it can be used as a reference for identifying the other pins.

We'll use the below connection schemes:

RFID-RC522 ESP32
SDA_PIN GPIO# 21
RST_PIN GPIO# 22
SCK_PIN GPIO# 18
MISO_PIN GPIO# 19
MOSI_PIN GPIO# 23
GND GND
VCC 3.3V
IRQ_PIN Leave blank

Below is our fritzing diagram:

Page 210 of 221


-: Internet of Things – The IoT World :-

And here is our physical connection:

Let's follow the below steps to execute this project:

1. First and foremost we need to record some information into our RFID cards. So, open the
Arduino IDE, connect to the ESP32 Dev Module board and COM port. Mine is COM4. Copy our
code ESP32_RFID_Read_Write.ino and make sure that the function writingData() is
uncommented and readingData() is commented and save it. The function writingData() writes
data into RFID cards in the format IMH-xxxxxxxxxxxx. See below:

Page 211 of 221


-: Internet of Things – The IoT World :-

2. Upload the code into ESP32. Once uploaded, open the serial monitor, press the RESET button
on ESP32 to restart the program. When it asks to swipe the care, please swipe one of the card
and observe the data written into the card. You can use all your cards and write data into those.
The program will write different & unique data in every card. The data looks like IMH-
050102821664. See below results from this code:

3. Once all our cards are ready with data, we are good to proceed. Now copy our code
ESP32_RFID_Live_Status.ino, provide your WiFi information and save.
4. Click on Sketch => Show Sketch Folder. It will take you to the current sketch folder. There you
need to copy our "data" folder. See below:

Page 212 of 221


-: Internet of Things – The IoT World :-

5. The "data" folder contains below 8 files:

6. The php code post-esp32-generic.php is the server side code which you need to keep inside
your website server. This code will connect to your MySQL database and insert or delete RFID
data. Edit this code and provide your MySQL database credential as below:

Above config.php file actually contains the MySQL DB credentials in our server as below:

Page 213 of 221


-: Internet of Things – The IoT World :-

7. Edit the file script.js and provide your website URL of the php file post-esp32-generic.php as
below:

8. Now we are ready with our all web files inside "data" folder and we will move these files to our
ESP32. Close the serial monitor if opened, click on Tools => ESP32 Sketch Data Upload. This
will move all our files under "data" folder into ESP32 FILESYSTEM. See below:

Page 214 of 221


-: Internet of Things – The IoT World :-

Note: If you don’t have ESP32 Sketch Data Upload plugin installed, you MUST follow our SPIFFS
session first then try again.

9. Next, upload the code ESP32_RFID_Live_Status.ino into ESP32 by pressing upload button.
10. Great! We have uploaded all the codes and necessary data files into our ESP32. Only pending
activity is to create the MySQL database table on our webserver. For that, let's get connected
to our phpMyAdmin, select your database name, click on SQL tab, insert below query and click
Go to create the table. See below:
CREATE TABLE `imh_generic_table` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`record_num` int(11) DEFAULT NULL,
`record` varchar(1000) DEFAULT NULL,
CONSTRAINT imh_id_pk PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

11. That's it! We have finished all the activities and are ready to execute the code. Open the serial
monitor and press the RESET button on ESP32. You will see the IP address of your ESP32. Open
the web browser and go to the IP address. In my case it is http://192.168.0.105. See below:

Page 215 of 221


-: Internet of Things – The IoT World :-

Now swipe your cards on the reader and observe the live information on the web dashboard. See
below:

Voww! It is working like a charm!!

To store the data into MySQL DB, check the check box "Check this to SYNC with Database also"
and swipe your card again and observe the results on your web dashboard and DB table both. See
below:

Page 216 of 221


-: Internet of Things – The IoT World :-

If you wish, you can delete the data from the web dashboard and MySQL DB both by click on delete
action. See below:

Page 217 of 221


-: Internet of Things – The IoT World :-

Congratulations IoT magician! Another feather in your cap! You are really learning great stuff
every day! Many more to go… Keep growing magicians!!

Page 218 of 221

You might also like