How to Build an RFID Safe

by denisesantiago in Circuits > Arduino

1331 Views, 8 Favorites, 0 Comments

How to Build an RFID Safe

RFID Safe

Introduction

Hi, I am Denise and in this instructable, I will be teaching you how to build a safe that incorporates an RFID lock system which can be unlocked or locked using a keycard. There are many different components used in this project so I suggest getting familiar with each individual component before proceeding to combine them in this project. It will also be helpful to have some basic background knowledge on how to use an Arduino board.

Inspiration Underlying the Project

The concept that this idea came from was the typical office workplace. Many workplaces use keycards to unlock doors and gain access to several rooms in the building. I thought that it would be interesting to incorporate this concept into a smaller scale project. I also made this project to test different skills to combine different modules/components into one whole project.
Research After getting inspiration to carry on with this project, I did a bit of research online to see projects that were similar to the one I wanted to create. There were many different projects that incorporated the RFID module in a variety of creative ways. After a bit of searching, I was able to stumble across a video and website that build similar projects.

Gather the Materials Needed to Complete This Project

IMG_3485.JPG
IMG_3481.JPG
IMG_3479.JPG
IMG_3476.JPG
IMG_3475.JPG
IMG_3478.JPG
batterypack.jpg

Materials You Will Need:

1x Arduino Uno Board

1x USB 2.0 Cable Type A/B

1x RFID Module

1x RFID Key Tag/Key Card

Purchase RFID Module and Key Tag/Card here

1x Servo Motor

1x Relay Module

1x Display LCD 16x2

18x Male/Female Jumper Wires

Wood or Cardboard

1x Rechargeable Battery Pack (OPTIONAL)

Purpose of Components

Before we continue on with the next step, it is important to know what each component of this project is and its function.


RFID

RFID is short for radio frequency identification. It is a wireless application to transfer data in the purpose of identifying and tracking tags. In this project, we will be using the RFID module to identify the correct keycard that unlocks the safe.

Servo Motor

Servo is a type of geared motor that can only rotate 180 degrees. It is controlled by sending electrical pulses from your SunFounder Uno board. These pulses tell the servo what position it should move to. A servo has three wires, the brown wire is GND, the red one is VCC, and the orange one is the signal line. In this project, we will be using the servo as the lock that moves to unlock or lock the door of the safe.

16x2 LCD

The LCD display is a display that can display different numbers, letters, and characters. In this project, we will be using this to give instructions and to display the identification number of the keycard.

Relay

The relay is a device which is used to provide a connection between two or more points or device in response to the input signal applied. In other words, the relay provides isolation between the controller and the device as we know devices may work on AC as well as on DC. However, they receive signals from microcontroller which works on DC hence we require a relay to bridge the gap. The relay is extremely useful when you need to control a large amount of current or voltage with a small electrical signal.

Make Connections From the Arduino to Components

Screenshot 2019-01-22 at 6.27.47 PM.png
Screenshot 2019-01-22 at 6.31.31 PM.png

Relate to images of the circuit above (Connect all modules to the same Arduino board).

Here is a list of the connections that I made to the Arduino Board to make it easier, or you can also follow the diagrams above.

List of Wire Connections

Servo Connections:
GND= GND

Signal= 9

Power = 11

LCD 16x2 I2C Connections:

GND=GND

VCC= 5V

SDA= A4

SCL=A5

Relay Module Connections:

GND=GND

VCC= 13

SIC= 8

RFID Module Connections:

VCC= 3.3V

RST= 2

GND= GND

MISO= 3

MOSI= 4

SCK= 5

NSS= 6

IRQ= 7

(Do not plug the RFID into 5V because it will damage the module and will potentially stop working)

Read a RFID Key Tag/card

Screenshot 2019-01-25 at 12.03.36 AM.png

This step is used to obtain the keycard/tag information which will be used in the code that is written to unlock the safe. When you get the information from the Serial Monitor located in the top right of the Arduino page, write it down somewhere such as a document so that you remember this, it is important since that information will be used in the next code. (This code will not be apart of the final code).

<p>#include"rfid1.h"<br>RFID1 rfid;//create a variable type of RFID1</p><p>uchar serNum[5];  // array to store your ID</p><p>void setup()
{
  Serial.begin(9600); //initialize the serial
  rfid.begin(7, 5, 4, 3, 6, 2);  ////rfid.begin(IRQ_PIN,SCK_PIN,MOSI_PIN,MISO_PIN,NSS_PIN,RST_PIN)
  delay(100);//delay 1s
  rfid.init(); //initialize the RFID
}
void loop()
{
  uchar status;
  uchar str[MAX_LEN];
  // Search card, return card types
  status = rfid.request(PICC_REQIDL, str);
  if (status != MI_OK)
  {
    return;
  }
  // Show card type
  rfid.showCardType(str);
  //Prevent conflict, return the 4 bytes Serial number of the card
  status = rfid.anticoll(str);</p><p>  if (status == MI_OK)
  {
    Serial.print("The card's number is: ");
    memcpy(serNum, str, 5);
    rfid.showCardID(serNum);//show the card ID
    Serial.println();
    Serial.println();
  }
  delay(500);</p><p>  rfid.halt(); //command the card into sleep mode 
}</p>

Coding

Now that we have the set up of components out of the way, it is time for the step that will actually make each component run. Code is basically a set of instructions that are written and sent to the Arduino board. Depending on the code you write, the components will do the tasks you tell it to do.

There are two required libraries that you will need to install for this code to run:

LiquidCrytal_I2C Library Download

Servo Library Download

<p>#include <br>Servo myservo;
#include"rfid.h"
#include 

#include 
LiquidCrystal_I2C lcd(0x27,16,2);
RFID rfid; //create a variable type of RFID
#define relayPin 8  //relay module attach to pin8</p><p>uchar serNum[5]; // array to store your ID</p><p>void setup()
{
  pinMode(11,OUTPUT);
  pinMode(13, OUTPUT);
  lcd.init(); 
  lcd.backlight(); //turn on the backlight
  Serial.begin(9600);
  rfid.begin(7, 5, 4, 3, 6, 2);//rfid.begin(IRQ_PIN,SCK_PIN,MOSI_PIN,MISO_PIN,NSS_PIN,RST_PIN)
  delay(100); 
  rfid.init(); //initialize the RFID
  pinMode(relayPin, OUTPUT);  //set relayPin as OUTPUT
  digitalWrite(relayPin,HIGH); //and high level
  //Serial.begin(9600);
  lcd.setCursor(0,0);
  lcd.print("    Welcome!    "); //print"    Welcome!    "
  delay(2000);
  lcd.clear();
  lcd.print(" unlock w/ key ");
  lcd.print("    Welcome!    ");
  delay(2000);
  lcd.clear();
 lcd.print(" Unlock w/ key ");
 delay(2000);</p><p>myservo.attach(9);
myservo.write(0);
delay(1000);
}
void loop()
{
  digitalWrite(11,HIGH);
  digitalWrite(13,HIGH);
  uchar status;
  uchar str[MAX_LEN];
  status = rfid.request(PICC_REQIDL, str);
  if (status != MI_OK)
  {
    return;
  }
  rfid.showCardType(str);
  status = rfid.anticoll(str);</p><p>  if (status == MI_OK)
  {
    //Serial.print("The card's number is: ");
    lcd.setCursor(0,0);
    lcd.print(" ID: ");
    memcpy(serNum, str, 5);
    rfid.showCardID(serNum);//show the card ID
    // Serial.println();</p><p>    // Check people associated with card ID
    uchar* id = serNum;
    if( id[0]==0xA6 && id[1]==0x6E && id[2]==0xAB && id[3]==0x29 ) 
    {
      digitalWrite(relayPin,LOW);
      // Serial.println("Hello Denise!");
      lcd.setCursor(0,1);
      lcd.print(" Hello Denise! ");
      delay(1500);
      lcd.clear();
      lcd.print(" Access Granted! ");
      delay(1500);
      lcd.clear();
      digitalWrite(relayPin,HIGH);
    myservo.write (1800);
    delay(10000);
    myservo.write (0);
    }
    else                            
    {
      //Serial.println("Hello unknown guy!");
      lcd.setCursor(0,1);
      lcd.print(" Nice Try! ");
      delay(1500);
      lcd.clear();
      lcd.print(" Access Denied! ");
      delay(1500);
      lcd.clear();
    }
  }
  lcd.setCursor(0,0);
  lcd.print("    Welcome!    ");
  delay(2000);
  lcd.clear();
 lcd.print(" Unlock w/ key ");
 delay(2000);
 lcd.print("    Welcome!    ");
  delay(2000);
  lcd.clear();
 lcd.print(" Unlock w/ key ");
 delay(2000);
 lcd.print("    Welcome!    ");
  delay(2000);
  lcd.clear();
 lcd.print(" Unlock w/ key ");
 delay(2000);
 lcd.clear();
}</p>

Putting Components Into a Box

This part can be approached in many different ways. You can use different sized boxes or materials to complete this part. All you have to do is make sure that the servo is located on the inner side of the door and that the RFID is exposed so that it can read the key tags/cards and of course make sure the LCD display is visible. I will include pictures of how I created my box below.

You have successfully completed this project!

I hope that this instructable has helped you :)