Introduction: Arduino Controlled Lock Box With Solenoid and RFID

About: The RobotGeek team is a 6-man operation that wants to make it even easier to use Arduino to make electronics and robots. Check out our instructables and robotgeek.com for all of our awesome kits.

The RFID Lock Box combines Arduino, RFID and a Solenoid to make your very own personal safe! The Lock Box will only open to Key Cards that you've programmed into the system, locking everyone else out!

This guide will show you how setup the electronics for and assemble your RFIDuino Lock Box. You will start of by setting up and programming the Geekduino microcontroller. You will then be able to test your electronics, and then move onto assembling your Lock Box Kit.

Step 1: Project Parts List

All the parts necessary are available in the RobotGeek RFID Lock Box Kit, or you can assemble it with the following parts:

If you are new to RFID, we recommend sticking with the RFIDuino Shield as your RFID reader so that the sample code provided runs without a hitch, and you can refer to our documentation if you run into any issues.

Step 2: Familiarize Yourself With the RFIDuino

RFID stands for Radio Frequency IDentification. The RFID system consists of two components, an RFID reader and an RFID tag. The reader interacts wirelessly with a tag to retrieve a unique identification number. The system can be used for many things from opening doors to tracking inventory.

The RFIDuino Shield for Arduino adds RFID capabilities to your Geekduino/Arduino. The shield fits on top of your arduino, making solid connections to the RFIDuino's circuitry. The built in buzzer and LEDs allow you to get stared right away by making visual and audio cues depending on the data that is on a given tag. The shield also allows you to add components to expand your system. You can use this to make your own door locks, inventory systems and more!

Step 3: Install the RFIDuino Shield

To Install the RFIDuino Shield, line the pins up with the bottom of the shield and the top of the Geekduino/Arduino. The male pins on the Shield should slide into the female pins on the Geekduino/Arduino. Once the Shield is installed, you can use the included 2-pin cable to connect the Shield to the Antenna.

You can program the Geekduino/Arduino with the shield plugged in. However, you cannot program the shield if you have an XBee module plugged in. You will have to remove the module or the shield to program the Arduino.

Step 4: Get Your RFID Tag ID

In order to use our RFID tag, we're going to need to know its ID to program into the board. Connect your RFIDuino into the computer as shown above.

You're going to need the RobotGeek Tools and Libraries ZIP file for a sketch that will allow you to read your card data to the serial monitor. The RobotGeek Tools and Libraries Download offers a variety of sketches and libraries for working with RobotGeek Robot Kits. The libraries folder contains libraries that will add functionality to your Arduino, while the RobotGeek Sketches folder contains behavioral code for robots, as well as tools for testing. Install it by adding these two folders to your Arduino user folder.

Open the RFIDuino_helloworld sketch. This can be found under:

File>Examples>RFIDuino>RFIDuino_helloworld

You will need to make sure the code is adjusted for your RFIduino hardware.
v1.2 shields (2 pin antenna, 'REV 1.2' printed on the board) will need the following code

RFIDuino myRFIDuino(1.2); //initialize an RFIDuino object for hardware version 1.2

v1.1 shields (4-pin antenna, no version number printed on the board) will need the following code

RFIDuino myRFIDuino(1.1); //initialize an RFIDuino object for hardware version 1.1

Both lines of code are available in the RFIDuino_helloworld sketch, simply uncomment the one you don't need. If you are still unsure about what hardware you are using, see this page

Connect a micro USB cable from your computer to your Geekduino

Load RFIDuino_helloworld onto your board using the upload button in the Arduino IDE.

Once loaded, you can leave your board connected to your computer - you will need this connection to power the board and to communicate with the computer

Open the Serial Monitor.

The serial monitor should be set to its default settings ('No Line ending', 9600 baud)

Swipe a tag across the RFIDuino antenna. The green light will light up and your buzzer will make a noise.

The Serial Monitor will display 5 numbers separated by commas. These numbers make up the ID of your tag.

Copy down these numbers for future use. It can be handy to write the ID on a sticky note and attach it to the tag.

Tags in the EM4102 protocol have 64 bits that they return to the RFID reader. 24 of these bits are used for communication / protocol information (9 header bits, 10 parity bits and a stop bit.) This leaves 40 bits, or 5 byte for the tag's ID. The RFIDuino library returns the tag's ID as an array that contains these 5 bytes. All of the RobotGeek tutorials will use this convention for dealing with the Tag's ID number, displaying the tag id as 5 numbers in decimal format. However here are many ways that you can represent this number.

Step 5: Wiring and Assembly

Connect your components as shown in the diagram. If you have the RFID Lock Box Kit, you can follow the directions in the Assembly Guide at this point.

If you're building your own, check out the images of the latching mechanism parts, and get an idea of how you'd like to make yours. Each piece in the locking mechanism can be re-positioned for height or depth. This is so the solenoid can be positioned in such a way to clear the latch when activated, but catch it when it's off. In the last picture, we are showing the position of the solenoid when inactive, resting on the edge of the latch. In this position, your solenoid plunger should clear the latch when activated. Adjusting the vertical position of the Latch may be necessary. If the latch is too low, the solenoid won't catch it. If the latch is too high, the box might not close, or it will close ineffectively, leaving a gap that allows you to see the latching mechanism even when the solenoid plunger rests in the latch.

Step 6: Program and Test Your Lock Box

  1. Open RFIDuino_demo2_lockbox onto your board. You can find this sketch under
    File>Examples>RFIDuino>RFIDuino_demo2_lockbox
  2. You will need to make sure the code is adjusted for your RFIduino hardware.
    v1.2 shields (2 pin antenna, 'REV 1.2' printed on the board) will need the following code
    RFIDuino myRFIDuino(1.2);     //initialize an RFIDuino object for hardware version 1.2
    v1.1 shields (4-pin antenna, no version number printed on the board) will need the following code
    RFIDuino myRFIDuino(1.1);     //initialize an RFIDuino object for hardware version 1.1
    Both lines of code are available in the RFIDuino_demo2_lockbox sketch, simply uncomment the one you don't need. If you are still unsure about what hardware you are using, see this page
  3. You will also need to modify the sketch to include the ID of a tag that we found in Hello World . Find line 57 - it looks like this.
    byte key_tag[5] ={0,0,0,0,0};			
    Now insert the ID numbers for your tag. For example, if our tags ID was '70 0 44 22 242' we would modify the code to look like this
    byte key_tag[5] ={77,0,44,22,242};
  4. Connect a micro USB cable from your computer to your Geekduino
  5. Load RFIDuino_demo2_lockbox onto your board using the upload button int the Arduino IDE.
  6. Once loaded, you disconnect the USB cable from your computer..
  7. Swipe the 'key' tag across the RFIDuino antenna. The green light will light up and your buzzer play three different notes. Additionally, the solenoid will fire.
  8. Swipe any tag that is not the 'key' tag across the RFIDuino antenna. The red light will light up and your buzzer play three monotone notes. The solenoid will not react.

Step 7: NICE.

At this point, you should have a fully functioning RFID enabled Lock Box. What are you going to store in it? You have a bunch of IO pins you can use on it, so how do you plan to upgrade it? Bigger box? Flashy lights? We'd love to see what you come up with!