Products for USB Sensing and Control
Products for USB Sensing and Control

#### sales inquiries

##### quotes, distributor information, purchase orders
sales@phidgets.com

#### technical inquiries

##### support, advice, warranty, returns, misshipment
support@phidgets.com

web@phidgets.com

#### Address

##### Unit 1 - 6115 4 St SE Calgary AB  T2H 2H9 Canada
Projects Dealers Terms and Conditions Discontinued Products Phidget21 Documentation

# Keyless Access Control with Phidgets RFID

#### How to set up a keyless entry system for any door in your house

by Brian

This project will help you set up a keyless entry system for any door in your house, specifically we want to create a system that will unlock a door when a recognized RFID tag is detected.

### Time

About a full day of work, including gathering components, writing code, and drilling/assembling. The challenge will be mounting, wiring, weather proofing, and running power to your system - the code is relatively easy.

### Special Tools

A selection of screwdrivers, Drill with a large bore drill bit, Fish tape, Exterior Caulk

### Materials Needed

A Double gang electrical box, and faceplate for the box

As with any of our described projects, Phidgets takes care of the electrical component design. Here, we walk you through the code and hardware connections to create a system out of our ready made boards.

Warning: Before you begin this project note that we will be drilling holes in an exterior wall, so make sure to check with local building codes to ensure the modifications you are making are legal.

## Introduction

Keyless entry systems have been in use in large facilities for years so why not your house too? At the flash of a card or key-chain your door will automatically unlock, no need to fumble around in the dark with a set of keys to find the right key which inevitably takes a few tries.

## Setting it up

The most difficult part with this project is installing all the components. We are trying to mount hardware on both the exterior and interior of the wall; this can be tricky as cables will need to be run through the wall. Since exterior walls have insulation in them, feeding wires through can be difficult.

1. The first step is to cut a hole in the exterior wall that is large enough to fit the box you have gotten.
2. You will need to drill a hole through the interior side of the wall inline with this large hole.
3. Use your fish tape to feed the USB cable through the hole and then fish it through the electrical box.
4. Insert the box into the hole you created and screw it in place.
5. Use the exterior caulk to create a seal between the box and the wall.
6. The easiest thing to do now is to fasten the RFID reader to the faceplate via glue or foam tape.
7. Attach the faceplate to the electrical box and this part is finished.

Depending on where you install the box it may also be a good idea to use some foam weather stripping to enhance the seal of the faceplate to the box.

On the inside you will need to mount the SBC. This can be done many ways though the obvious choice is to do the same thing as you did for the RFID reader. Since the location of the SBC is less important you could even put it down at foot level, out of sight. Alternatively you could mount it in an enclosure directly on the wall. If you have a basement or crawlspace underneath your front door you could also mount it on the rafters below the door. Having the SBC be connected to the internet will help debug issues, keep maintenance easy, and allow for easier addition of new tags

Next we need to have a method for actually unlocking the door. For this project we will be using an electric strike. An electric strike is a device that replaces the hardware on the jamb of the door. Electric strikes can be difficult to install, usually they are used in metal frame doors since the jambs tend to be hollow in these cases which makes running wires much easier. However, there are strikes made specifically for wooden doors. In general, you should follow the instructions that come with the strike for installation.

While installing the strike keep in mind what you are going to need to do with the wires. You need to run wires from the power supply to the relay and from the relay to the strike.

This is the functional schematic for the components of this project:

This is how it would look in real life

## Software

Note: The code examples in this article use Phidget21 code and may not work with newer versions of the Phidget library.

We want the program to have the following process flow:

We need to have code that checks RFID tag events against a list or database of accepted tags and if the tag is a recognized tag, switch power on to the electric strike.


rfid.addTagGainListener(new TagGainListener()
{
public void tagGained(TagGainEvent oe)
{
String line = null;
try{
reader = new Scanner(inFile); // set the scanner to read in from the appropriate file
}
catch(Exception e){}
while(reader.hasNextLine()){  // read through the entire file
try{
line = reader.nextLine(); //read in the current tag data
if(line.equals(oe.toString())){ //does the active tag match this entry?
ik.setOutputState(0,true); //if so activate the relay.
}
}
catch(Exception e){}
}
reader.close();
}
});



Where inFile is a File object set to the file in which the tag data is stored. The tags can be read into a file off-line prior to normal operation, or at will with the push of a button depending on what you prefer. You can download the full code here. Note that this code has a mechanism for reading tags into a file though it is for demonstration purposes. In practice you would want the tag reading system to be a bit more robust. Perhaps by using a database of some kind so you could also log who specifically was accessing the door etc...

When the tag is no longer detected the door should relock, though we want to have a window in which the user can still open the door before it locks. This can be handled in our tag loss handler:

//SHORTDELAY is an arbitrary number of milliseconds
delay = new javax.swing.Timer(SHORTDELAY, new ActionListener(){
public void actionPerformed(ActionEvent evt){
try {
ik.setOutputState(0,false);
}
catch(Exception e){}
delay.stop();
}
});

rfid.addTagLossListener(new TagLossListener()
{
public void tagLost(TagLossEvent oe)
{
try {
if(ik.getOutputState(0) == true){
delay.start(); //add a short delay so the user has time to open the door
}
}
catch(Exception e){}
}
});