BLE Shield Project: RFID Tag Reader

After creating the BLE Shield for Arduino it is time to create some projects with it to show you what can be done using the shield.

Now it is time to create a simple RFID Tag Reader using the BLE Shield. In order to stack such a device together, I grabbed the following out of my “Arduino Box”:

  • 1 x Arduino Pro Mini 3.3V
  • 1 x Adafruit PN532 NFC/RFID Controller Shield for Arduino
  • 1 x Seeddstudio Solar Charger Shield v0.9b
  • 1 x BLE Shield 0.9.2

In this setup I ‘m using hardware serial to send data to the BLE Shield, so the switch needs to be set to the Tx0/Rx1 position. I programmed the Arduino Pro mini with the following sketch, where the 16 byte buffer is filled with padding zeros and then with the UID of the tag.

#include
#include 

#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

void setup(void) {
  Serial.begin(19200);

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (!versiondata) {
    while (1); // halt
  }

  // configure board to read RFID tags
  nfc.SAMConfig();
}

void loop(void) {
  boolean success;
  // Buffer to store the returned UID
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };
  // Buffer for writing the padding
  uint8_t pad[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  uint8_t uidLength;
  uint8_t bleBufferLength = 16;
  uint8_t paddingSize = 0;

  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

  if (success) {
    paddingSize = bleBufferLength - uidLength * 2;
    // add padding depending of the size of the TAG UID
    for (uint8_t i=0; i < paddingSize; i++)  {
      Serial.print(pad[i], HEX);
    }

    // write the UID of the tag.
    for (uint8_t i=0; i < uidLength; i++)  {
      Serial.print(uid[i], HEX);
    }

    // Wait 1 second before continuing
    delay(1000);
  }
}

You can use BLExplr to test the reader. Just connect to the BLE Shield, enable notify on the RX characteristic and place an RFID Tagreader near the antenna.

The following video shows this connection and tagging procedure: