✨ DOWNLOAD OUR APP - Use RCAPP
for additional 5% discount! + Redeem RC COINS 👇
Skip to content
Free Delivery on Orders Above Rs 999/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA

NFC BASED SECURITY DOOR LOCK

Let us take a closer look at the hardware components used for this project:

1.  Witty Fox NFC board

2.  Witty Fox Storm board

3.  12V Solenoid lock

4.  5V relay module

5.  Jumper Wires

6. 5V microUSB Power adapter

7.  12V Power adapter

 

The block diagram for the hardware connections is shown below:

 

Connection Diagram

 

 

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 <Wire.h> 
#include <RF430CL.h> //include to use the Witty Fox NFC board
#include <NDEF.h>
#include <NDEF_TXT.h>

#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);
NDEF_TXT msg;
uint8_t buf[512];
String password = "Robocraze"; //declaration of the password which will unlock the door
void DumpSRAM();

void setup()
{
  Serial.begin(115200);
  delay(1000);
  pinMode(2, OUTPUT); //pin connected to on-board LED
  pinMode(13, OUTPUT); //pin connected to input of Relay

  Serial.println("Initializing I2C-");
  Wire.begin();

  Serial.println("Initializing NFC Tag-");
  nfc.begin();

  Serial.println("Activating NFC transceiver-");
  nfc.enable();

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
}

void loop()
{
  digitalWrite(13, HIGH);

  if (nfc.loop())
{
// If nfc.loop() returns true, nfc.disable() is implicitly run...
    if (nfc.isError())
{
  Serial.println("NFC transceiver reports its SRAM contents do not contain valid NDEF data.");
      DumpSRAM();
}
    if (nfc.wasRead())
{
      Serial.println("NDEF tag was read!");
}
    if (nfc.available())
{
      Serial.print("NFC master has written a new tag! ");
      uint16_t len = nfc.getDataLength();
      Serial.print(len);
      Serial.println(" bytes");

      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:");
        DumpSRAM();
}
      else
{
        Serial.println("Success!");
        Serial.print("Language code: ");
        Serial.println(msg.getLanguage());
        Serial.println("Text block:");
String Data = msg.getText();
        Serial.println(Data);

        if (Data == password) //door will only unlock if the received message matches with the password set in the beginning
{
          int i;
          for (i = 0; i < 5; i++)
{
            digitalWrite(13, LOW); //door will unlock for approximately 5 seconds
//blink onboard LED when the door is unlocked
            digitalWrite(2, HIGH);
            delay(500);
            digitalWrite(2, LOW);
            delay(500);
}
i = 0;
}
}
      nfc.flush();
}
    nfc.enable();
}
}

void DumpSRAM()
{
  uint8_t sram[128];

  nfc.readSRAM(0x0000, sram, 128);
  for (int i = 0; i < 128; i++)
{
    if (sram[i] < 0x10)
      Serial.print('0');
    Serial.print(sram[i], HEX);
    Serial.print(' ');
    if (i % 9 == 8)
      Serial.println();
}
  Serial.println();
}

Working:

Once the program is uploaded and the setup is completed, install the TagWriter Application made by NXP - Available on  Android and  iOS.

IMG_256
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. 
1.

IMG_256

2.

IMG_256

3.

IMG_256

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.

IMG_256

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. 

IMG_256

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.

 

Excerpt

Learn how to build an NFC-based security door lock ✓ uses Witty Fox NFC & Storm boards, solenoid lock, relay module, and Arduino for DIY projects.

Frequently Asked Questions

1. What is NFC technology and how does it work?

NFC, or Near Field Communication, is a short-range wireless technology that enables data exchange between devices within a few centimeters. It operates by generating electromagnetic fields to allow communication. Commonly used in mobile payments and smart devices, NFC is convenient and secure, allowing for quick data transfer without physical contact.

2. How does the NFC door lock system enhance security?

An NFC door lock system enhances security by using encrypted data transfer, which is difficult for unauthorized users to replicate. It enables keyless entry through authorized NFC tags or smartphones, reducing the risk of physical key duplication. Additionally, users can easily monitor access and revoke permissions remotely, improving overall security and control.

3. Which components are used in this NFC door lock project?

This NFC door lock project typically includes an NFC reader, microcontroller, servo motor for locking mechanism, power supply, and authorized NFC tags. Optionally, an LED indicator and buzzer can be added for feedback. These components work together to create a secure and efficient locking system controlled by NFC technology.

4. Can I integrate this system with a smartphone?

Yes, the NFC door lock system can be integrated with a smartphone. By utilizing NFC-enabled devices, users can unlock doors by simply tapping their phones against the lock. This provides a seamless experience, allowing easy access without the need for traditional keys or separate tags.

5. How can I add multiple authorized NFC tags?

To add multiple authorized NFC tags to your system, you can program the microcontroller to recognize each tag’s unique identifier. This involves using a specific command to register new tags, allowing multiple users access. Ensure that the programming logic accommodates each tag's ID, enhancing convenience for families or shared spaces.

Prev Post
Next Post

Leave a comment

Please note, comments need to be approved before they are published.

Thanks for subscribing!

This email has been registered!

Shop the look

Choose Options

Edit Option
Back In Stock Notification
Compare
Product SKU Description Collection Availability Product Type Other Details

Choose Options

this is just a warning
Login
Shopping Cart
0 items
FREE SHIPPING!
₹100 OFF
₹200 OFF
WhatsApp Chat Chat