BLOG > Tutorial 12 for Arduino: RFID Card Reading

Finally!  It’s been about 3 months since my last arduino tutorial – I’ve been keeping busy as usual.  I’ve been working on this one for some time.  I got the parts months ago, made an outline a few weeks ago, prototyped the circuits and wrote the code last week, and did the filming over the last few days.  I’ve upped the ante for my production capabilities on this video.  I’m using two cameras (A Canon Vixia HF11 and a Canon EOS Rebel T3i Digital SLR), a fancy new Rode Shotgun microphone, and more tripods!  I’ve also implemented some improved audio processing on my voice-overs, so let me know what you think!

RFID technology is really really fun in my opinion, and I’ve been wanting to implement it in a project for some time now.  However, doing that can be challenging.  But, thanks to the tutorial below, you should have no problems putting together a simple RFID-based security system!  I explain the physics of how RFID works in the video, but if you’re a physics nerd like me, and you’re hungry for more, be sure to read up on RFID on wikipedia.  In this video, I’ll explain how to setup an RFID reader (like this one) with your arduino, read some serial numbers, and use that data to make a secure entrance database.

 

You can download the files associated with this episode here:

GNU GPL License Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.

192 comments

  1. thnaks my arduino work fine but . i test some time with the card and the rfid after read and write some time it stop read the card. but the loop still working wainting card.

  2. Hi jeremy, I’m earl and a newbie in arduino. I have aproject using RFIDREADER, GSM SHIELD, ARDUINO MEGA, and a database. The overview of my project is this: If the RFID reader reads a rfid card, it will then send the read code to the arduino mega and the arduino will relay the code to the database to compare if its already registered, if it is already registered, the database will get the information (such as cellphone No. and real time that the card was swipe) and it will send the info to the arduino mega to run the sketch of the GSM SHIELD to send THE info. My problems are interfacing my sketches of the rfid, and the gsm, to interface my arduino mega to the database to communicate and accept the info. by the arduino. And also to change the cellphone number and the real time in my sketch in GSM Shield in every swipe of the rfid card to the reader I’am using software serial to accommodate all these serial components.

      1. I have written the code and the program is reading the cards but it is only showing 3 symbols.. this is due to them being blank, how do I get them to show the whole serial number that they have been assigned?

      2. Hi Jeremy,

        You have written : “Each tag comes with a unique ID” and it seems true.
        But I would like to clone UHF and passive tag for security test purposes. I was thinking to emulate tag with the same TID but clearly I want to clone tag with copying also the TID.
        Do you think about a way to do that ?
        Regards,

        Laurent

  3. Hi! Sir, Can you please help me … I am working with the RFID reader using VB6 because I am new for this.. I don’t know how to read FRID reader using visual basic.. that when I tap an Id the Information will appear in the form.. please help..

    thanks in advance..

    1. hello we same project but my library system are already connect the reader
      and it’s already function..

  4. i am using rfid em-18…with tags….tag having 18 no on each tag…how to write with in the program where to modify the code..i am understand fully…pls help me

  5. i need an rfid reader and some tags , reader could read tag at a minimum of 15cm distance . please help me to choose one .? i need to connect it with arduino for a project

      1. 15cm might be far for NFC and high frequency (HF) RFID tags, but that’s a very attainable read distance with UHF passive RFID tags. However, you’ll need an RFID reader & antenna that can transmit enough energy to power the passive RFID tag, and I’m not sure if that’s going to be within the budget for a diy project. Anyways, it’s not uncommon for UHF passive tags to be read at distances of 20-30 feet.

        @Jeremy Great tutorial btw.

        1. hello
          can you give me some suggestions on getting appropriate RFID devices for STUDENTS… that can scan multiple tags(STICKER) per second.. around 9feet maximum read distance?? your words would be a great help..thankx..

          1. Hi, I’m not sure if you were asking me of Jeremy, but it would really depend on your budget.

            To reach that read range, you’ll want to research UHF which has a frequency range of 856 – 960 MHz.

            UHF RFID chips/tags are relatively cheap, but I’m not aware of many UHF RFID reader modules that are budget friendly. You’ll also need an antenna and cable.

            ThingMagic makes a UHF RFID reader with an integrated antenna, but it only has a read range of 3 feet. Also, it costs $445, but it’s the cheapest option I’m aware of. Here’s a link: http://www.atlasrfidstore.com/ThingMagic_USB_Plus_RFID_Reader_p/usb-5ec.htm

            Otherwise, you’ll need an entreprise level RFID reader, antenna, and cables.

            Hope that helps.

  6. hi.. is it possible to have the rfid card reader to only read a registered rfid card at a specific time? like for ex.. 1 rfid card will only gain access at 730 to 8 and the other will gain access at 9 to 10? and how will i make it happen??
    I would gladly appreciate your response.. pls?? ahaha tnx.. ^_^

  7. Hi jeremy, For my project I need to use the data of more than one RFID reader at a far distance, where my micro controller is situated. Can RFID reader transmit the data wirelessly? And how can I receive the data on the other hand on my controller? Please help me……

  8. hello sir,
    I am a student, we are tasked to make RFID reader that can scan multiple tags on boxes(sticker type) per second.. its like a inventory management style.. and also, what can u suggest to use appropriate devices to make it maximum 9feet distance.. your reply will surely be appreciated.. thank you so much..

  9. thank you so much. you did help me alot.. it would be my 2nd option.. for now, im so interested with the enterprise level.. but im not sure which one i need.. i was quite interested with their micro- lte module from thingMagic, but i dunno what other parts needed… if arduino based, Mr jeremy’s vid tutorial would be great help… but i need multiple tags per second..

  10. Anyone else having trouble finding the same xbee shield used in the video? The link on the parts list brings up a “product not found” page on element14 website.

  11. Never mind! I found it on the cooking hacks site. It was recommended during checkout when buying the rfid reader.

  12. Hi,
    I am very new for arduino abd hope this is not annoying you.
    I bought Aruino Uno V3 and NXP RC522 RFID
    after i connect pin fellow by code
    RC522–>UNO
    SDA –> 10
    SCK–>13
    MOSI–>11
    MISO–>12
    IRQ –X (no connect)
    GND–>GND
    RST–>9
    3.3V –>3.3V
    then i upload program (i got this example code from library after I add RFID library)

    /**

    * Read a card using a mfrc522 reader on your SPI interface

    * Pin layout should be as follows (on Arduino Uno):

    * MOSI: Pin 11 / ICSP-4

    * MISO: Pin 12 / ICSP-1

    * SCK: Pin 13 / ISCP-3

    * SS: Pin 10

    * RST: Pin 9

    *

    * Script is based on the script of Miguel Balboa.

    * Serial number is shown on a HD44780 compatible display

    *

    * The circuit:

    * LCD RS pin to digital pin (7)

    * LCD Enable pin to digital pin (6)

    * LCD D4 pin to digital pin 5

    * LCD D5 pin to digital pin 4

    * LCD D6 pin to digital pin 3

    * LCD D7 pin to digital pin 2

    * LCD R/W pin to ground

    * 10K resistor:

    * ends to +5V and ground

    * wiper to LCD VO pin (pin 3)

    *

    * @version 0.1

    * @author Henri de Jong

    * @since 27-01-2013

    */

    #include

    #include

    #include

    #define SS_PIN 10

    #define RST_PIN 9

    RFID rfid(SS_PIN, RST_PIN);

    LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

    // Setup variables:

    int serNum0;

    int serNum1;

    int serNum2;

    int serNum3;

    int serNum4;

    void setup()

    {

    Serial.begin(9600);

    lcd.begin(16, 2);

    SPI.begin();

    rfid.init();

    }

    void loop()

    {

    if (rfid.isCard()) {

    if (rfid.readCardSerial()) {

    if (rfid.serNum[0] != serNum0

    && rfid.serNum[1] != serNum1

    && rfid.serNum[2] != serNum2

    && rfid.serNum[3] != serNum3

    && rfid.serNum[4] != serNum4

    ) {

    /* With a new cardnumber, show it. */

    Serial.println(” “);

    Serial.println(“Card found”);

    serNum0 = rfid.serNum[0];

    serNum1 = rfid.serNum[1];

    serNum2 = rfid.serNum[2];

    serNum3 = rfid.serNum[3];

    serNum4 = rfid.serNum[4];

    //Serial.println(” “);

    Serial.println(“Cardnumber:”);

    Serial.print(“Dec: “);

    Serial.print(rfid.serNum[0],DEC);

    Serial.print(“, “);

    Serial.print(rfid.serNum[1],DEC);

    Serial.print(“, “);

    Serial.print(rfid.serNum[2],DEC);

    Serial.print(“, “);

    Serial.print(rfid.serNum[3],DEC);

    Serial.print(“, “);

    Serial.print(rfid.serNum[4],DEC);

    Serial.println(” “);

    Serial.print(“Hex: “);

    Serial.print(rfid.serNum[0],HEX);

    Serial.print(“, “);

    Serial.print(rfid.serNum[1],HEX);

    Serial.print(“, “);

    Serial.print(rfid.serNum[2],HEX);

    Serial.print(“, “);

    Serial.print(rfid.serNum[3],HEX);

    Serial.print(“, “);

    Serial.print(rfid.serNum[4],HEX);

    Serial.println(” “);

    /* Write the HEX code to the display */

    lcd.clear();

    lcd.setCursor(0, 0);

    lcd.print(“Cardno (hex):”);

    lcd.setCursor(0,1);

    lcd.print(rfid.serNum[0], HEX);

    lcd.print(‘,’);

    lcd.print(rfid.serNum[1], HEX);

    lcd.print(‘,’);

    lcd.print(rfid.serNum[2], HEX);

    lcd.print(‘,’);

    lcd.print(rfid.serNum[3], HEX);

    lcd.print(‘,’);

    lcd.print(rfid.serNum[4], HEX);

    } else {

    /* If we have the same ID, just write a dot. */

    Serial.print(“.”);

    }

    }

    }

    rfid.halt();

    }

    but when i test card(also keychain) it doesn’t reponse println in serial monitor
    do i done something worng ?TWT i have been search around internet for solution
    i did found someone connect it directly as i did but they could run as i expect but not for me.

  13. hi Jeremy, will you help me or any suggestion about my project
    the rfid library system, do you have idea about the exit
    sensor that affordable, where it can detect the rfid ID tags about more than 3 feet.
    thank you i advance.

  14. Do you know how to write to the MF RC522? I have been having trouble finding any info on that. I have no issues reading the cards.

  15. Hello.
    I’ve connected my RFID module according to that of the accompanying datasheet, but as soon as I attempt to load my code onto the arduino it returns an error as follows: avrdude: stk500_getsync(): not in sync: resp=0x00. This is however not the case when I remove the Rx and Tx connections to the RFID module. Am I perhaps wiring it incorrectly? I also am not able to access your schematic files, so I cant really compare setups, I’m considering using an I2C approach if the error persists.
    Thank you

    1. That is the expected response. You can’t program an arduino when you have something plugged into TX/RX, since those pins are multiplexed for USB serial communication. Unplug the module, program the module, then plug it back in.

  16. Hi jeremy, I am using the same rfid module that you have in the tutorial. The sample program works only if the antenna is vacant (no tag nearby) and gets activated when it senses the tag. However, my application is such that the tag is seating on the antenna for a length of time. I need to keep reading the tag verifying whether is the current tag or a new tag. This is a gameboard I am designing. The pseudo code:

    Loop
    {
    1. start rfid read

    2. if there is a tag read it goto 3 else goto 1

    3. Is the same tag, if yes report as same else report as new
    }

    The problem with the sample code is that it does not keep reading the tag. It reads only when originally placed but not anymore when the tag is seating on the antenna.

    I hope I did not confuse you. Thanks for any help you may render.

  17. Hello from Spain,
    Im following with excitement all your tutorials and I recently bought your book, which is also really helpful. Congratulations for your work and thank you for sharing your knowledge.
    But in this tutorial Im struggling. I can not upload the sketch you created. Arduino software tells me Serial.print(var,BYTE) is no longer supported since Arduino 1.0. It tells me to use Serial.write(), but Im not sure if Im doing it right. Im using the same shield and RFID reader as you did, but the UNO board.
    Im not sure where the problem is, but the RFID reader never seems to detects any card (it never ligths up the RFID led). Im moving the jumpers to USB position when uploading code, and then back to XBEE position when testing. Can you give me some advice?. Can you tell me how the code should look like using Serial.write? Thank you.

  18. hi jeremy, i have RDM630(125khz) RFID, i want to build my own antenna with reading range of 1 foot, can you please give me the needed diameter and number of turns?

    thanks very much

  19. Hae, am interested with arduino projects, i wanted to implement a code such that when The RFIDs detect the tag a message is sent to my phone.
    could you assist me in this please;

    Kindly send me via email

  20. hey jeremy … how r u?
    >>
    can you help me
    i have a project …. using arduino uno+GLCD+rfid12…. i need a program.. that can help me to give output data on the GLCD…when i read the tag..

    .
    .
    .
    with my respect…

  21. sir can u plz help me i brought a auduino uno the whole kit of rfid based secured access system…and i want to use visual studio 2008 IDE can u plz explain me step by step process of doing this project…..

  22. Hi, Recently the game Skylanders introduced game pieces that allow switching (TopA/BottomA and TopB/BottomB could be switched to TopA/BottomB and TopB/BottomA held together with magnets) where both tops and bottoms have RFID chips. How would they recognize the different pairings? It seems it would just be 4 different RFIDs? How can they tell which RFID is “on top” of the other? Can they sense positioning of the pair? Thanks for any insights.

      1. Hi, The toy figures have rfid chips inside. They are 2 part figures (bottom and top). The top has an rfid and the bottom has an rfid. There are many figures and you can swap tops and bottoms.

        http://www.youtube.com/watch?v=0BzrW-ta2so

        There can be 2 figures on a reader at the same time (4 rfids). My question was how do they know the combination of top and bottom for a figure.

  23. Hi, Jeremy I used Low Cost RFID and is not the same with arduino RFID you used in the tutorial.
    The RFID I used has TX and Rx pin , where will I connect this two in arduino uno?
    Thank you and God bless

  24. Hey Jeremy,

    Good stuff. I just watched your video and I had developed the same thing as you showed to control a simple locker. As you showed I recorded the ID of the card that has the access into the code, but I would like to use my SD card shield as well to be able to register new cards. The idea is to search inside of the “registry” file if the card that was swiped has access or not. I am afraid of making the system get slow as it may take a while to search inside of the file if that RFID has access or not.

    What do you think? My plan will be to have maybe 20-30 IDs registered.

  25. Hi sir Jeremy, is it possible to program a function which will have different time availability for each RFID cards? For example, I have a card number 1, then i would like it to be read by the RFID reader at 7:00am to 10:00am and then on the time onwards the card will not be read anymore. I mean the card will only be identified at the time of span it is programmed to. If it is possible, could you please help me?

  26. Hey Jeremy and thanks for all the awesome tutorials! I had the Rfid project in mind since I bought the arduino but lacked the skills on code to pull it off. Still do. One question tho is it possible to use the code for this tutorial on a adafruit pn532 Rfid shield? Thanks in advance for your help. I look forward to your next tutorials!

  27. Hello,
    I’ve tried to download the Arduino program from the link u provided; it downloaded but the zipd file is corrupted :-( will u mind sharing it once again.

  28. Hi jeremy,

    I am new to arduino. I’m going to do equipment tracking system by using the wireless device…I already had the RFID 6H10D and the arduino uno r3…I’m also going to link the rfid code with the database that I had make by using the MySQL, How I’m going to do it?

    1. I can help you about MySQL Database.But i can’t RFID 6H10D to work with Arduino.So we can help each other.

  29. I had bought arduino leonardo and RC522 rfid, I would like to integrate it C#.net so can you guide me how to do …

  30. Hi, i am doing a project for my university on which they gave me the materials but i am having quite a lot of problems implementing a code to read / write the rfcards. The materials are arduino uno, Hobbypower Pn532 NFC Rfid Reader/writer Shield Breakout Board Module Compatible Arduino (http://www.amazon.com/dp/B00HY847G4/ref=asc_df_B00HY847G43254247?tag=thefind0178220-20&creative=395261&creativeASIN=B00HY847G4&linkCode=asn) and a wifi shield for arduino. How can i implement it without using the same pins. the main problem is that there is almost none information about this rfid reader/writer.

    thanks for your time and help

Leave a Reply to Rakesh Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement