Arduino and the RFID reader ID-12

This tutorial is all about wiring the RFID reader ID-12 and retrieving RFID tags via an Arduino board. There are already a few good tutorials with working code out there, but all of them are quite basic and therefore I want to show you how to use it in more complex applications.

There are basically 2 major differences in comparison to other implementations:

1. software serial
The ID-12 uses a serial connection to send the tags. All the other implementations are using the hardware serial pin (RX) to retrieve the information and send it to the computer. The problem of this setup with the ID-12 blocking the receive pin is that you can’t send any data from the computer to the arduino board anymore. This implementation is using a software serial connection on an other I/O pin in order to maintain bidirectional communication.

2. RFID tag removed
The ID-12 has no native method to determine whether a RFID tag is still in range or has been removed already. With a little workaround you can get this information as well.

but enough talking, get this thing started:


Connect pin 11 to +5V, 1 and 7 to ground, 2 and 9 to Arduino pins 4 and 5;

Arduino code

First of all you have to get the AF_SoftSerial library (you will need an Arduino board with an ATmega168) or NewSoftSerial (for ATmega328). Uncompress and place it in the hardware/library directory under your Arduino software installation.

After installing the AFSoftSerial library you can download my arduino code and upload it to your board. I don’t want to go through the code in detail, you can always leave a comment or get in touch with me if you have problems with it.

void loop () 
  byte action = 0;
  unsigned int now = millis();
  // connection to computer established
  if(connected == true)
    clearTag(rfidTagTemp, 6);
    // serial connection with rfid reader
    if (rfidSerial.available()) 
      // wait for the next STX byte
      while(rfidSerial.available() && action != 0x02)
        action =;
      // STX byte found -> RFID tag available
      if(action == 0x02)
          nowLastRfid = millis();
          rfidTagSeen = true;
    else if(rfidEnabled && rfidTagSeen == true && (now - nowLastRfid) >= RFID_REMOVED_TIME)
      rfidTagSeen = false;
  // serial connection with computer
  while (Serial.available() > 0) 
    // read action byte
    action =;
    switch (action) 
      // PING
      case 0x01:
        Serial.print(0x01, BYTE);
      // (C)ONNECT
      case 0x43:
        // clear serial
        connected = true;
      // (D)ISCONNECT
      case 0x44:
        connected = false;
  // delay 100 milliseconds

The first part of the code is for reading the RFID tags and checking if the tag is still in the range of the reader.

The second part handles the communication with the computer. You can define specific bytes as marker and accordingly get the value of different sensors, execute functions on the hardware or whatever you want, e.g. in order to use the RFID reader and get an output of the RFID tags on your console you have to send the connect marker which is a "C" or 0×43 in hex.

Update 08.02.2010 – Fix for the Atmega 328 chip

Finally a fix for the Duemilanove (which is using an Atmega 328 chip). There is a new Sofware Serial Library out there which works with the Duemilanove, it’s called NewSoftSerial. Just use this library instead of the old one and everything should work. Thanks Thijs for the information

48 Responses (Add Your Comment)

  1. interesting code- seems you have to make a big effort with these devices…
    Also took some time to get your code working- problems most likely with the ID-12 reseting(??)

    I have found the ID-12 very unreliable,and it does not meet the claims
    made by its makers for range, sensitivity etc.

  2. thanks for your comment. in my case the performance of the ID-12 is quite good but I didn’t try other readers so far, so I have no comparison.

    I’m using the Mini (V3) and the Diecimila and the code works fine, but apparently there are some issues with newer boards like the Duemilanove. Which Arduino are you using?

  3. Joeri Dehouwer March 30, 2009
    at 7:00 pm

    I’m using your code in combination with a duemilanove and for some reason it stops working after a few reads. The ID-12 apparently still recognizes the tags (the LED blinks) but the data is not transmitted… Any idea why?

  4. I’ve heard from a few people now that there are some problems using the code with the duemilanove, but I don’t have one here … so I can’t test it on my own. I guess there is a problem with the software serial. If you find a solution, tell me and I’ll update the code.
    I guess I’ll go for a duemilanove soon …. lets see

  5. Thanks for sharing, it’s great help!

  6. Hi,

    I can’t seem to get the reader working using this code. I am using a Decimilia board and have the correct AFSoftSerial library but it doesn’t seem to work.

    It connects when i send a “C” but then doesn’t seem to read the tag… its not getting into this if statement:
    if (rfidSerial.available())
    // read tag…

    I’m new to all this but do you have any ideas?

    Many thanks,


  7. uhmm, did you wire up everything correctly? not getting into the if statement means that you don’t get any data from the id-12. First of all I would try if the id-12 works. Just hook it up to the hardware serial port (RX) and check if you receive any bytes. If this works than it’s definitely a problem with the AFSoftSerial library.

    Keep me updated about your progress.

  8. It definitely works as I had it working and reading rfid tags through the serial port. I used the example in the arduino playground.

    It must be a problem with the AFSoftSerial library… but i’m not sure how to go about resolving it? It couldn’t be to do with the ide could it? I’m using the latest one downloaded from the liquidware blog – Antipasto Arduino?

    Thanks for your help in advance…

  9. I have never seen or used the IDE your are talking about, so maybe try the arduino IDE. Did you setup the AFSoftSerial on PWM pins?

  10. Ah, I don’t think I used the PWM pins for the AFSoftSerial I just used pins 4 and 5 on the Deicimila… I’ll try using the standard IDE from arudino and have a look at the pins…


  11. After a second (or more like 10th check) i realised had it wired up wrong! It works perfectly… thanks for humouring me…

    Now to get working with the Stealth TouchShield and maybe a bit of ActionScript if I’m feeling lucky…

    Thanks again,


  12. Superb! Exactly what I was looking for. Thanks for sharing this piece.

  13. Hm, i have just tried this project on Arduino Deumilanove and it does not work. When it comes to this statement action =; it reads zero only once and there is no connection to RFID anymore.

    Any suggestions?

    Thanks for sharing this…

  14. hey john, like I allready mentioned above, there are some problems using the duemilanove, but I don’t have one here, so I can’t test it

  15. Hi, i need something like this but i don’t know if this reader works for me.
    I need to detect when a tag is remove from the range. This can be done reading continually tags but the tags have to be read as fast as posible.
    Could you tell me how fast can you detect a tag? I mean how many times per second can the reader detect a tag. Thanks in advance and thanks for sharing this.

  16. The reader can read a tag very fast and continuously, but when it comes to detect when a tag is removed you need to add some delay because you have to reset the reader. the delay is at 1500ms in my code at the moment. I guess you can also use a shorter delay … maybe 1000ms.

  17. Hi, thanks for your fast reply. I wonder if i could use it without any delay because i would like to get several readings per second.
    Is the delay for your code or because it is the time the reader takes to restart after the reset?
    Is it posible to read several times per second with this reader?
    Thank you so much

  18. Basically the ID-12 reads the same tag only once while being in range. with the reset you can implement a continuous reading of the tag. To reset the ID-12 you have to pull down the reset line to 0V and afterwards pull it up to 5V, physically this takes some time and therefore you’ll need some kind of delay.

  19. Ok, thanks

  20. Is it possible to read multiple tags at the same time using the ID-12?

  21. no, you can only read one tag at the same time

  22. Hi,

    I build the your example using a Diecimila with an Atmega 168 and it works great.
    After that I tried it wit the Deumilanove wit Atmega 320 but I couldn’t upload the program…

    Have you all ready did some tests to find the “Deumilanove” problem?

    Thank anyway!

  23. Hi,

    real nice work!,
    I would like to build this however i got the duemilanove :( ,
    did anyone find out what the problem is with the newest arduino?

  24. I am having trouble with the Arduino file finding the custom library. I am using a Duemilanove and maybe going to use a Mega.

  25. see updates in the post for the duemilanove

  26. Really great help.
    I’m building an object with arduino using your schemas and sketch…
    I’ll tell you my progress soon.
    It works :-)

  27. Hey, Thanks for a great tutorial I’ve been making use of this code for my project with the RFID and it’s been great.

    I’m having a problem resetting or clearing the reader though and I’m not sure if it’s in code or hardware. The first time I run through my loop it reads the tag and works fine. The second time it either has the old tag or crashes when a new one is detected. What parts of the code clear it?
    P.S I also tried putting digital 4 on the arduino (the reset line) low then high, Like this:

    digitalWrite(RESET_PIN, LOW);
    digitalWrite(RESET_PIN, HIGH);

    but it didn’t change it which means its software?

  28. there is a function called clearTag, should be obvious that this clears the tag. the resetting is done in line 233-254. What exactly crashes? I don’t think that there’s a problem in with the arduino or the arduino code

  29. please help. my id20 is dead its outputting no data. please help. no led is glowing. is there any way to find if it is still working?

  30. I may have done too much editing of your original code, but I think that you forget to reset index back to index = 0 when you clear the tagString variable. Fought with this for a while!

  31. hey tom, which index do you want to set to 0. I don’t think that there’s any problem in the code

  32. hello martin!!, I’m Carlos, i from México, You have got a Interesting blog, i’m working in a prototype with ID-12, i wonder to know if I can work with a Microchip microcontroller board based on the 18FXXXX or ATMEL microcontroller board based on the ATmega168. For the last, could your code works with arduino mini? Sorry for bad English and so much thanks :)

  33. hey carlos, I don’t know anything about 18FXXXX or ATMEL. the code works with arduino mini

  34. hello martin, I´m Carlos again, afer working with pic 18f4550 for 2 moths, I had descovered, 18f4550 works great with RFID-12.

    If someone wants the code, coud ask me!

    PD.Sorry for bad English

  35. Hi!

    I’m trying to use your code to read an id12. I’ve got it set up on a Arduino Mega. I’m having a problem where the “action” value in the while(rfidSerial.available() && action != 0×02){
    loop is always 255 it never equals 0×02. Any ideas of what I’m doing wrong?

  36. sorry alan, I don’t have any clue. I don’t have an Arduino Mega here, so I can’t test it.

  37. hi
    i’m using ID-12
    and i’m using PLX-DAQ from Parallax.
    i send RFID code to PLX-DAQ (ms.excel) via serial comm.

    i guess PLX-DAQ can do it vice versa (excel will send back the data to arduino)
    here pin 9 of ID12 is connected to pin 0 RX arduino.

    what should i do if i want to read what excel send to arduino?
    change the pin RX of rfid?
    how can i read what excel send? use

    thanks for advance

  38. Hi,

    I try to use two ID-12 read tag. Do you know how to do this?


  39. with software serial you can setup the ID-12 on any pin, so you can use RX/TX pins and with software serial any other to connect the second ID-12

  40. Wonderful goods from you, man. I’ve understand
    your stuff previous to and you are just too magnificent.
    I actually like what you’ve acquired here, certainly like what you’re saying and
    the way in which you say it. You make it entertaining and you
    still take care of to keep it sensible. I cant wait to read much more from
    you. This is really a wonderful web site.

  41. Really interesting entry, keep up like more! I will surely be trying back now often:) I would still usually be content near the following any longer, but I must keep working.

  42. I AM LAZY.. So..
    The question is:
    2. If cannot, what is the solution?

  43. hi I am very happy with your article, I want to ask, I want to make the project a barrier gate. bbisa help me to make the arduino code and rfid id-12 to drive the dc motor?


Leave a Reply

Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Other Entries


Martin Rädlinger is an Interactive Developer & Designer. He specializes in interactive coding predominantly with ActionScript, but every new challenge is welcome. If you like his work feel free to get in touch with him. At the moment he's available for freelance work.


Martin Rädlinger
mail: mr [at]
xing: Martin Rädlinger
linkedin: Martin Rädlinger
skype: martinraedlinger