RFID and Arduino (1)

In this tutorial, divided in two posts, I’ll show you how to use RFID (Radio-frequency Identification) tags with Arduino.

In the first part you’ll learn how to connect the reader to your Arduino and how to write a simple sketch to display the tag’s ID, while in the second part you’ll learn how to build a complete access control system based on RFID tags.

PN532

I chose as RFID reader a board based on the PN532 chip by NXP. This is a very versatile chip: it can work as a tag reader/writer but it can also act as a RFID tag; moreover it supports both I2C and SPI communication buses.

Adafruit created a breakout board for the PN532 chip and the Arduino libraries we’re going to use. Alternatively you can find on several webstores the following board, that I’m also going to use for this tutorial:

rfid-03 rfid-04

Connections

As I wrote before, the PN532 chip supports both I2C and SPI. For simplicity, I’ll use the first one, connecting the SDA and SCL pins of the board to the corresponding pins of Arduino. You have also to connect the IRQ pin to a digital pin of your Arduino (I chose pin 2); thanks to this connection the PN532 pin “warns” Arduino if a new tag is being read:

rfid-06 rfid-07

To select the I2C bus, you have to set the board’s dip switches as explained on the silk screen:

rfid-05

Finally, power the board connecting the VCC and GND pins to pins 5V and GND of Arduino.

For this project, I used the beta version of a new LCD shield by Lemontech. The main feature of this shield is that the LCD is connected to Arduino via an I2C expander; moreover all the buttons are connected to only one pin, the analog pin A0. This means that almost all the Arduino pins are still available for connecing other devices. The display’s default address – but you can change it – is 0x27 while the PN532 chip has address 0x24 so there’s no conflict.

rfid-10 rfid-11jpg

Having two devices connected to the I2C bus, I had to add two 10Kohm pull-up resistors for SCL and SDA as explained in the following schematics:

rfid-13

To keep things simple, I place them on a small breadboard:

rfid-08

I also added a small speaker (connected to pin 8 and GND) to play a sound everytime Arduino reads a tag:

rfid-09

Libraries

To be able to compile the sketch of this tutorial you have to install the following libraries in your IDE:

  • Adafruit PN532 di Adafruit
  • hd44780 di Bill Perry

Both the libraries are available in the Library Manager:

rfid-01

Sketch

The complete sketch is available in my Github repository.

To use the LCD, first you have to define its size (rows and columns), the address on the I2C bus and the pins it’s connected to. You can then initialize the library in the setup():

#define LCD_COLS      16
#define LCD_ROWS      2
hd44780_I2Cexp lcd(0x27, I2Cexp_PCF8574, 0,1,2,4,5,6,7,3,HIGH);
[...]
if(lcd.begin(LCD_COLS, LCD_ROWS) != 0) {
  Serial.println("- Unable to initialize LCD!");
  while(1);
}

The same for the PN532 chip: you have to declare the pin connected to the IRQ signal (RESET is optional) and then initialize it. Using the getFirmwareVersion method you can get the chip version and therefore verify that it’s working correctly:

#define PN532_IRQ     2
#define PN532_RESET   3
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
[...]
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if(!versiondata) {
  Serial.println("- Unable to find a PN532 board");
  while(1);
}
Serial.print("- found chip PN5"); 
Serial.println((versiondata>>24) & 0xFF, HEX);

Lastly, call the SAMConfig() method to configure the chip in normal mode and to enable the IRQ pin:

rfid-02

It’s very easy to read a tag. The readPassiveTargetID method returns true if a tag is near the reader:

success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {

In this case, you can play a sound and display the tag’s ID on the display:

tone(SPEAKER_PIN, TONE_FREQ, TONE_TIME);
lcd.clear();
lcd.print("Found RFID tag!");
lcd.setCursor(1,2);
lcd.print("ID: 0x");
for(int i = 0; i < uidLength; i++) {
  if(uid[i] <= 0xF) lcd.print("0");
  lcd.print(uid[i] & 0xFF, HEX);    
}

Demo

App note: Transponder coils in an RFID system

Doc397_TranspondersinRFID

A short application note from Coilcraft about transponder coils. Link here (PDF)

Radio Frequency Identification (RFID) is the system of using radio signals to send information identifying a particular situation or item. It can be used to track and locate any item including material, people and animals.

The RFID transponder coil is part of the coupling device and acts as the transmitting antenna. The key specifications of the transponder coil are sensitivity and read distance, however, the inductance of the transponder coil directly influences the sensitivity and the read distance. Generally, a higher inductance provides greater sensitivity resulting in a longer read distance. The manufacturer of the tag usually specifies the inductance of the coil to be used. The read distance is defined as the maximum distance from the reader that the transponder responds to the reader’s magnetic field.

Faulty Parking Meter Tracking System? RFID To The Rescue!

How often do you see problems that need fixing? How often do you design your own solutions to them — even if they won’t be implemented at scale? Seeing that many of the municipal parking lots in his native Sri Lanka use a paper ticketing system which is prone to failure, [Shazin Sadakath] whipped up his own solution: an efficient RFID tag logging system.

Digging out an HZ-1050 RFID reader — as well an RFID card and two tags — [Sadakath] set to work connecting it to his Raspberry Pi and cooking up a batch of code and a dashboard to work with. A Python script — using a PiGPIO library — reads the Wiegand Format RFID number, storing it in an SQLite3 database. A Bootstrap, Javascript, and JQuery trifecta make up the dashboard that pulls the RFID info from said server and organizes it into a functional format.

An RFID keyed system like this might be difficult to realize for even a small portion of the parking lots, but it’s a potential solution nonetheless. RFID entry systems can certainly be a functional solution in an office-scale environment for those with similar initiative.


Filed under: hardware, Raspberry Pi, transportation hacks

Inside a RFID race timing chip: die photos of the Monza R6

monza6-die-600

Ken Shirriff took some die photos of the Monza R6 chip  and wrote a post on his blog on how the RFID timing chip works:

I recently watched a cross-country running race that used a digital timing system, so I investigated how the RFID timing chip works. Each runner wears a race bib like the one below. The bib has two RFID tags, consisting of a metal foil antenna connected to a tiny RFID (radio-frequency identification) chip. At the finish line, runners pass over a pad that reads the chip and records the finish time. (I’m not sure why there are two RFID tags on each bib; perhaps for reliability of detection.)
The die photo below shows the RFID chip used on these tags. To create it, I took 22 photos of the chip with my metallurgical microscope and stitched them together to create a high resolution photo. (Click the image for a larger version.) To prepare the chip, I removed it from the plastic carrier with Goof Off, dissolved the antenna with pool acid (HCl), and burnt off the mounting adhesive over a stove. This process left the chip visible with just a bit of debris that wouldn’t come off. I’d probably get better results with boiling sulfuric acid, but that’s too hazardous for me. I described the image stitching process in this article.

More details at Ken Shirriff’s blog.

Tutorial: RFID tags with the NXP NFC controller PN7120 and Eclipse

pics-nfc-pn7120s-board

Erich Styger writes:

Playing with RFID and NFC is definitely fun🙂, and they are everywhere! For a research project I’m exploring different RFID tags and solutions. I several types around for a long time, but never found the time to actually work on it, so last nightI thought I give it a try, and I have it working with GNU ARM and Eclipse, powered by the NXP FRDM-K64F board🙂

More details at MCU on Eclipse site.

Simple RFID Door Lock System

Group entry hacks are a favorite for hacker social groups. Why use old fashioned keys when you can use newfangled electronic keys? If you are looking to build a simple RFID-based security system to secure your important stuff, this project from Resin.io is a good place to start. In it, [Joe Roberts] outlines the process of building a simple RFID-triggered mechanism for their office door.

It’s a pretty simple setup that is composed of an RFID reader, a Rasperry Pi and a Neopixel ring. When someone places an RFID card against the reader hidden behind a poster by their front door, the reader grabs the code and the Pi compares it with a list of authorized users. If the card is on the list, the Pi triggers the door lock using a signal line originally designed to work with an intercom system. If the user isn’t on the list, a laser is triggered that vaporizes the interloper… well, that’s perhaps in the next version, along with an API that will allow someone to open the door from the company chat application.

At the moment, this is a clean, simple build that uses only a few cheap components, but which could be the basis for a more sophisticated security system in the future.


Filed under: security hacks

Contactless transit card teardown

pic-compass-0001-600

A RFID transit pass teardown from Electronupdate:

Here is the die photo: super tiny. I bet they get thousands of dice off of each wafer. Looks like it’s a protocol called MIFARE. Vendor of the chips is NXP. I think it’s their ultra light family
The amazing bit is that a card is printed with conductive ink, a semiconductor added (with a transistor count in the tens of thousands), a vendor-specific ID placed on the outside with another layer of paper, spooled in to giant rolls, vended for a single trip and then thrown away…..

More details at Electronupdate blog.

Check out the video after the break. 

Arduino RFID login

20160316_114913-600

Luke has published a new build:

I wanted a simple way of quickly logging on to my computer without having to typing my password in and did not want to have no security either.
There are various products on the market that would solve this problem from fingerprint readers to proximity dongles but i decided to see what i could knock up with parts i mainly already had.

Looking in my micro stuff i had a RC522 RFID tag reader 3.3v :
Also an 3.3v arduino Leonardo clone aswell based on a sparkfun pro micro which also can act as a USB device such as a keyboard. This is useful as if a 5v arduino was used a level shifter would be required due to the RC522 not being 5v torrent.

More info at Luke’s project page.

NFC tags and Android smartphones

I recently brought from Banggood 3 NFC tags, for about 4 euros. Tags are adhesive and round shaped; the package also contains three colored stickers labeled please touch it to cover the tags:

nfc-01

A NFC (Near Field Communication) tag is a passive device (it does not contain batteries or any other power sources) that, when located near to a reader, establishes with it a peer-to-peer communication to change data. A tag contains some read only fields (for example the serial number) and also normally offers some memory locations where the reader can store custom data (read and write).

If your Android smartphone features an NFC reader, you can – thanks to dedicated apps – read and write NFC tags. In this tutorial I’ll show you how it’s possible to configure the smartphone to automatically execute tasks when it scans an NFC tag.

First, install from the Google Play store the free applications NFC Tools e NFC Tasks:

nfc-00

Run NFC Tools (sorry if the screenshots below are in italian!):

rfid-1

Put the tag next to the phone; you’ll hear a beep and NFC Tools will display tag’s information:

rfid-2

Choose the TASKS tab and click on Add actions:

rfid-3

In this example, I’m going to configure my smartphone to run the Waze navigator when I put it near the tag. You can of course configure different actions: the list of the actions supported by the app is very impressive!

Choose Application – Launch app and select the app you want to be launched:

rfid-4

Click on Write and put the tag near the phone:

rfid-5

Wait for the confirmation:

rfid-6

If I glue the tag on my smartphone car mount, I can now automatically launch the navigator app when I put the phone in it: