Archive | rfid

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.

Posted in arduino, lesson, rfid, RFR101A1M, RFR103B2B, seeedstudio, tronixstuff, tutorial41 Comments

Arduino tutorial 15a – RFID with Innovations ID-20

Learn how to use RFID readers with your Arduino. In this instalment we use the Innovations ID-20 RFID reader. The ID-12 and ID-2 are also compatible. If you have the RDM630 or RDM6300 RFID reader, we have a different tutorial.

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.

Updated 26/02/2013

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. In this tutorial we’ll run through the basics of using the ID-20 module then demonstrate a project you can build and expand upon yourself.

Introduction

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:

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. And out reader is the Innovations ID-20 RFID reader:

Unlike the RDM630 reader in the other RFID tutorial – the ID-20 is a complete unit with an internal aerial and has much larger reader range of around 160 mm. It’s a 5V device and draws around 65 mA of current. If you have an ID-12 it’s the same except the reader range is around 120mm; and the ID-2 doesn’t have an internal aerial. Connecting your ID-20 reader to the Arduino board may present a small challenge and require a bit of forward planning. The pins on the back of the reader are spaced closer together than expected:

… so a breakout board makes life easier:

… and for demonstration and prototyping purposes, we’ve soldered on the breakout board with some header pins:

 The first thing we’ll do is connect the ID-20 and demonstrate reading RFID tags. First, wire up the hardware as shown below:

If you’re using the breakout board shown earlier, pin 7 matches “+/-” in the diagram above. Next, enter and upload the following sketch (download):

Note that we’re using a software serial port for our examples. In doing so it leaves the Arduino’s serial lines for uploading sketches and the serial monitor. Now open the serial monitor window, check the speed is set to 9600 bps and wave some tags over the reader – the output will be displayed as below (but with different tag numbers!):

Each tag’s number starts with a byte we don’t need, then twelve that we do, then three we don’t. The last three aren’t printable in the serial monitor. However you do want the twelve characters that appear in the serial monitor.  While running this sketch, experiment with the tags and the reader… get an idea for how far away you can read the tags. Did you notice the tag is only read once – even if you leave it near the reader? The ID-20 has more “intelligence” than the RDM630 we used previously. Furthermore when a tag is read, the ID-20 sends a short PWM signal from pin 10 which is  just under 5V and lasts for around 230 ms, for example:

id20pulse

 This signal can drive a piezo buzzer or an LED (with suitable resistor). Adding a buzzer or LED would give a good notification to the user that a card has been read. While you’re reading tags for fun, make a note of the tag numbers for your tags – you’ll need them for the next examples.

RFID Access System

Now that we can read the cards, let’s create a simple control system. It will read a tag, and if it’s in the list of allowed tags the system will do something (light a green LED for a moment). Plus we have another LED which stays on unless an allowed tag is read.  Wire up the hardware as shown below (LED1 is red, LED2 is green – click image to enlarge):

Now enter and upload the following sketch:

In the function readCard() the sketch reads the tag data from the ID-20, and stores it in an array testtag[]. The index is -1 so the first unwanted tag number isn’t stored in the array. Once thirteen numbers have come through (the one we don’t want plus the twelve we do want) the numbers are smooshed together into a string variable testcard with the function String. Now the testcard string (the tag just read) can be compared against the three pre-stored tags (Sinclair, Smythe and Stephen).

Then it’s simple if… then… else to to see if we have a match, and if so – call the function approved() or disApproved as the case may be. In those two functions you store the actions you want to occur when the correct card is read (for example, control a door strike or let a cookie jar open) or when the system is waiting for another card/a match can’t be found. If you’re curious to see it work, check the following video where we take it for a test run and also show the distances that you have to work with:

Hopefully this short tutorial was of interest. We haven’t explored every minute detail of the reader – but you now have the framework to move forward with your own projects.

LEDborder

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, 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.

Posted in arduino, id12, id20, innovations, lesson, PRT-00553, rfid, RFR103B2B, SEN-08419, SEN-08423, SEN-08628, tutorial, wireless19 Comments

Project – Simple RFID access system

In this tutorial you can make an RFID access system. It’s very simple and can be used with a wide variety of end-uses.

Updated 18/03/2013

The purpose of this project is to prototype a basic RFID access system. Although it is not that complicated, this article is my response to a kit reviewed in the Australian “Silicon Chip” (November 2010) electronics magazine. Their article describes the kit in detail – operation, schematic, use and installation. However the code for the microcontroller (PIC16F628A)  is not published due to the kit manufacturer holding copyright over the design.

This is a shame, as many organisations have been quite successful selling open-source kits. So instead of moaning about it, I have created my own design that matches the operation of the original, instead using the ATmega328 MCU with Arduino bootloader. Consider this a basic framework that you can modify for your own access system, or the start of something more involved.

articless

There are pros and cons with the original vs. my version. The biggest pro is that you can buy the whole kit for around Au$40 including a nice PCB, solder it together, and it works. However if you want to do it yourself, you can modify it to no end, and have some fun learning and experimenting along the way. So let’s go!

The feature requirements are few. The system must be able to learn and remember up to eight RFID access tags/cards, etc – which must be able to be altered by a non-technical user. Upon reading a card, the system will activate a relay for a period of time (say 1 second) to allow operation of a door strike or electric lock. Finally, the RFID tag serial numbers are to be stored in an EEPROM in case of a power outage. When a tag is read, a matching LED (1~8) will show which tag was read. There are also two LEDs, called “Go” and “Stop” which show the activation status. The original kit has some more LEDs, which I have made superfluous by blinking existing LEDs.

This is a simple thing to make, and the transition from a solderless breadboard to strip board will be easy for those who decide to make a permanent example. But for now, you can follow with the prototype. First is the parts list:

  • Atmel ATmega328 with Arduino bootloader;
  • 16 MHz resonator (X1 in schematic);
  • ten LEDs of your choice;
  • two normally-open push buttons;
  • two 560 ohm resistors (all resistors 1/4 watt);
  • one 1k ohm resistor;
  • three 10k ohm resistors;
  • one BC548 transistor;
  • three 0.01 uF monolithic capacitors;
  • one 100 uF electrolytic capacitor;
  • one 1N4004 diode;
  • Microchip 24LC256 EEPROM;
  • 125 kHZ RFID module;
  • 125 kHz RFID tags/cards;
  • connecting wire;
  • large solderless breadboard;
  • LM7805 power regulator;
  • relay of your choice with 5V coil (example).

When selecting a relay, make sure it can handle the required load current and voltage – and that the coil current is less than 100mA.

If attempting to switch mains voltage/current – contact a licensed electrician. Your life is worth more than the money saved by not consulting an expert.

And here is the schematic (large version):

simplerfidschematic

Here is the prototype on the solderless breadboard. For demonstration purposes an LED has been substituted for the transistor/relay section of the circuit, the power regulator circuitry has not been shown, and there are superfluous 4.7k resistors on the I2C bus. To program the software (Arduino sketch) the easiest way is by inserting the target IC into an Arduino-compatible board, or via a 5V FTDI cable and a basic circuit as described here.

rfidbboardss

The Arduino sketch is also quite simple. The main loop calls the procedure readTags() to process any RFID tag read attempts, and then monitors button A – if pressed, the function learnTags() is called to allow memorisation of new RFID tags. Each tag serial number consists of 14 decimal numbers, and these are stored in the EEPROM sequentially. That is, the first tag’s serial number occupies memory positions 0~13, the second tag’s serial number occupies memory position 14~28, and so on. Two functions are used to read and write tag serial numbers to the EEPROM – readEEPROMtag() and writeEEPROMtag().

The EEPROM is controlled via the I2C bus. For a tutorial about Arduino, I2C bus and the EEPROM please read this article. For a tutorial about Arduino and RFID, please read this article. The rest of the sketch is pretty self-explanatory. Just follow it along and you can see how it works. You can download the sketch from hereAnd finally, a quick video demonstration:

So there you have it. I hope you enjoyed reading about this small project and perhaps gained some use for it of your own or sparked some other ideas in your imagination that you can turn into reality.

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.

Posted in hardware hacking, learning electronics, microcontrollers, projects, RDM630, RDM6300, rfid12 Comments

Project – The “Kid-e-log”

With this project you can build an RFID time-clock system to keep track of employees, children and more.

Updated 18/03/2013

Recently I was listening to a friend who has three teenage children, of whom needed to arrive home before their parent. Unfortunately the parent needs to work all day and arrives home in the evening, and they lamented not being able to check when the children had arrived home.

After a few hours it occurred to me that a simple time clock would solve her problem – each child could check-in upon arriving home, and the parent could review the check-in times later on. And thus the kid-e-log was born.

From a hardware perspective, it would be quite simple. An LCD screen, RFID reader and some tags, and a real time clock IC such as a Maxim DS1307 – all running from the ubiquitous Arduino board. After some contemplation it occurred to me that smart kids might try to mess up the hardware by pulling the power, so it also uses an EEPROM to store time data which is impervious to power loss, and the kid-e-log will not have any user buttons. After initial programming for time and RFID key data, any changes will need to be effected by the programmer (i.e. me).

If RFID is new to you, review my Arduino tutorials before moving forward.

Before jumping ahead and making something, we discussed exactly what the function would be. Each child would have an RFID tag, and when it is read the hardware will save the arrival time in memory, and display it on the LCD. The time data will be reset automatically at 0400h or by reading an RFID card belonging to the parent. There will not be any buttons, and the hardware must be power-failure resistant – therefore EEPROM memory is needed for time data and a backup battery for the real-time clock.

From a hardware perspective, the requirements are quite simple:

  • An Arduino-style board of some sort (we used the Freetronics Eleven)
  • Maxim DS1307 or DS3232 real-time clock IC
  • Microchip 24LC256 EEPROM
  • Usual 16 character, 2 line LCD with HD44780-compatible interface
  • 125kHz RFID reader with serial output, and four RFID tags (don’t get the Weigand version!)
  • Two 4.7 kilo ohm resistors (for I2C bus with EEPROM)
  • Two 0.1 uF ceramic capacitors (for power smoothing on the breadboard)
  • a solderless breadboard for prototyping
  • a nine volt DC power adaptor, rated for no less than 300 milliamps
  • And for the final product, a nice enclosure. More on that later…

The DS1307 and the EEPROM are both using the I2C bus, and the RFID reader (more information) uses Arduino digital pin zero (serial input).  The LCD is pretty straight forward as well, as described in the tutorials.

Here is the schematic for the prototype hardware:

schematicss

From a software (sketch) perspective, the design is easily broken up into distinct functions which makes programming quite easy. The sketch is a basic loop, which follows as such:

  • check to see if a tag is read by the RFID reader – if so, branch to the the reading function (which compares the read tag against those on file, and records the time matching the tag to the EEPROM)
  • display real time, date and check-in data on the LCD – another function
  • delay for a moment to stop the LCD flickering from fast updating
  • check if the time is 4am, and if so call a function to reset the check-in times

From each of those four main instructions, functions are called to handle various tasks. For example the displayData() funtion is used to read the DS1307 real time clock, and display the time and date on the top line of the LCD. Then it reads the contents of the EEPROM, and displays the check in time for each RFID tag – or a line if they have not checked in yet.

The data stored in the EEPROM is held in following order

  • tag 1 status (0 for not checked in, 1 for checked in)
  • tag 1 check-in hour
  • tag 1 check-in minute

and repeats for tag two and three. You will notice in the sketch that the RFID cards’ serial data are stored in individual arrays. You will need to read your RFID cards first with another sketch in order to learn their values. The rest of the sketch should be quite easy to follow, however if you have any questions please ask.

You can download the sketch from here. Next for the hardware. Here is our prototype, ready for action:

prototypess

And now for a short video clip of the prototype kid-e-log in operation:


Notice how removing the power does not affect the real time nor the stored check-in data. Almost child-proof. The final task was to reassemble the prototype in order to fit into a nice enclosure. Unfortunately by this stage the person concerned had moved away, so I had no need to finish this project. However I had already purchased this nice enclosure:

enclosuress

It was just large enough to accept the Eleven board, and protoshield with the EEPROM and RFID reader circuitry, and the LCD module. It is custom-designed with mounts for Arduino boards and the LCD – a perfect fit. However the use of it can wait for another day. So an important note to self – even if designing things for a friend – get a deposit!

Such is life. I hope you enjoyed reading about this small project and perhaps gained some use for it of your own or sparked some other ideas in your imagination that you can turn into reality.

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.

Posted in arduino, I2C, projects, rfid, time clock, tronixstuff, tutorial3 Comments

Moving Forward with Arduino – Chapter 15 – RFID Introduction

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.

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.

Updated 21/02/2013

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

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:

readerss

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.

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.

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:

 

exam15p1ss

Note that all the GND pins are connected together. Now upload the following sketch:

You may need to remove the wire from the RFID reader to Arduino 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).

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:

example15p2schematicss

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.

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

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

ds1307shield2

Now here is a short video clip, with the addition of the ‘boss mode’ shutdown sequence:

And finally, here is an example of the text file that was produced from a recent test run:

example15p3datalog

As you can see, it is easy to reproduce expensive time-keeping systems with our own equipment and some time. We have some RFID projects in … the project section.

LEDborder

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, 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.

Posted in 125 kHz, arduino, ELB149C5M, lesson, microcontrollers, RDM630, RDM6300, rfid, RFR101A1M, RFR103B2B, sensor, tronixstuff, tutorial8 Comments


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: