Alert.png

Notice: This page contains information for the legacy Phidget21 Library.

Phidget21 is out of support. Bugfixes may be considered on a case by case basis.

Phidget21 does not support VINT Phidgets, or new USB Phidgets released after 2020. We maintain a selection of legacy devices for sale that are supported in Phidget21.

We recommend that new projects be developed against the Phidget22 Library.


Click on the 2phidget22.jpg button in the menu bar to go to the Phidget22 version of this page.

Alert.png

Access Control: Difference between revisions

From Phidgets Legacy Support
No edit summary
No edit summary
 
(47 intermediate revisions by 5 users not shown)
Line 4: Line 4:
[[Category: mounting]]
[[Category: mounting]]
[[Category: PhidgetsSBC]]
[[Category: PhidgetsSBC]]
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.  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 with a set of keys to find the right key which inevitably takes a few tries. 
[[Category: Application Guides]]
 
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.   
{|border = 1
{|
|'''Hardware Difficulty: '''||image here||'''Software Difficulty: '''||image here||'''Time Commitment: '''||image here||'''Awesome: '''||image here
|Practical concepts covered are (click on links to see other projects on that topic):
* [[:Category:cabling|Cabling]]
* [[:Category:Weatherproofing|Weatherproofing]]
* [[:Category:mounting|Hardware Mounting]]
* [[:Category:PhidgetSBC|Using the Phidget SBC]]
|width="45px"| 
|[[File:doorunlockfull.png|500px|link=|alt=]]
|}
|}


This project includes:
{| style="border:1px solid darkgray;" cellpadding="5px;"
*Some tricky wiring
|'''Time:'''  
*Protecting your devices against the elements
| About a full day of work, including gathering components, writing code, and drilling/assembling.<br>  The challenge will be mounting, wiring, weather proofing, and running power to your system - the code is relatively easy.
 
|-
{|border = 1
|'''Special Needed Tools:'''  
|align = "center"|'''Phidgets'''||align = "center"|'''Parts'''||align = "center"|'''Tools'''
|A selection of screwdrivers, Drill with a large bore drill bit, Fish tape, Exterior Caulk
|-
|'''Phidgets Needed:'''  
|A [{{SERVER}}/products.php?product_id=1024 1024 - PhidgetRFID Read/Write], a [{{SERVER}}/products.php?product_id=1072 1072 - PhidgetSBC2] or [{{SERVER}}/products.php?product_id=1073 1073 - PhidgetSBC3], and a [{{SERVER}}/products.php?product_id=3052 3052 - SSR Relay Board]
|-
|-
|*1 [[1023_1 - PhidgetRFID]]
|'''Materials Needed:'''
*1 [[1072_0 - PhidgetSBC2]]||*1 Double gang electrical box
| A Double gang electrical box, and faceplate for the box
*1 Faceplate for the box||*Drill with a large bore drill bit
*Fish tape
*A selection of screwdrivers
|}
|}


'''''Warning: '''''Before you begin this project take note:  We will be drilling holes in an exterior wall, make sure to check with local building codes to ensure the modifications you are making are legal.
As with any of our [[:Category:Application Guides|described projects]], Phidgets takes care of the electrical component designHere, we walk you through the code and hardware connections to create a system out of our ready made boards.
 
===Hardware===
 
{|align="right"
|[[image:KeyPad.jpg|thumb|link=http://sl/wiki/images/4/47/KeyPad.jpg|100px|Front face of the keypad]]||[[image:KeyPadOpen.jpg|thumb|link=http://sl/wiki/images/9/95/KeyPadOpen.jpg|310px|Keypad PCBIf the leftmost terminal is connected to ground, all the buttons act as switches to ground.]]
|}
If you choose to use a keypad instead then you will need:
*A [[1018_2 - PhidgetInterfaceKit 8/8/8]]
*A keypad
*A weatherproof enclosure
*Possibly a relay depending on the method you choose.


The keypad you choose should have its buttons be switches to ground.  The keypad used in this particular example can be seen on the right.  Each button closes the circuit between ground and the terminal, this makes it perfect for connecting to a 1018 which has active low digital inputs (meaning they are true when the voltage is below 1.25V).
'''''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.


The most difficult part with either of these set ups is mounting.  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 tricky.  It is advisable to drill a small hole and use a coat hanger to check for large obstructions.  When you are ready to drill a larger hole, the use of a fish tape is advisable.  You might want to cut the plug of the USB cable off so that the hole can be smaller in diameter and then reattach it once the cable has been pulled through the wall.  On the exterior side you should make sure to make a loop in the cable before connecting it to the device, this will prevent any moisture on the cable from getting into the wall since it will drip off at the lowest point of the loop instead of travelling back into the wall.  Exterior caulk is also a good idea since you do not want cold air getting in through the hole. 
==Introduction==


Once the cable is in place you can mount the devices. Make sure that the housing you use on the exterior device (keypad or RFID reader) is weatherproof and you should also put a desiccant in the housing to ensure no moisture builds up (silica gel would work).  Phidgets enclosures are not weatherproof by default, but you can modify them to be suitable.  To do this you need to glue all the pieces save the top plate together to ensure an airtight seal. You can then use some thin weather stripping around the top to make the remaining gap tight, since the enclosure screws together you can make room for the weather stripping by not screwing the top plate down all the way.
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.


'''Next''' we need to have a method for actually unlocking the door. There are two ways this is done commercially, you can either motorize the actuation of the deadbolt. Or you can use what is known as an electric strike.
==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.
#The first step is to cut a hole in the exterior wall that is large enough to fit the box you have gotten.
#You will need to drill a hole through the interior side of the wall inline with this large hole.
#Use your fish tape to feed the USB cable through the hole and then fish it through the electrical box.
#Insert the box into the hole you created and screw it in place.
#Use the exterior caulk to create a seal between the box and the wall.
#The easiest thing to do now is to fasten the RFID reader to the faceplate via glue or foam tape.
#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.


To motorize the deadbolt a servo motor is recommendedYou will need to check how much force it takes to turn your deadbolt, for information on selecting an appropriate motor refer to the [[Motor Selection Guide]]Once you have picked out a motor that will work you need to make a frame to mount the motor over the deadbolt.   
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 readerSince 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 wallIf you have a basement or crawlspace underneath your front door you could also mount it on the rafters below the doorHaving the SBC be connected to the internet will help debug issues, keep maintenance easy, and allow for easier addition of new tags


The second option was to use 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.  In the case of a wooden door and frame you will need to bore out a well in the door frame that is large enough for the strike.
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.
{|
{|
|[[image:metaldoorjamb.jpg|thumb|left|500px|link=http://sl/wiki/images/3/3d/Metaldoorjamb.jpg|Metal door jamb with precut whole for a strike plate.  Note that since the frame is hollow wiring can be run through it fairly easily.]]||[[image:wooddoorjamb.jpg|thumb|left|500px|link=http://sl/wiki/images/a/af/Wooddoorjamb.jpg|Wood door jamb with traditional strike plate installed.  This needs to be removed, and a large well cut out for the electric strike.]]
|[[File:metaldoorjamb.jpg|thumb|left|310px|link={{SERVER}}/docs21/images/3/3d/Metaldoorjamb.jpg|Metal door jamb with precut hole for a strike plate.  Note that since the frame is hollow wiring can be run through it fairly easily.]]||[[File:wooddoorjamb.jpg|thumb|right|310px|link={{SERVER}}/docs21/images/a/af/Wooddoorjamb.jpg|Wood door jamb with traditional strike plate installed.  This needs to be removed, and a large hole cut out for the electric strike.]]
|}
|}
Something to note when installing an electric strike particularly into a wooden frame.  Since the device will have some amount of power running through it, it can generate heat.  If you are installing into a wooden frame door then you will need to check with the appropriate authority about fire safety concerns.  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 strike and from the relay to the strike.   
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.   


The layout for the setup is as follows:
This is the functional schematic for the components of this project:<br />
[[File:doorlockblockdiagram.png|600px|link={{SERVER}}/docs21/images/5/54/Doorlockblockdiagram.png]]<br />
This is how it would look in real life<br />
[[File:doorunlockfull.png|600px|link={{SERVER}}/docs21/images/a/aa/Doorunlockfull.png]]


[[image:electricstrike.jpg|850px|link=http://sl/wiki/images/c/c6/Electricstrike.jpg]]
==Software==
We want the program to have the following process flow:


===Software===
[[File:Gliffyflowchart.png|link=|alt=|900px]]
We want the program to have the following structure:
 
[[image:Gliffyflowchart.png]]
 
There are several cases for the software for this project.  They are as follows:
 
{|border = 1
|align=center|'''Case'''||align = center|'''Access Method'''||align = center|'''Unlock Method'''
|-
|1||RFID||Electric Strike
|-
|2||RFID||Motorized Deadbolt
|-
|3||Keypad||Electric Strike
|-
|4||Keypad||Motorized Deadbolt
|}


'''For case 1''', 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.'''
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.


<div class="source">
<div class="source">
Line 104: Line 95:
</div>
</div>


Where ''inFile'' is a File object set to the file in which the tag data is stored.  The data can be read into a file off line prior to installing, or at will with the push of a button or the swipe of a master tag etc... depending on what you prefer.  You can download the full file [http://sl/wiki/images/c/c9/DoorUnlocker.java here].  Note that this code has a mechanism for reading tags into a file though in practice you would want this system to be a bit more robust.  Perhaps by using a database of some kind.  This way you could also log who specifically was accessing the door etc...   
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 [{{SERVER}}/docs21/images/c/c9/DoorUnlocker.java 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:


'''In case 2''', the code will look almost the same except instead of
<div class="source">
<div class="source">
<syntaxhighlight lang=java>
<syntaxhighlight lang=java>
ik.setOutputState(0,true);
delay = new javax.swing.Timer(SHORTDELAY, new ActionListener(){  //SHORTDELAY is an arbitrary number of milliseconds
</syntaxhighlight>
public void actionPerformed(ActionEvent evt){
</div>
try{
ik.setOutputState(0,false);
}
catch(Exception e){}
delay.stop();
}
});


We need to set the motor to the correct position for the unlocked state:


<div class="source">
rfid.addTagLossListener(new TagLossListener()
<syntaxhighlight lang=java>
{
servo.setPosition(0, DOORUNLOCKED);
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){}
}
});
</syntaxhighlight>
</syntaxhighlight>
</div>
</div>


The door's locked and unlocked positions can be determined experimentally once the assembly has been installed. The full code can be downloaded [http://sl/wiki/images/a/a6/DoorUnlocker2.java here].  In this code the settings for DOORLOCKED and DOORUNLOCKED are arbitrary and will not have much bearing on the finished product.


<!--
'''Case 3''' involves a number sequence detection algorithm.  The length of the input sequence is arbitrary.  The interface kit input change handler should look something like this:
'''Case 3''' involves a number sequence detection algorithm.  The length of the input sequence is arbitrary.  The interface kit input change handler should look something like this:


Line 153: Line 159:
</div>
</div>


Where ''UNLOCK'' is whatever (in this case 4 digit long) sequence of numbers you choose.  The rest of the file is available [http://sl/wiki/images/4/43/KeypadUnlocker.java here].
Where ''UNLOCK'' is whatever (in this case 4 digit long) sequence of numbers you choose.  The rest of the file is available [{{SERVER}}/docs21/images/4/43/KeypadUnlocker.java here].
 
-->
'''Case 4''' is almost exactly the same as 3, except that once again we must replace the ik.setOutputState line with code that moves the motor.  Refer to case 2 for more on this.

Latest revision as of 18:35, 7 June 2017

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.

Practical concepts covered are (click on links to see other projects on that topic):  
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 Needed Tools: A selection of screwdrivers, Drill with a large bore drill bit, Fish tape, Exterior Caulk
Phidgets Needed: A 1024 - PhidgetRFID Read/Write, a 1072 - PhidgetSBC2 or 1073 - PhidgetSBC3, and a 3052 - SSR Relay Board
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.

Metal door jamb with precut hole for a strike plate. Note that since the frame is hollow wiring can be run through it fairly easily.
Wood door jamb with traditional strike plate installed. This needs to be removed, and a large hole cut out for the electric strike.

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:
Doorlockblockdiagram.png
This is how it would look in real life
Doorunlockfull.png

Software

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:

delay = new javax.swing.Timer(SHORTDELAY, new ActionListener(){  //SHORTDELAY is an arbitrary number of milliseconds
					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){}
	}
});