Project tutorial

Never Forget Your Keys: NFC Door Reminder © CC BY-NC-SA

This project will remind you with auditory cues and an NFC scanning system to make sure that you have your keys on the way out the door.

  • 1 comment
  • 20 respects

Components and supplies

About this project

I recently moved into my dorm room at Harvard--among the many changes I've encountered is having to remember my keys each and every time I leave the room. Rather than just try and remember the normal way I decided to have technology do the remembering for me!

This project is essentially an NFC reader that you stick on your door. Every time you approach the door the circuit makes noise; the only way to stop the noise is to scan an NFC tag affixed to your keys against the reader. Thus, the noise means you won't ever forget your keys again! Let's dive in.

Step 1: The Parts

Every component required for this project can be purchased from The links are below:

  • NFC Tags (order as many as you want to have to put on key rings)

You're also going to need a few male-to-male jumper wires and female-to-male jumper wires to connect everything together. In addition, you should have your key ring handy.

The purpose of the distance sensor in this project is to determine when you start to approach the door. When a certain threshold is met the buzzer will start making noise until an NFC tag is scanned.

Step 2: Connecting the Components

No soldering is required, so connection time is minimal.

  • The IR sensor needs 5V power, so plug the red connection wire into the Leonardo's 5V pin. The black wire goes to GND, and the remaining data wire goes to A0.
  • The NFC reader's 3.3V pin should be plugged into 3V, and the GND pin into GND. The RX pin gets plugged into the Leonardo's TX pin and the TX pin into the RX pin on the Leonardo.
  • You can connect the red wire on the Gravity piezo buzzer to VIN, the black wire to GND, and the green wire to pin 10.

There should be just enough power pins available that a breadboard isn't required. Please note that if you power your Leonardo from a source other than USB the VIN pin may not output a clean 5V.

Step 3: The Code

Upload the sketch attached in the code section to your Leonardo to begin. Don't worry if you don't understand some of the serial communication code; the sole purpose of a lot of this program is communicating with the NFC reader. The portions that implement making noise and reading distance values are pretty simple. As soon as the distance reading from the IR sensor drops below a specific threshold the buzzer starts making noise until either an NFC tag is scanned or the distance threshold isn't met. Once a tag is scanned the buzzer won't make any noise for 5 seconds even if an object is within the threshold.

Obviously there's the capability for much more. Right now the NFC reader checks to see if any tag is scanned - it doesn't care about the data on the tag. Different profiles could be created to gather analytics on when/how often a specific person enters and leaves the room.

Step 4: Mounting

After some trial and error I developed what I think is the optimal mounting system. Place the distance sensor right next to the door. This minimizes the number of false positives of people just walking past it. The location of the NFC reader is a matter of personal preference: I placed it right at waist level so I can quickly scan my keys when I walk out of the door. Depending upon your outlet setup you might very well need an extension cord to provide power to the Leonardo.

Double-sided sticky tape is probably the best way to ensure that components stay where they should be.

Step 5: Going Further

As I mentioned previously, there's much more you can do with this system. Incorporating some kind of analytics system would be an interesting experiment. Additionally, you could try and replace the distance sensor with some kind of capacitive system that detects when the doorknob is touched and responds accordingly.


//Code written by Alex Wulff and For contact info visit

// bytes necessary for communication with NFC Reader
const unsigned char wake[24]={
  0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, 0x00};
const unsigned char firmware[9]={0x00, 0x00, 0xFF, 0x02, 0xFE, 0xD4, 0x02, 0x2A, 0x00};
const unsigned char tag[11]={0x00, 0x00, 0xFF, 0x04, 0xFC, 0xD4, 0x4A, 0x01, 0x00, 0xE1, 0x00};
const unsigned char std_ACK[25] = {
  0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x0C, \
0xF4, 0xD5, 0x4B, 0x01, 0x01, 0x00, 0x04, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x4b, 0x00};
unsigned char old_id[5];
unsigned char receive_ACK[25];

// setting up Serial for NFC Reader
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#define print1Byte(args) Serial1.write(args)
#define print1lnByte(args)  Serial1.write(args),Serial1.println()
#include "WProgram.h"
#define print1Byte(args) Serial1.print(args,BYTE)
#define print1lnByte(args)  Serial1.println(args,BYTE)

// pins utilized on Leonardo and constants
#define IR_SENSOR         A0
#define BUZZER            10
#define FLAG_RESET_TIME   5000

void setup(){
  pinMode(BUZZER, OUTPUT);
  pinMode(IR_SENSOR, INPUT);

long lastFlag = 0;
bool flag = false;

void loop(){

  // get current distance from IR sensor
  int distance = getDistance();
  if (!cmp_id()) {
    if (test_ACK()) {

      // NFC device detected. Play tone!
      tone(BUZZER, 440, 200);
      tone(BUZZER, 800, 200);
      tone(BUZZER, 2000, 200);
      tone(BUZZER, 300, 200);
      lastFlag = millis();
      flag = true;

  // only turn on buzzer if there's no NFC tag and distance < 10
  if(distance < 10 && flag == false) {
    analogWrite(BUZZER, 255);

  else {
    digitalWrite(BUZZER, LOW);

  // reset flag after 5 seconds
  if (millis() - lastFlag > FLAG_RESET_TIME) {
    flag = false;

int getDistance(void) {
  return 2076.0 / (analogRead(IR_SENSOR) - 11.0);

void copy_id (void) {//save old id
  int ai, oi;
  for (oi=0, ai=19; oi<5; oi++,ai++) {
    old_id[oi] = receive_ACK[ai];
char cmp_id (void){//return true if find id is old
  int ai, oi;
  for (oi=0,ai=19; oi<5; oi++,ai++) {
    if (old_id[oi] != receive_ACK[ai])
      return 0;
  return 1;

int test_ACK (void) {// return true if receive_ACK accord with std_ACK
  int i;
  for (i=0; i<19; i++) {
    if (receive_ACK[i] != std_ACK[i])
      return 0;
  return 1;

void UART1_Send_Byte(unsigned char command_data){//send byte to device
#if defined(ARDUINO) && ARDUINO >= 100
  Serial1.flush();// complete the transmission of outgoing serial data 

void read_ACK(unsigned char temp){//read ACK into reveive_ACK[]
  unsigned char i;
  for(i=0;i<temp;i++) {

void wake_card(void){//send wake[] to device
  unsigned char i;
  for(i=0;i<24;i++) //send command

void firmware_version(void){//send fireware[] to device
  unsigned char i;
  for(i=0;i<9;i++) //send command

void send_tag(void){//send tag[] to device
  unsigned char i;
  for(i=0;i<11;i++) //send command


Similar projects you might like

Secret Door Opener

Project tutorial by Alex Wulff

  • 37 respects

How to Make Non-Touch Automatic Door Open-Close System

Project tutorial by DKARDU

  • 12 respects

Arduino - Remotely Open Door via Web with Pattern Password

Project tutorial by phpoc_man

  • 23 respects

RFID Door Lock with Arduino

Project tutorial by RobotGeek Projects Team

  • 46 respects

Door Alarm With Ultrasonic Sensor

Project showcase by MattG

  • 32 respects

Alexa Controlled Face Recognizing Arduino Door Bell

Project tutorial by Team Enzi

  • 17 respects
Add projectSign up / Login