Moving Forward with Arduino – Chapter 15 – RFID Introduction
Please note that the tutorials may not be compatible with Arduino IDE v1.0. Please continue to use v22 or v23 until further notice.
This is part of a series originally titled “Getting Started with Arduino!” by John Boxall – A tutorial on the Arduino universe. The first chapter is here, the complete series is detailed here.
Welcome back fellow arduidans!
In this instalment we will start to examine RFID systems
Please note that we will not be discussing the use of 13.56 MHz RFID systems such as NXP “Mifare Classic”. I’m not going to teach you how to clone stored-value public transport fare cards.
First of all, RFID – radio frequency identification. Some of us have already used these things, and they have become part of everyday life. For example, with electronic vehicle tolling, door access control, public transport fare systems and so on. Personally I thought the electronics behind RFID systems was quite complex, and had even procrastinated with examining them myself… however finally I ordered some parts in and had them working almost no time. (There’s a good lesson in that for all of us).
To explain RFID for the layperson, we can use a key and lock analogy. Instead of the key having a unique pattern, RFID keys hold a series of unique numbers which are read by the lock. It is up to our software (sketch) to determine what happens when the number is read by the lock. The key is the tag, card or other small device we carry around or have in our vehicles. We will be using a passive key, which is an integrated circuit and a small aerial. This uses power from a magnetic field associated with the lock. Here are some key or tag examples:
Our lock is a small circuit board and a loop aerial. This has the capability to read the data on the IC of our key, and some locks can even write data to keys. Here is our reader (lock) example:
As you can see from the 5mm graph paper, the circuitry is quite small, and the loop is somewhat fragile. For installation and use, it would be wise to mount the loop aerial inside something strong and protective. But more about that later. The RFID system we will examine works on the 125 kHz frequency, but that is not so relevant at this stage.
Our use for the RFID equipment is to have our sketch make a decision based on the unique tag number. For example, it could be used as a switch to turn on and off something, perhaps an alarm system or a computer. It could control an electric door strike (lock), or activate a series of lights to one’s personal preference. The possibilities are only limited by your imagination. I hope that with your existing knowledge you can implement this RFID equipment into your next prototype or product.
Example 15.1
First of all, let’s do a basic test – what happens when we read a tag? To do this we need to connect our reader to the Arduino or compatible board, and see what comes out when we read a card. The connections are quite simple:
You may need to remove the wire from the RFID reader to Arduino D0 before uploading the sketch, then replacing it after the upload. From the reader data sheet.pdf (our version is the TTL model), the reader sends out serial data from the TX pin at 9600 bps. We will read that data using the serial input (digital pin zero on the board) and display it on the serial monitor box to see what it looks like. The LED activates (rather dimly) when reading is taking place. Here is the sketch to use.
Once the sketch has been uploaded, open your serial monitor box, and wave a tag over the antenna. You should have a reading similar to the video below, however your tag number will be different.
Excellent – simple numbers that we can work with. For example, one of my tags returns: 2,51,69,48,48,49,65,51,53,70,50,69,51,3 and another returns 2,51,67,48,48,67,69,49,48,68,53,51,55,3. Note that both start with 2 and end with 3, so the unique tag details are the 12 integers between the 2 and 3. One could read the data as characters or hexadecimal numbers by altering the data type in the sketch from int to byte, but for simplicity I am working in integers.
Now all we need to do is fashion sketches to recognise the tag number(s) we want to use, and perform an action based on which tag number is used (or do something when a tag is read, but not the tag you want).
Example 15.2
In the following example, (download) the sketch reads the 14 integers returned from the card reader when a tag is swiped. These integers are placed into a fourteen element array, which is then compared against arrays holding the numbers my “allowed” tags. If an allowed tag is read, the green LED comes on, if a disallowed tag is read, the red LED comes on. Of course you could have the digital outputs controlling other things using a switching transistor or a relay. Below is the schematic:
The hardware laid out:
And a short video in action:
Excellent – now we are getting close to something useful. The example above could make a simple door control, or an over-engineered cookie jar.
Speaking of cookies, time for a cup of tea…
Now for some more practical uses of RFID and Arduino. In the past we have worked with real time in many chapters, and also have stored data using a microSD card shield. So:
Example 15.3
We will build on our previous example by adding time and date logging for all accesses to the system, successful or not. This could be used again for door access, payroll calculations as a modern-day punch-clock, or even a simple logging device to see what time the children arrive home when you aren’t around to check. So we will need a microSD shield, and some sort of DS1307 breakout board or shield.
When using more than one shield together, be mindful of the pins you will need to use. For example, my DS1307 shield uses analogue 4 and 5 (for I2C interface), and the microSD shield uses digital 10 to 13.
The sketch for this example is quite simple – the good thing about programming for Arduino is that just like the hardware shields, sketch procedures and functions can be very modular and reused quite easily. If you are unsure about the microSD shield, please read my instructional review. Most of the code can be copied from that microSD shield article’s demonstration sketch, which I have done for this example. The sketch writes the time, date, tag number, and read status (accepted/rejected).
However there is one caveat when using the microSD shield – the file needs to be closed before the card can be removed for examination. In practical use, our RFID system would be usually on most of the time, so a method will needed to activate the card write function. This has been implemented with a function bossMode() that is called when a certain tag is read – one may call this the supervisor’s card. Once this particular tag is read, the file is annotated as closed, reading stops, and the LEDs blink alternately when it is safe to remove the card. A simple reset after the card is reinserted will start the reading again. Here is the sketch, and a hardware layout.
The schematic is the same as example 15.2, with a few simple additions – the use of the microSD card shield, and the DS1307 real time clock shield. If you are using a DS1307 breakout board wired in separately, please use the following schematic as a guide:
Now here is a short video clip, with the addition of the ‘boss mode’ shutdown sequence:
And finally, here is a copy of the text file that was produced from a recent test run:
As you can see, it is easy to reproduce expensive time-keeping systems with our own equipment and some time. In the near future we will return to RFID and build some self-contained units with an LCD display (I need to get some more LCD units!)
Thus concludes our introduction to RFID systems. However, stay tuned for more about this and other interesting things!
Have fun and keep checking into tronixstuff.com. Why not follow things on twitter, Google+, subscribe for email updates or RSS using the links on the right-hand column, or join our Google Group – dedicated to the projects and related items on this website. Sign up – it’s free, helpful to each other – and we can all learn something.














Wow, an off the shelf RFID datalogger for outdoor use costs over $1000. I’m a wildlife biologist, and this thing will save us a fortune. I’d like to try using it to log mouse visits to food caches. The mice would be tagged with subdermal PIT tags (just a glass encapsulated RFID tag, PIT=passive Integrated Transponder). All I need is the mouse ID and a timestamp, so why pay a fortune for some over the top gadget with all the bells and whistles.
How about a follow up project incorporating a solar battery charger shield? or a bluetooth data access module? pleeeease?
hello mousedude
A solar battery shield? I’ll put it on the long list
You could probably make the whole setup you have described for <US$150.
cheers
john
Excellent
Thank you very much
John
My parents were discussing the other day about my grandmother, who’s arthritis is playing up. Apparently she finds it difficult to unlock her doors at home.
One of these, coupled with an electronic door striker, would go a long way to helping her out. Thanks for the write up, John =)
Hello
No worries, I hope you can help out your Grandmother. Jaycar and little bird have a range of electric door strikes which might be useful. Jon Oxer has done this with his home, have a look at: http://www.practicalarduino.com/projects/rfid-access-control-system … plus he has the RFID as an implant.
cheers
john
I have the same setup and get the same sot(2) and eot(3) with
12 groups of 2 digit numbers, but I can not match the numbers printed on the tag any ideas?
Hello Andrew
Thanks for your question. I just had a look at mine, same deal. The printed number seems to be a separate tag serial number, which differs to the RFID number.
take it easy
john
Check this project out witch me and some friends made in school: http://www.youtube.com/watch?v=aUc2MldEJio
Hi Kristian,
Nice project! Check your youtube mailbox, I sent you a message.
David
Hi,
Is there a way to get few tags with the same ID or to copy them? I speak about the same tag from Little Bird Electronics.
David
The tags that are easily available cannot be purchased with identical ID numbers. If you are so inclined you could build an RFID spoofer:
http://hackaday.com/2010/11/28/rfid-spoofer-with-code-and-instructions/.
have fun
john
I am stuck on the tag ID section..when I read my yellow tags in the monitor console it is 3C00CEACC698
so do I convert this to decimal 65974165096088
and therefore in octets
// define the tag numbers that can have access
int yellowtag[14] = { 6,59,74,16,50,96,08, 8};
??
I am getting error: invalid digit “8″ in octal constant
Out of curiosity, why are you using octal? You can easily work with decimal numbers, as shown in the examples.
the problem is in the way he wrote the constants. He was breaking it up 2 digits at a time, and so he used 08 instead of 8. However, a leading 0 tells the compiler you’re using octal, so 08 is nonsensical. It needs to just be 8 not 08.
Excellent, thanks for that.
John
im working with arduino mega board and the software Arduino 1.0
I i think i have the same RFID chip but honestly it look a litte diferent..but (data sheets are the same)
My problem:
the example 1 dont works very good, i can just see one list with 2 values (255 and 254) but it doesnt works as in the video..
other problem is each time that i put my card i get diferent values secuence. for example for the card 1
i see in the serial monitor (255 255 254 255 244 255) but in the next time using the same car i get (244 244 244 244 255 255)
i expected to get always the same values for one card but it dont works in this way.
could you help me, ?
i
Arduino v1.0 works a little differently with Serial commands. Try using Serial.write instead of Serial.print.
Hello,
may I ask? why my rfid code program can’t work if using RFID RDM6300? but if using RFID RDM630 my code program can run properly. thank you
this is my code : http://goo.gl/OHrwS
Hi, i got a quick question. I am doing a final year project on RFID Tracking. i need to build an circuit which gives me a freuency of 13.56MHz (oscillator). i couldnt find any circuits to design on multisim or ltspice. can u help me out pls?
No. If it is a final year project your teachers expect you to have the knowledge to work it out for yourself.
Hello, i have follow ur instruction base on example 15.1
Once i upload my program. i always get the error:
avrdude: stk500_getsync(): not in sync: resp=0×00
I tried using arudino 1.0.0 and 1.0.1.
could u help me? Thanks
Try removing the wire from the RFID reader to Arduino digital pin zero before uploading the sketch, then replace it afterwards.