In this article, we are going to learn some basics about RFID technology and use an Arduino MEGA to a play around with a popular RFID module, the ID12LA.
RFID stands for Radio Frequency IDentification. If you haven’t noticed yet, it is found in many places. This technology is near you right now!
RFID technology is commonly found in hotels, offices, banks, stores, etc. RFID chips are even implanted in pets to make sure that they can be identified and returned home if lost. It is often compared to a barcode. But even if it has the same use as a barcode, the two differ in a few ways.
In this article, we are going to learn some basics about RFID technology and use an Arduino MEGA to a play around with a popular RFID module, the ID12LA. You will be surprised by how easy it will be to incorporate this technology into your next electronics project!
The ID12LA. Image courtesy of Sparkfun.
Arduino MEGA - You don't have to use a MEGA, but this will do!
ID12LA Breakout PCB
The pins to the ID12LA are a bit weird so I suggest the breakout PCB from Sparkfun or any other reputable dealer.
Some jumper wires
Solder and soldering iron
Before we can start any kind of software or hardware planning, it is essential to have an understanding of the very basics of RFID.
In any RFID system, there will be a device that will have information, typically called a tag or transponder, and another device that will “look” or “sense” this information, typically called a reader or interrogator. Both components will need to have their own antenna to communicate and, depending on the type of RFID technology, they can exchange information one or both ways.
To understand this better, we need to understand the two distinctly different types of RFID technology: passive and active.
Let’s start with passive. In a passive system, the tag consists of an antenna and circuitry to house a unique code. But there is no power source (no battery), so how does the circuitry inside get powered?
The answer lies in the reader. In a passive RFID system, the reader will have an antenna that will emit RF energy that will induce a current in the tag’s circuitry. So whenever the tag is moving through the reader’s electromagnetic field, it gets powered and then immediately broadcasts its unique code. At the same time, the reader is also listening for this code.
At what range does all this happen? It depends on the reader and tag, but it is largely dependent on the frequency on which the code is broadcasted. The three main frequencies for passive RFID are:
Low frequency: ~125 kHz. Typically has a range of a few centimeters
High frequency: 13.56 MHz. Has a range of up to a meter
Ultra-high frequency: ~865 MHz. Has a range of about 30 meters
With all this being said, the ID12LA in our project is a passive type reader that consists of a built-in antenna and circuitry that can decode the tag and spit out serial data that our Arduino can understand. It is also 125 kHz which means we need tags that can be interrogated on that frequency.
Passive RFID may seem like it would have its shortcomings due to its short read range but these systems are generally inexpensive. Also, since the tags have no batteries, they can last a long time without service.
Now for active RFID.
As you might have guessed, these tags are always powered and thus have an onboard battery to transmit their code.
Because of this, along with the option of operating at either 433 MHz or 915 MHz, they have a very long read range—up to a couple of hundred meters! And since they have onboard batteries, they can be coupled with other technologies like temperature sensors and GPS tracking modules that can tailor to many different types of applications.
Finally, there are two types of tag styles you can purchase: transponder (like in passive RFID) and beacon.
A transponder tag is similiar to the passive system in terms of the communication protocol. The reader will send a signal to the tag to ask for its code.
A beacon tag will do the opposite and send a signal every so often on its own—but this really cuts down on battery life.
In either passive or active systems, you can have a tag that is read-only or writable. Read-only means just that, you cannot change the tag's data. Writable means that you can choose what data to place within the tag.
An active RFID tag. Image courtesy of RFIDinsider.
Communicating with the ID12LA with an Arduino
Phew! Now that we got that out of the way, let’s figure out how to get the ID12LA to communicate with the Arduino.
To follow along, I strongly suggest having the ID12LA's datasheet (PDF) handy.
So with our newfound RFID knowledge, we know that a tag will send a code to the reader, but then what happens?
This means that once a tag is read, information can be sent out of the reader in serial format, at 9600 baud, No Parity Bit, and 1 Stop Bit. This is a pretty common asynchronous serial communication setup and will make connecting to the Arduino a snap.
Once the reader sends out the data to the Arduino, we need a way to know when to start capturing data. Looking at how the reader spits out data, we find that it uses a Start of Text controller character. Basically, when the serial buffer has some data in it, we can first look to see if this control character is in the queue. If so, then we can go ahead and record the next. If not, we will keep reading until we see it or until the serial buffer is empty.
Assuming we read in the Start of Text controller character, we can go and blindly read in the next 10 ASCII characters from the serial buffer. Then, for the next 5 ASCII characters (2 for checksum, 1 for carriage return, 1 for line feed, and 1 for End of Text controller character), we will read them in but not save it anywhere in our program.
However, to ensure that our transmission was correct, we will double check to see that the End of Text controller character is seen. Though it may rarely be the case, the transmission might fail and we should throw everything we did out the window for the sake of system integrity.
Once the tag is read and saved somewhere in our program, we can use this data for whatever we want! A typical application is access control. You take your saved tag and compare it to a database of tags that are considered to be valid (in our case, we only use one saved tag). The problem is, how do we know what the tag’s code is before we save it to a database? It is not like the tag comes with a paper with its code scribbled on it from the manufacturer.
To work around this and begin to make a database for ourselves, we will need to read in the code and spit it out to the serial monitor. In the Arduino code section, I will provide easy-to-follow comments on where this occurs. When this happens, we will need to write this code down and then alter our program to store this code upon compilation. This is rather a manual way of doing it but this is for the sake of learning the basics of RFID.
Once that is achieved, I would encourage experimenting with programming a simple program sequence that could save RFID tag to EEPROM while the code is running, as well as a way to save and validate more than one tag.
Okay, so let us summarize what the Arduino code must do:
Monitor the serial buffer for available data.
When data is present, read and save it with some validation ensuring communication integrity.
Spit out the data to a serial monitor (primarily for initial setup) and compare this tag to our saved tags.
Perform an action (we will spit out a message to the serial terminal to illustrate this).
Wire it Up
The ID12LA has some nice features such as an output (pin 6) that indicates when a tag is in range and a beeper output (pin 10). However, we don’t use these features in our baseline interface.
For our application, we are using ASCII output. For this to happen, the datasheet tells us (on page 6) that we need to set the format selector input (pin 7) to ground. The data pin we will use is D0 (pin 9). For controlling the reader’s status, we will connect RES (pin 2) to +5V that way the reader is always on.
As for getting the ID12LA onto a breadboard, there's a reason that I suggested buying a breakout board from Sparkfun.com or some other reputable shop. The spacing on the ID12LA is not breadboard-friendly, and, unless you have female-to-male jumpers, will be impossible to connect easily.
For an example on how to wire on a breadboard, please take a look at my wiring setup below:
My tip is to try and be as neat as possible as it is easy to get lost while wiring. But whatever you do, please ensure the power and ground pins are where they are supposed to be! Follow the schematic!
The capacitor is not optional—it provides important high-frequency power-supply bypassing for the ID12LA.
Statement: This post is only the personal view of the author and does not represent the opinions of ALLPCB.com.