You are on page 1of 14

 (/) Circuits Tutorials

Arduino (/circuits /) – RFID


Worksby
hoptronixstuff
(/works hop/) Craft (/craft/) Cooking (/cooking/)
(/member/tronixstuff/) Follow Log In (/account/login/)
|
Sign Up

Living (/living/) Outs ide (/outs ide/) Teachers (/teachers /) (/account/register/)

Download
Favorite
w I Made It

instructables (/circuits/) Projects (/circuits/projects/) Contests (/contest/) Let's Make...


circuits 

Arduino Tutorials – RFID


By tronixstuff (/member/tronixstuff/)
in Circuits (/circuits/) > Arduino (/circuits/arduino/projects/) 164,030 212 17

Download Favorite

(https://content
auto=webp&frame=1&fit=bounds&md=4c2bd0aad10da350d1363b91f4e2491c)
instructables com/ORIG/F0D/12JV/HO2344PA/F0D12JVHO2344PA jpg?

(/member/tronixstuff/)

(/A d i (/A d i (/G l


By tronixstuff (/Arduino- (/Arduino- (/Google-
Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow More by Book- Tutorial- Docs-and-
(/member/tronixstuff/)
the author: Monster/) Numeric- the-Arduino-
tronixstuff (http://tronixstuff.com)
Keypads/) Yún/)
Follow
Download
Favorite
w I Made It

About: Technical person. Visit http://tronixstuff.com for Arduino and other tutorials, projects, kits, reviews and more.
VK3FJBX http://arduinoworkshop.com
More About tronixstuff » (/member/tronixstuff/)

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 (http://tronixstuff.com/2013/02/26/arduino-tutorial-15a-rfid-with-innovations-id-20/)
for you. This is chapter fifteen of our huge Arduino tutorial series
(http://tronixstuff.com/tutorials). Updated 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. Some key or tag examples are shown in the image above.

 Add Tip V Ask Question | Comment Download

Step 1: Getting Started


Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

Download
Favorite
w I Made It

(https://content
auto=webp&frame=1&fit=bounds&md=bc7c28722139c68268ded606446bcef7)
instructables com/ORIG/F27/0UD4/HO2344PB/F270UD4HO2344PB jpg?

In this tutorial we’ll be using 125 kHz tags – for example


(http://www.seeedstudio.com/depot/rfid-tag-combo-125khz-5-pcs-p-700.html?cPath=19_24).
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. Our
reader (http://www.seeedstudio.com/depot/125khz-rfid-module-uart-p-171.html?
cPath=19_24) (lock) example is show in the image above.

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 (http://tronixstuff.com/2013/02/26/arduino-tutorial-15a-rfid-with-innova-
tions-id-20/).

 Add Tip V Ask Question | Comment Download


Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

Step 2: Setup Your RFID Reader


Download
Favorite
w I Made It

(https://content
auto=webp&frame=1&fit=bounds&md=4c2bd0aad10da350d1363b91f4e2491c)
instructables com/ORIG/FG4/OKUZ/HO2344P9/FG4OKUZHO2344P9 jpg?

Setting up the RFID reader

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

1. Arduino Uno or compatible board and matching USB cable


1. solderless breadboard
1. three jumper wires
1. the RFID reader package (http://www.seeedstudio.com/depot/125khz-rfid-module-uart-p-
171.html?cPath=19_24)
1. someTutorials
Arduino RFID tags or cards
– RFID (http://www.seeedstudio.com/depot/rfid-tag-combo-125khz-5-pcs-
by tronixstuff (/member/tronixstuff/) Follow

p-700.html)
Download
Favorite
w I Made It

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 as shown above.

 Add Tip V Ask Question | Comment Download

Step 3: Your First Arduino Sketch


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

// --------------------------------------------------------

#include <SoftwareSerial.h>

SoftwareSerial RFID(2, 3); // RX and TX

int i;

void setup()

RFID.begin(9600); // start serial to RFID reader

Serial.begin(9600); // start serial to PC

void loop()

if (RFID.available() > 0)

i = RFID.read();

Serial.print(i, DEC);

Serial.print(" ");

// --------------------------------------------------------

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
Arduino waving
Tutorials RFIDbycards
– RFID or tags
tronixstuff over the coil. You
(/member/tronixstuff/) Follow
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 videow
Download
Favorite
I Made It

(http://www.youtube.com/watch?v=Ed9z6y5qzVc) 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.

 Add Tip V Ask Question | Comment Download

Step 4: Reading and Recognising RFID Cards


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 sketche, but add a typical green and red LED with 560 ohm resistor to digital pins 13
and 12 respectively. Then upload the following sketch:

//-------------------------------------------------------------------------------------------------------------

#include <SoftwareSerial.h>

SoftwareSerial RFID(2, 3); // RX and TX

int data1 = 0;

int ok = -1;

int yes = 13;

int no = 12;

// use first sketch in http://wp.me/p3LK05-3Gk (http://wp.me/p3LK05-3Gk) to get your tag


numbers

int tag1[14] = {2,52,48,48,48,56,54,66,49,52,70,51,56,3};

int tag2[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};

int newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // used for read comparisons

void setup()

{
Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

RFID.begin(9600); // start serial to RFID reader

Serial.begin(9600); // start serial to PC

Download
Favorite
w I Made It

pinMode(yes, OUTPUT); // for status LEDs

pinMode(no, OUTPUT);

boolean comparetag(int aa[14], int bb[14])

boolean ff = false;

int fg = 0;

for (int cc = 0 ; cc < 14 ; cc++)

if (aa[cc] == bb[cc])

fg++;

if (fg == 14)

ff = true;

return ff;

void checkmytags() // compares each tag against the tag just read

ok = 0; // this variable helps decision-making,

// if it is 1 we have a match, zero is a read but no match,

// -1 is no read attempt made

if (comparetag(newtag, tag1) == true)

ok++;

if (comparetag(newtag, tag2) == true)

ok++;

void readTags()

{
Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

ok = -1;

if (RFID.available() > 0)

Download
Favorite
w I Made It

// read tag numbers

delay(100); // needed to allow time for the data to come in from the serial buffer.

for (int z = 0 ; z < 14 ; z++) // read the rest of the tag

data1 = RFID.read();

newtag[z] = data1;

RFID.flush(); // stops multiple reads

// do the tags match up?

checkmytags();

// now do something based on tag type

if (ok > 0) // if we had a match

Serial.println("Accepted");

digitalWrite(yes, HIGH);

delay(1000);

digitalWrite(yes, LOW);

ok = -1;

else if (ok == 0) // if we didn't have a match

Serial.println("Rejected");

digitalWrite(no, HIGH);

delay(1000);

digitalWrite(no, LOW);

ok = -1;

void loop()

readTags();

// ------------------------------------------------------------------------------------


Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

In the sketch we have a few functions that take care of reading and comparing RFID tags. Notice
w add your own
Download

that the allowed tag numbers are listed at the top of the sketch, you can always
Favorite
I Made It

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
(http://www.youtube.com/watch?v=IDHqRpyWOFM).

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
(http://www.freetronics.com/collections/modules/products/n-mosfet-driver-output-module))
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
(http://nostarch.com/arduino)” from No Starch Press.

 Add Tip V Ask Question | Comment Download

2 People Made This Project!


Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

Download
Favorite
w I Made It

ta8aym (/member/ta8aym/) made it! AntonisK15 (/member/AntonisK15/) made it!

Did you make this project? Share it with us!

I Made It!

Recommendations

(/How-to-Build-8x8x8-LED-Cube/) (/Webcam-Privacy-Friend/)

How to Build 8x8x8 LED Cube (/How-to- Webcam Privacy Friend (/Webcam-
Build-8x8x8-LED-Cube/)
by SmartTronix Privacy-Friend/)
by bekathwia
(/member/SmartTronix/)
in Arduino (/member/bekathwia/)
in Electronics

w
1

29
8
3.2K 
43
8
6.7K

(/contest/arduino2021/) (/contest/box/)

Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Add Tip
Follow

w I Made It
V Download

Ask Question
Favorite


| Post Comment

We have a be nice policy.


Please be positive and constructive.

Add Images Post

17 Comments

(/member/Geyst/) Geyst (/member/Geyst/) 2 years ago Reply / Upvote


Is there a 128khz version?

NguyễnH216
(/member/Nguy%25E1%25BB%2585nH216/)
(/member/Nguy%25E1%25BB%2585nH216/) 3 years ago

Reply / Upvote
I am using NodeMCU instead of Arduino. But RFID.Available() return 0 value! Please help me this
problem!

(/member/FaizanH6/) FaizanH6 (/member/FaizanH6/) 3 years ago


on Step 4
Reply / Upvote
I did everything same as done in this tutorial but nothing is happening. Wondering where I am making
mistakes??? please help me i want to make a RFID parking system using arduino.

faizan6603@gmail.com (mailto:faizan6603@gmail.com)

(/member/JMB1971/) JMB1971 (/member/JMB1971/) 3 years ago


Reply / Upvote
Nice Turorial. I have built something along these lines however, I would love to see someone do an RFID
project where the tag data is NOT in the source code but saved in a file on the SD card. I was hoping to be
the first(ish) but alas, my programming skills not up to job yet. No one else is doing this though. Could you
be the first? Do you know anyone who made an RFID project such as this?

(/member/adillbeck/) adillbeck (/member/adillbeck/) 4 years ago


Reply / Upvote
RFID.flush() doesn't appear to be working right?
I swipe the card and it shows Accepted and blinks 5-6 times...
Otherwise it seems to be working very nice.
Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

(/member/Vedant+Naik/) Vedant Naik (/member/Vedant+Naik/) 4 years ago


Reply / Upvote

Download
Favorite
w I Made It

can you tell how to add a tag and how in detail


1
reply
F

(/member/PedroC101/) PedroC101 (/member/PedroC101/) 5 years ago


Reply / Upvote
hello, how can i add more tags?
what i need to change? thanks
1
reply
F

(/member/ShrutiR5/) ShrutiR5 (/member/ShrutiR5/) 5 years ago


Reply / Upvote
I NEED A RFID TO UNLOCK MY HEXPAD WHEN THE USER WIPES ONCE HOW AM I SUPPOSE TO
DO
1
reply
F

(/member/ZairilH/) ZairilH (/member/ZairilH/) 5 years ago


Reply / Upvote
Is this correct? why i got all 255?

(https://content.instructables.com/ORIG/F98/FSMY/IMC92DI4/F98FSMYIMC92DI4.png?
auto=webp&fit=bounds&frame=1)

(/member/Ryan_Hanlon/) Ryan_Hanlon (/member/Ryan_Hanlon/) 5 years ago Reply / Upvote


My classmates and I were assigned a project using RFID to create an attendance system for our school.
We are using Arduino UNO and the RDM6300. We need to first be able to read 6 tags. We are confused
as to how we do this seeing that your code uses boolean and we need more than just a true of false. If
anyone could please assist us it would be much appreciated.
Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow
(/member/bitterbug/) bitterbug (/member/bitterbug/) 6 years ago
on Introduction Reply / Upvote
Download
Favorite
w I Made It

Awesome :) I've just ordered the RDM6300 and some tags from Hobby Components. Is there a way to get
the reader to adjust for 128 and 134.2 kHz chips as well? I want to be able to read all 3 frequencies of pet
RFID chips.

(/member/georgemakarona/) georgemakarona (/member/georgemakarona/) 6 years ago


on Step 3

Reply / Upvote
How far the RFID reader can measure RFID tag ?

(/member/leofoam/) leofoam (/member/leofoam/) 6 years ago


Reply / Upvote
Thanks for putting this out there. I'm hoping to use RFID tags in a project of mine using Bluetooth. I am
already using software serial ports for my Bluetooth modules and am wondering if I can use the RFID tags
on the hardware serial ports at the same time as the Bluetooth. Any help you can give me would be
appreciated! Thanks in advance.

(/member/davidandora/) davidandora (/member/davidandora/) 7 years ago


on Introduction

Reply / Upvote
Great Instructable! Excuse my ignorance, but can you also program a reader to recognize or accept other
items you may already have with an RFID chip? I'm not sure what other components might be in place to
prevent that from functioning. For example, Disney has RFID chip embedded bracelets which are used for
a variety of things around the park. Does it seem likely or unlikely that one could use other RFID
embedded items to function with an Arduino RFID setup? I've not been able to discern whether or not this
is generally possible.

Post Comment

Categories About Us Resources


 Circuits  Living Who We Are Sitemap (/sitemap/)
(/circuits/) (/living/) (/about/) Help (/how-to-write-a-
 Workshop  Outside Why Publish? great-instructable/)
(/workshop/) (/outside/) (/create/) Contact (/contact/)
 Craft  Teachers Jobs (/jobs/)
(/craft/) (/teachers/)
 Cooking
(/cooking/)
Find Us
Arduino Tutorials – RFID by tronixstuff (/member/tronixstuff/) Follow

nstagram.com/instructables/) (https://www.pinterest.com/instructables) (https://www.facebook.com/instructables) (https://www.twitter.com/ins


Download
Favorite
w I Made It

© 2021 Autodesk, Inc. Terms of Service (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21959721)


Privacy Statement (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=21292079)
Privacy settings
Legal Notices & Trademarks (http://usa.autodesk.com/legal-notices-trademarks/)
(http://www.autodesk.com)

You might also like