NFC BASED SECURITY DOOR LOCK
Let us take a closer look at the hardware components used for this project:
5. Jumper Wires
6. 5V microUSB Power adapter
The block diagram for the hardware connections is shown below:
To have a better understanding of how to make the hardware connections, please refer to the video below:
The code for this project is given below. Before uploading this code, make sure you have installed the RF430 library.
#include <RF430CL.h> //include to use the Witty Fox NFC board
#define RF430CL330H_BOOSTERPACK_RESET_PIN 25 //reset pin of NFC board connected to GPIO
#define RF430CL330H_BOOSTERPACK_IRQ_PIN 26 //interrupt pin of NFC board connected to GPIO
RF430 nfc(RF430CL330H_BOOSTERPACK_RESET_PIN, RF430CL330H_BOOSTERPACK_IRQ_PIN);
String password = "Robocraze"; //declaration of the password which will unlock the door
pinMode(2, OUTPUT); //pin connected to on-board LED
pinMode(13, OUTPUT); //pin connected to input of Relay
Serial.println("Initializing NFC Tag-");
Serial.println("Activating NFC transceiver-");
Serial.println("Now waiting for NFC master to post a Text block.");
msg.setPayloadBuffer(buf, 512); // Set allocation buffer used to store incoming NDEF data
// If nfc.loop() returns true, nfc.disable() is implicitly run...
Serial.println("NFC transceiver reports its SRAM contents do not contain valid NDEF data.");
Serial.println("NDEF tag was read!");
Serial.print("NFC master has written a new tag! ");
uint16_t len = nfc.getDataLength();
Serial.println("Assuming data is NDEF TEXT; importing-");
int ret = msg.import(nfc);
if (ret < 0)
Serial.println("ERROR importing NDEF TEXT data. SRAM dump:");
Serial.print("Language code: ");
String Data = msg.getText();
if (Data == password) //door will only unlock if the received message matches with the password set in the beginning
for (i = 0; i < 5; i++)
digitalWrite(13, LOW); //door will unlock for approximately 5 seconds
//blink onboard LED when the door is unlocked
i = 0;
nfc.readSRAM(0x0000, sram, 128);
for (int i = 0; i < 128; i++)
if (sram[i] < 0x10)
if (i % 9 == 8)
Working:Once the program is uploaded and the setup is completed, install the TagWriter Application made by NXP - Available on Android and iOS.
Open the app, go to the “Write tags” option, and click on "New Dataset" followed by "Plain Text". Enter the password which you have set in the code and click on the "Save & Write" option at the bottom.
A screen will pop up displaying the data which you have entered, you may or may not choose the "Confirm Overwrite" option. Press on write again and take your phone close to the NFC reader.
The phone should be able to write to the NFC reader when they are within 5cm of each other. It will take 1-2 seconds for the write operation to be completed which will be indicated by an alert tone made by the application. The door will open as soon as you pull out your phone away from the readers' proximity.
Once you create a dataset, you can access it directly in the app under "My Datasets" tab, this means you don't have to enter the password in the application every single time.
Feel free to come up with other cool ideas and do share them with us. You can buy the Witty Fox boards at Robocraze .
Comment below if you get stuck or have any further questions.