Introduction: RFID Lockbox

This instructable was created in
fulfillment of the project requirement of the Makecourse at the University of South Florida (

This Inscrutable will take you through all of the steps necessary to
build your own arduino controlled RFID Lockbox. The final product will use an RFID reader along with RFID chips to lock and unlock your deposit box.

The Lockbox uses a rechargeable battery to power itself.

One can open it with the RFID Chips, but if for some reason you want to use the original key, of course you can do so. Only now you need to disarm it with your own secret combination.

I found the project fun, and I learned alot about programming.

This was my first Arduino Project, so enjoy, but keep in mind there could be many improvements.

Step 1: Aquire Materials

This project will call for the following materials:

1 X Arduino Uno (Here)

1 X RFID Module with card/dongle (Here)

1 X Steel lockbox (Here)

1 X ON/OFF Switch (Local electronics store)

1 X Solenoid-Lock (Here)

3 X Buttons (Here)

1 X Buzzer (Here)

2 X LED's (Local electronics store)

1 X Tilt Sensor (Here)

1 X Relay (Here)

1 X Rechargeable Lithium battery Pack (Here)

And Miscellaneous Wires, Solder and Screws

Step 2: Design Your Box in CAD and 3D-Print Parts

Attached are the Solidworks Parts that I designed for my particular Lockbox. If you go with a different type of box you will have to modify accordingly. The holes for the Buttons and the ON/OFF switch as well as the LED's are not accounted for because those are very easily made after printing and could vary very much depending on what hardware was used.

Step 3: Design Your Control System

My Control System is pretty simple, but looks scary at first.

We have the Arduino as brains of the operation. It gets information from the tilt switch as well as the RFID module. It also receives inputs from the buttons. Once it has received all of its inputs and digested them. It unlocks the box, or the buzzer as well as red LED will be on. The green LED is simply an indicator for the tilt.

I will explain which pin's on the Arduino are used in the next Step.

Step 4: Write the Arduino Sketch

The hardest part of programming this system for me, was to get the buttons to work. The buttons need to store a value (in this case 1,2 or 3) in a vector and then compare them with a preset "Code". This can be challenging using simple buttons.

At the top of my arduino code you will see two include commands. You will have to download these and add them to your arduino libraries so that the code will work.

Then you see alot of define statements. This is where you will see how to wire the components.

Here is my Code:

#include <SPI.h>

#include <MFRC522.h>

MFRC522 mfrc522(SS_PIN, RST_PIN);

int counter = 0;
unsigned long lastPush = 0;
int lastPushValue = -1;
unsigned long lastOpened = 0;
int array1[5] = {1, 2, 3, 2, 1};
int array2[5] = { -1, -1, -1, -1, -1};
bool gLocked = true;
unsigned long lastScan = 0;

#define RST_PIN 9

#define SS_PIN 10
#define button1 3
#define button2 5
#define button3 4
#define greenLed 7
#define redLed 6
#define buzzer 8
#define relay 2
#define tilt 14

void setup() {
Serial.begin(9600); // Establishing Serial connection
pinMode (button1, INPUT); // Defining Input or Output pins
digitalWrite(button1, HIGH);
pinMode (button2, INPUT);
digitalWrite(button2, HIGH);
pinMode (button3, INPUT);
digitalWrite(button3, HIGH);
pinMode(greenLed, OUTPUT);
digitalWrite(greenLed, LOW);
pinMode(redLed, OUTPUT);
digitalWrite(redLed, HIGH);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, LOW);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
pinMode(tilt, INPUT);

SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

int buttonValue (int b) {
if (b == button1) {
return 1;
else if (b == button2) {
return 2;
else if (b == button3) {
return 3;
return 0;
String printButton(int b) {
int value = buttonValue (b);
return "button " + String(value);

int checkButton(int refresh, int c, int b) { //c=counter b=button
int ret = refresh;
unsigned long currentTime = millis();

if (digitalRead(b) == LOW && refresh == 1 && (currentTime - lastPush > 500 || lastPushValue != buttonValue(b))) {
array2[counter] = buttonValue(b);
lastPush = currentTime;
lastPushValue = buttonValue(b); //Serial.println("counter: " + String(c) + " " + printButton(b) );
for (int i = 0; i < 5 ; i++)
ret = 0;
return ret;

void loop() {

bool tilted = tiltCheck(); // I keep the loop very simple by just putting the 4 main functions we made together lockKey();
output(gLocked, tilted);

void output(bool locked, bool tilted) { // all possible outcomes
if (locked && tilted ) {
digitalWrite(buzzer, HIGH);
else {
digitalWrite(buzzer, LOW);
if (locked) {
digitalWrite(redLed, HIGH);
digitalWrite(relay, LOW);
else {
digitalWrite(redLed, LOW);
digitalWrite(relay, HIGH);

if (tilted) {
digitalWrite(greenLed, HIGH);
else {
digitalWrite(greenLed, LOW);


void lockKey() { // unlock or not using buttons

bool match = true;
int refresh = 1;
refresh = checkButton(refresh, 3, button3);
refresh = checkButton(refresh, 1, button1);
refresh = checkButton(refresh, 2, button2);

for (int i = 0; i < 5 ; i++) {
if (array1[i] != array2[i]) {
match = false;
if (match && gLocked) {
gLocked = false;

if (millis() - lastPush > 10000) {
for ( int erase = 0; erase < 5; erase++) {
array2[erase] = -1;
counter = 0;
void lockChip() { // unlock or not using keycard
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {

// Dump debug info about the card; PICC_HaltA() is automatically called
String scannedKey = "";
byte readCard[4];
unsigned long currentTime = millis();
if (currentTime - lastScan > 2000) {
scannedKey = "";
for ( uint8_t i = 0; i < 4; i++) {
readCard[i] = mfrc522.uid.uidByte[i];
//Serial.print(readCard[i], HEX);
scannedKey += readCard[i];
if (scannedKey == "86234213229" || scannedKey == "9712424785") {
gLocked = !gLocked;
lastScan = currentTime;

bool tiltCheck() { // check if tilted or not
return digitalRead(tilt) == LOW;


Step 5: Assemble and Enjoy

Now all that is left to do is assemble!

I started by cutting the lid of the lockbox out and placing the RFID chip in its housing. This is what covers up the hole you just cut. (RFID does not work through metal, so you must cut a hole)

I also cut out the existing locking mechanism from the box, as the lock now latches onto the solenoid.

Then I carefully disassembled the battery pack. I had to extend the wires going to the lcd screen. I cut the lcd screen out carefully and glued it into the hole in the Component plate.

Next I placed the lock into its bracket and screwed it down.

I drilled the appropriate holes for the LEDS, Buttons and ON/OFF switch and wired everything up.

Lastly I drilled holes into the Lockbox enclosure and attached the whole component plate in one go.

I finished the box with a coat of paint and it was done!

Now I have a place to store my belongings! (keep in mind this is not a "safe", one could simply unscrew the mechanism and the intruder would be in)

If the battery dies, one can simply recharge it using the supplied usb cable.