NFC security sketch

I have a project much like the many door locking projects around the web…however I want to create a database on SD card and have the arduino read and compare the number with that database. and edit that number with a character that disables the number form the database without deleting it.

The following project would fit my needs however I would have to enter the number in the sketch instead of the SD. therefore making a limitation to the number of entries.

I found the Babel Fish project from Adafruit to be a close parallel to my project. here is that code as given by that programmer:

#include <WaveHC.h>
#include <WaveUtil.h>
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>

#define IRQ 6 // this trace must be cut and rewired!
#define RESET 8

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

SdReader card; // This object holds the information for the card
FatVolume vol; // This holds the information for the partition on the card
FatReader root; // This holds the information for the volumes root directory
FatReader file; // This object represent the WAV file for a pi digit or period
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time

  • Define macro to put error messages in flash memory
    #define error(msg) error_P(PSTR(msg))

//////////////////////////////////// SETUP

void setup() {
// set up Serial library at 9600 bps

PgmPrintln(“Pi speaker”);

if (!card.init()) {
error(“Card init. failed!”);
if (!vol.init(card)) {
error(“No partition!”);
if (!root.openRoot(vol)) {
error(“Couldn’t open dir”);

PgmPrintln(“Files found:”);;

// find Adafruit RFID/NFC shield

uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print(“Didn’t find PN53x board”);
while (1); // halt
// Got ok data, print it out!
Serial.print(“Found chip PN5”); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print(’.’); Serial.println((versiondata>>8) & 0xFF, DEC);

// configure board to read RFID tags


/////////////////////////////////// LOOP

unsigned digit = 0;

void loop() {
uint8_t 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)

// wait for RFID card to show up!
Serial.println(“Waiting for an ISO14443A Card …”);

// 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, &uidLength);

uint32_t cardidentifier = 0;

if (success) {
// Found a card!

Serial.print(“Card detected #”);
// turn the four byte UID of a mifare classic into a single variable #
cardidentifier = uid[3];
cardidentifier <<= 8; cardidentifier |= uid[2];
cardidentifier <<= 8; cardidentifier |= uid[1];
cardidentifier <<= 8; cardidentifier |= uid[0];

// repeat this for loop as many times as you have RFID cards
if (cardidentifier == 2588581390) { // this is the card’s unique identifier
playcomplete(“1.WAV”); // these are file names for the sample audio files - change them to your own file names

if (cardidentifier == 2146122274) {

/////////////////////////////////// HELPERS


  • print error message and halt
    void error_P(const char str) {
    PgmPrint("Error: ");
  • print error message and halt if SD I/O error
    void sdErrorCheck(void) {
    if (!card.errorCode()) return;
    PgmPrint("\r\nSD I/O error: “);
    Serial.print(card.errorCode(), HEX);
    PgmPrint(”, ");
    Serial.println(card.errorData(), HEX);
  • Play a file and wait for it to complete
    void playcomplete(char *name) {
    while (wave.isplaying);

// see if an error occurred while playing

  • Open and start playing a WAV file
    void playfile(char *name) {
    if (wave.isplaying) {// already playing something, so stop it!
    wave.stop(); // stop it
    if (!, name)) {
    PgmPrint("Couldn’t open file ");
    if (!wave.create(file)) {
    PgmPrintln(“Not a valid WAV”);
    // ok time to play!;

Any help with an existing sketch similar to this that would allow this to happen would be appreciated or advice on how to accomplish this using edits.

I am absolutely certain that your code does NOT look like that. You clearly didn't read the "How to post in this forum" topic before you blundered in here. So, why should we be inclined to help you?

What part of the project do you need help with? You have a bunch of incorrectly posted code that does something. You haven't bothered to say what it does. You have some requirements that may, or may not, be met by that code. You haven't explained which are, and which are not, met by the code.