Skip to main content

How to use The RFID/NFC Card Reader Kit

The NFC controller is based on a collection of microcontrollers that allow for contactless communication of around 13.56 MHz. The batteryless and powerless NFC tags and cards send radio waves that activate the antenna of the receiving device. This device only works around a short distance of around 4 inches.

How it works

The RFID sends radio waves to the active tags, which then send radio waves back to the antenna of the RFID, where the data from the NFC tags and cards are received.

Wiring

  • GND pin to ground
  • VCC pin to 5V
  • SDA pin to 10
  • SCL pin to 11

Parts

Wiring Guide

  • Use the provided 4 pin, right angled male header, and solder it to the GND, VCC, SDA and SCL pins
  • Now connect each pin to its appropriate locations on the Arduino board (check our wiring)
  • Connect the positive led of the LED to the resistor, and then the resistor to pin 13 on the Arduino and connect the negative led pin to ground
  • Follow the provided code and watch the LED light up when it detects a card!!

Programming

The following code demonstrates how read the RFID and NFC cards or keys and receive the ID number.

Step 1: Include the libraries needed for this program. You can down load the zip files from onlien and add the zip files to the library under Sketech and then under Include Library.

#include <SoftwareSerial.h>
#include <PN532_SWHSU.h>
#include <PN532.h>

Step 2: Create objects for SoftwareSerial, PN532_SWHSU and PN532.

SoftwareSerial SWSerial( 10, 11 ); // RX, TX
PN532_SWHSU pn532swhsu( SWSerial );
PN532 nfc( pn532swhsu );

Step 3: Set the following varibales to store data and to store the pin number of the LED.

int ledPin = 13; 


void setup(void) {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();

Step 4: Creating an if statement to reconize whether any data was found from the scan, and whether any scan was recieved.

if (! versiondata) {
Serial.print("Didn't Find PN53x Module");
while (1); // Halt
}

// Got valid data, print it out!
// Configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}

Step 5: Next, we will create an array to store the card or key ID from the scan. We will also store the length of the ID if the scane was successful.

void loop(void) {

boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

Step 6: Then, when we are sure that the scan was successful, we will load the array up with the digits of the ID.

if (success) {
Serial.println("Found A Card!");
digitalWrite(ledPin, HIGH);
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");

Step 7: Finally, we can print out the ID from the scaned card or key.

    for (uint8_t i=0; i < uidLength; i++) {
Serial.print(" ");Serial.print(uid[i], DEC);
}
Serial.println("");
// 2 second halt
delay(1000);
digitalWrite(ledPin, LOW);
}
}

Full Code

#include <SoftwareSerial.h>
#include <PN532_SWHSU.h>
#include <PN532.h>
SoftwareSerial SWSerial( 10, 11 ); // RX, TX
PN532_SWHSU pn532swhsu( SWSerial );
PN532 nfc( pn532swhsu );

int ledPin = 13;


void setup(void) {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't Find PN53x Module");
while (1); // Halt
}

// Got valid data, print it out!
// Configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}

void loop(void) {

boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

if (success) {
Serial.println("Found A Card!");
digitalWrite(ledPin, HIGH);
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");

for (uint8_t i=0; i < uidLength; i++) {
Serial.print(" ");Serial.print(uid[i], DEC);
}

Serial.println("");
// 2 second halt
delay(1000);
digitalWrite(ledPin, LOW);
}


}

Output

Serial Monitor will display the ID number that is received from the Card or key that was scaned.