Arduino Tutorials – Chapter 15 – RFID

Learn how to use RFID readers with your Arduino. In this instalment we use an RDM630 or RDM6300 RFID reader. If you have an Innovations ID-12 or ID-20 RFID reader, we have a different tutorial for you.

This is chapter fifteen of our huge Arduino tutorial seriesUpdated 19/11/2013

Introduction

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. It sounds complex – but isn’t.

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 Arduino 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:

Arduino RFID tags

In this tutorial we’ll be using 125 kHz tags – for example. To continue with the analogy 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:

Seeedstudio RFID reader Arduino

These readers are quite small and inexpensive – however the catch is that the loop aerial is somewhat fragile. If you need something much sturdier, consider the ID20 tags used in the other RFID tutorial.

Setting up the RFID reader

This is a short exercise to check the reader works and communicates with the Arduino. You will need:

Simply insert the RFID reader main board into a solderless breadboard as shown below. Then use jumper wires to connect the second and third pins at the top-left of the RFID board to Arduino 5V and GND respectively. The RFID coil connects to the two pins on the top-right (they can go either way). Finally, connect a jumper wire from the bottom-left pin of the RFID board to Arduino digital pin 2:

Arduino RFID reader setup

Next, upload the following sketch to your Arduino and open the serial monitor window in the IDE:

If you’re wondering why we used SoftwareSerial – if you connect the data line from the RFID board to the Arduino’s RX pin – you need to remove it when updating sketches, so this is more convenient.

Now start waving RFID cards or tags over the coil. You will find that they need to be parallel over the coil, and not too far away. You can experiment with covering the coil to simulate it being installed behind protective surfaces and so on. Watch this short video which shows the resulting RFID card or tag data being displayed in the Arduino IDE serial monitor.

As you can see from the example video, the reader returns the card’s unique ID number which starts with a 2 and ends with a 3. While you have the sketch operating, read the numbers from your RFID tags and note them down, you will need them for future sketches.

To do anything with the card data, we need to create some functions to retrieve the card number when it is read and place in an array for comparison against existing card data (e.g. a list of accepted cards) so your systems will know who to accept and who to deny. Using those functions, you can then make your own access system, time-logging device and so on.

Let’s demonstrate an example of this. It will check if a card presented to the reader is on an “accepted” list, and if so light a green LED, otherwise light a red LED. Use the hardware from the previous sketch, but add a typical green and red LED with 560 ohm resistor to digital pins 13 and 12 respectively. Then upload the following sketch:

In the sketch we have a few functions that take care of reading and comparing RFID tags. Notice that the allowed tag numbers are listed at the top of the sketch, you can always add your own and more – as long as you add them to the list in the function checkmytags() which determines if the card being read is allowed or to be denied.

The function readTags() takes care of the actual reading of the tags/cards, by placing the currently-read tag number into an array which is them used in the comparison function checkmytags(). Then the LEDs are illuminated depending on the status of the tag at the reader. You can watch a quick demonstration of this example in this short video.

 

Conclusion

After working through this chapter you should now have a good foundation of knowledge on using the inexpensive RFID readers and how to call functions when a card is successfully read. For example, use some extra hardware (such as an N-MOSFET) to control a door strike, buzzer, etc. Now it’s up to you to use them as a form of input with various access systems, tracking the movement of people or things and much more.

And if you enjoyed the tutorial, or want to introduce someone else to the interesting world of Arduino – check out my book (now in a third printing!) “Arduino Workshop” from No Starch Press.

tronixstuff

In the meanwhile have fun and keep checking into tronixstuff.com. Why not follow things on twitterGoogle+, subscribe  for email updates or RSS using the links on the right-hand column? And join our friendly 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.

The following two tabs change content below.

John Boxall

Founder, owner and managing editor of tronixstuff.com.

39 Responses to “Arduino Tutorials – Chapter 15 – RFID”

  1. Ken says:

    Can the reader read multiple tags at a go?

  2. Michelle says:

    Can the module write data on the RFID tags?
    Is there any example?

  3. ivan says:

    i mean i don’t have a clear idea about the resistence ohm , one is – , the other one must be + for the leds indicators or is the part of the digtal pin 1 turn on and off the light?

    regards

  4. andhika dwi says:

    hi, could you help me please?
    i use rfid em9918 and board arduino uno with atmega 328p. but when i run your program, it can’t build well.
    there is a cmmand like this :
    Binary sketch size: 8.236 bytes (of a 32.256 byte maximum)
    avrdude: stk500_getsync(): not in sync: resp=0×00

    what does it means? please help me to solve it.
    thanks.

    • John Boxall says:

      avrdude: stk500_getsync(): not in sync: resp=0×00
      is a common problem, usually related to the Arduino not connecting with your PC. Google can answer that. However if you have your RFID connected to D1/D0 remove these before uploading sketches.

  5. andhika dwi says:

    Mr John, i was try to run on other PC and it can work, the lcd.print program on IDE can appears on LCD. But when i install RFID serial driver on the other USB port, i can not work again.
    I tried to check setting menu, but they were on different COM (from USB port), actually i have confuse with this problem.
    Thank you for helping

  6. Nad says:

    Hi!

    Can I use RDM630 or RDM6300 to do multiple reading of card ID – say, every 2 seconds. The purpose is to detect presence of the card near the coil and the moment when user removes the card? Thank you.

  7. ivan says:

    thank you John another cuestion is the bobbin is too small(rdm630/125k) and i think that’s why i need to be very close tag and bobbin, can i change the bobbin for one more big? what specifications do i need?

  8. emperor says:

    Is it possible to add 100 tags?coz after I tried to add 51 tags, the tag51 doesn’t accepted.

  9. Omar says:

    i make all steps but no response from my rfid or serial monitor
    the rfid led is on but no response
    i try the both codes
    i am using arduino leonerdo and i am sure of my hardware connection 100%

  10. muhammed magdy says:

    hi am working on module parellex28140 for rfid could you supply me with some information about the arduino sutiable for it codes board everything

  11. Topu says:

    i have left a comment few days ago, bt it vanished. whatever, i am asking again.
    Dear john, can you please tell me how can i set my tag1 number where my card value is “080078FE0F80″.. i set tht value to ur given code in tag1.but u know it doesnt support char value. moreover i convert the number to ASCI value but still no result. my RFID module is this one http://www.seeedstudio.com/wiki/Grove_-_125KHz_RFID_Reader
    .please john,i need ur help.

    • John Boxall says:

      If you setup your reader as shown for the first example, does it read tag values?

      • Topu says:

        yes,it does.. and the tag value is “080078FE0F80″..but i cant use that for ur 2nd example to the purpose of comparing values.but i need it very urgent .. please, give me solution for comparing tag values..

      • John Boxall says:

        If you use the method in the tutorial you have a way to compare values. I don’t create custom solutions for everyone.

  12. nhuda says:

    hello how about if i use existing card such as student card? it is possible for me to use the coding?

  13. Gabriel says:

    Hi John,

    When I use the RFID in the Ethernet Shield it does not work, so I saw no incompatibility with pin 2, you know why he does not read any TAG?

    Tks,
    Gabriel.

  14. redone says:

    Hello ,

    pleaze i’m trying to do the same thing but i want that my RFID detect tags from 1 metter it is possible with the same ship ?

    • John Boxall says:

      You will need to invest in some industrial RFID readers.

      • redone says:

        please another question with this module can we know the distance between the card and the module because i add a buzzer and i want that when i get closer the buzzer be higher volume thank you

  15. caezar says:

    whenever i wave my RFID card, nothing appears on the serial monitor why is that sir? all set up is right, its just that im using gizduino x not arduino uno

Trackbacks/Pingbacks


Leave a Reply

Receive notifications of new posts by email.

The Arduino Book

Arduino Workshop

Für unsere deutschen Freunde

Dla naszych polskich przyjaciół ...

Australian Electronics!

Buy and support Silicon Chip - Australia's only Electronics Magazine.

Use of our content…

%d bloggers like this: