0% found this document useful (0 votes)
30 views

Arduino RFID Door Lock

The document describes building an Arduino-based RFID door lock system. It uses an Arduino microcontroller, RFID reader, and electric door strike to unlock a door when a valid RFID tag is scanned. The system stores authorized tag IDs in EEPROM memory. A master tag can add new tags to memory, allowing access without reprogramming. Code is provided to control an RGB LED for status and unlock the door for 5 seconds when a valid tag is scanned.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Arduino RFID Door Lock

The document describes building an Arduino-based RFID door lock system. It uses an Arduino microcontroller, RFID reader, and electric door strike to unlock a door when a valid RFID tag is scanned. The system stores authorized tag IDs in EEPROM memory. A master tag can add new tags to memory, allowing access without reprogramming. Code is provided to control an RGB LED for status and unlock the door for 5 seconds when a valid tag is scanned.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Arduino RFID Door Lock

***Updated 8/9/2010***
I wanted to make an easy and secure way to enter my garage. RFID was the
best way to unlock my door, even with my hands full I can unlock the door and
push it open! I built a simple circuit with a basic ATMega 168 arduino chip and a
ID-20 RFID reader to control an electronic door lock.

The circuit consists of 3 separate parts, a Reader to read RFID tags, a Controller
to accept data from the reader and control the output of the RGB LED and the
Electric door lock. The door lock is first installed in a door and tested with a 9v
battery to ensure correct installation. In most cases you want a Normally Open
circuit on the door lock, or Fail Secure. This means the door stays locked when
no current passes through it. When 12vDC is passed through the electromagnet
in the door lock, a plate in the lock gives way and allows the door to be pushed
open freely.
The reader is placed on the outside of the door and is separate from the
controller on the inside so that no one can circumvent the security by breaking
open the Reader and trying to short circuit the reader. The controller receives
serial data from the Reader and controls the RGB led and the Door lock. In this
case I have put both on separate bread boards for testing. Here is a video
overview of the system in action Read on to see how to build one for your self!

**Update**
All of the code, schematics, and PCB designs have been tested and refined.
They are all posted here as of 8/9/2010
Updated video of the final system installed and working.

Remove these ads by Signing Up

Step 1: Parts Needed

Here are a list of parts and links to SparkFun.com where I bought them. This is
the basic set of parts you need to build and arduino and a circuit to read RFID
tags into the arduino. I am assuming you have a breadboard, power supply and
hookup wires already.
Arduino Stuff
ATmega168 with Arduino Bootloader $4.95
Crystal 16MHz $1.50
Capacitor Ceramic 22pF $0.25 (x2)
Resistor 10k Ohm 1/6th Watt PTH $0.25
Mini Push Button Switch $0.35

Triple Output LED RGB - Diffused $1.95


RFID stuff
Either one of these, 20 has better range, 12 is smaller
RFID Reader ID-12 $29.95
RFID Reader ID-20 $34.95
RFID Reader Breakout $0.95
Break Away Headers - Straight $2.50
RFID Tag - 125kHz $1.95
Other
TIP31A transistor (radio shack/local electronics store $1.50)
Door Lock is from ebay.
Door Fail Secure access control Electric Strike v5 NO $17.50 (kawamall, bay)

Step 2: Build the Arduino controller

The first step to building a RFID door lock with a basic Arduino is to bread board
out a basic working arduino. Most Arduino pre-flashed ATMega 168 chips come
with the default blink program pre installed. Connect a LED to digital output 13
and verify that everything is working.
The hardware portion of this RFID reader would be too simple if we used a
regular arduino with built in USB programmer. Since I plan on putting this into the
wall and not touching it again I dont want to use a big bulky $30 arduino board
when I can buy a $5 ATMega 168 and make a much smaller custom PCB.
Because I chose to make a basic Arduino circuit myself I need an external USB>Serial FDIT programmer. I have included Eagle schematics of the controller with
a power supply built from a 7805 voltage regulator. In testing I used a bread
board power supply.
To get an arduino up and running all you really need is the ATMega168 with the
arduino software flashed on it, 2x 22pF capacitors, 16mhz crystal, 10k ohm
resistor, push button and a breadboard. The hookup for this is well known but
I have included the entire schematic for the circuit.
The arduino is going to trigger 4 outputs, 1 each for Red/Green/Blue LEDs, and 1
to trigger the TIP31A to send 12vDC to the door lock. The arduino receives serial
data in on its Rx line from the ID-20 RFID reader.

Controller_PCB.pdf(612x792) 12 KB

Step 3: Build the RFID Reader

Now that you have your arduino bread boarded and working you can put together
the RFID reader portion of the circuit that will contain the ID-10 or ID-20 and RGB
LED to indicate the status of the circuit. Remember that the reader will be outside
and separate from the controller inside so that someone cannot easily break in.
To build this, we are going to send 5v/Ground over from the primary bread board
to a secondary bread board we are building the Reader on. Also send over 3
wires from 3 of the arduino output pins to control the RGB LED, one for each
color. One more wire, Brown in the pictures, will be a serial connection for the ID20 to talk to the arduino's Rx serial input. This is a very simple circuit to connect.
LED's get resistors and a few points on the ID-20 are tied to ground/5v to set the
correct status.
To make it easier to breadboard the ID-10/ID-20 Sparkfun sells a Breakout board
that allows you to attach longer pin headers that are spaced to fit a bread board.
This part and the pinheaders and listed in the parts list.
The schematic should be strait forward and easy to follow.

reader_PCB.pdf(612x792) 8 KB

Step 4: Program!
Time to program your arduino. This can be a bit tricky using a basic arduino, you
may have to press the reset button multiple times before and during the first part
of the upload. A very important thing to remember, you WILL get an upload error
if you do no temporarily disconnect the ID-20 serial line to the arduino's Rx line.
The ATMega168 only has 1 Rx input and it uses it to upload code to talk to the
programmer. Disconnect the ID-20 while programming then plug it back in when
your done. I used a FTDI programmer which allows you to program the arduino
via USB with only 4 wires. The Controller schematic shows a pin header
connection to allow you to plug one in directly. Sparkfun also sells this part but
many may already have it.
You can easily upload my code to your arduino and never look back but whats
the fun in that? Let me explain the basic idea of how it works.
First of all, I did not want any external buttons/switches/etc and I did not want to
reprogram the arduino every time I wanted to add a new card. Therefore

I wanted to use only RFID to control the operation of the circuit as well as control
over the door lock.
The program turns on the Blue LED to indicate it is ready to read a new card.
When the card is read it decides if it is a valid card or not by comparing what it
read in to a list of valid cards. If the user is valid, the arduino turns OFF the Blue
LED and turns on the Green LED for 5 seconds. It also turns on another output
high for 5 seconds. This output is connected to the TIP31A transistor and allows
the tiny arduino to control a much larger 12v 300mA door lock without being
damaged. After 5 seconds the door lock re-locks and the LED turns back to blue
to wait for another card to be read. If the card is invalid then the LED changes to
RED for a few seconds and back to Blue to wait for another card.
It is important that the door lock still work even if the arduino loses power
overnight or is reset. Therefore all valid card ID's are stored in
EEPROM memory. The ATMega168 has 512 Bytes of EEPROM memory. Each
RFID card has a 5 Hex Byte serial number and a 1 Hex Byte Check sum that we
can use to verify there were no errors in the transmission between the ID-20 and
the arduino.
Valid cards are stored in the EEPROM by using the first Byte as a counter. For
example, if there are 3 valid cards stored the first Byte in the EEPROM would be
3. EEPROM.read(0); = 3. Knowing this, and the fact that each ID is 5 Bytes long
we know that 1-5 is card one, 6-10 is card 2 and 11-15 is card 3. We can make a
loop that looks through the EEPROM 5 bytes at a time and tries to find the card
that was read in by the reader.
But how can we add new cards to the EEPROM after the circuit is installed??
I have read in one of the RFID cards I have and hard coded it to be the Master
RFID card. So even if the entire EEPROM is wiped the master card will still
function. Whenever a card is read, it checks first to see if it is the Master card, if
not, then it continues to see if it is a valid card or not. If the card is the master
card we have the arduino go into a "programming mode" where it flashes RGB
and waits for another valid tag to be read. The next tag that is read is added to
the next free spot in the EEPROM and the counter is incremented 1 if the card
does not already exist in the EEPROM memory. The reader then returns to
normal mode and waits for a new card to be read.
Currently I have not programmed a way to delete a card as the reasons for
deleting a card would most likely be it was lost or stolen. As this would most likely
be used with 1-10 people the easiest thing to do would be to hard program a

Master Erase card that will wipe all cards from the EEPROM then re add them
all, which only takes a few seconds. I have added code to wipe the EEPROM but
I have not implemented this feature yet. .
The code is attached in a text file along with a copy of the parts list.

RFIDLock.txt16 KB
Updated_Code.txt22 KB

Step 5: Expand
This is only some of the cool stuff you can do with RFID. You could expand this
much further with a LCD output, logging of who enters and when, network/twitter
connection etc. I plan on making a finished PCB version of this circuit. I have
never made a PCB before so I am still working on the design and layout of the
parts. Once I have them complete I will post them as well. I encourage anyone to
take the code I have written and modify it to do even more cool things!

/*
RFID Door Lock
10/13/2009
Brett Martin
www.pcmofo.com
System for controlling access by reading 125khz RFID cards and compairing the
ID tags to stored EEPROM values
Master RFID card used to program new cards into the system.
ID-12/ID-12 RFID reader
Using sparkfun breakout board
[1] GND (Ground)
[2] /RST (Reset Reader) Connect to +5vDC
[3] ANT (NC)
[4] ANT (NC)
[5] CP (NC) (Card Present)
[6] NC
[7] FS (Format select) (ground this for ASCII)
[8] D1 (NC)
[9] D0 (TTL Serial) to arduino RX
[10] Buzzer/LED (Card read indicator) (Connect to transistor + buzzer/led to
indicate card was read)
[11] 5v+ ( +5vDC power)
On Arduino....
[3] (Digital OUT)
[4] (Digital OUT)
[5] (Digital OUT)
[6] (Digital OUT)
[RX0] (Serial IN)

to
to
to
to
to

Blue LED+
Red LED+
Green LED+
lock relay+
[9] D0 TTL serial out on ID-20

// Based on code by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>


// and code from HC Gilje http://hcgilje.wordpress.com/resources/rfid_id12_tagreader/
// Modified for Arudino by djmatic
// Modified for ID-12 and checksum by Martijn The - http://www.martijnthe.nl/
//
// Use the drawings from HC Gilje to wire up the ID-12.
// Remark: disconnect the rx serial wire to the ID-12 when uploading the
sketch
*/
#include <EEPROM.h> // Needed to write to EEPROM storage
#define
#define
#define
#define

powerPin
failPin
passPin
doorPin

10
11
12
13

boolean programMode = false;


boolean match = false;

byte storedCard[6];
byte readCard[6];
byte checksum = 0;

// Stores an ID read from EEPROM


// Sotres an ID read from the RFID reader
// Stores the checksum to verify the ID

void setup()
{
// for (int i = 0; i < 512; i++) // Uncoment to wipe the EEPROM
//
EEPROM.write(i, 0);
pinMode(powerPin, OUTPUT);
// Connected to Blue on tri-color LED to
indicate reader is ready
pinMode(passPin, OUTPUT);
// Connected to Green on tri-color LED to
indicate user is valid
pinMode(failPin, OUTPUT);
// Connected to Green on tri-color LED to
indicate user is NOT valid or read failed
pinMode(doorPin, OUTPUT);
// Connected to relay to activate the door
lock
Serial.begin(9600);
// Connect to the serial port
}
void loop ()
{
byte val = 0;

// Temp variable to hold the current byte

normalModeOn();

// Normal mode, blue Power LED is on, all others are off

if ( programMode)
// Program mode to add a new ID card
{
programModeOn(); // Program Mode cycles through RGB waiting to read a new
card
if(Serial.available() > 0)
{
if((val = Serial.read()) ==
{
getID();
if ( !isMaster(readCard) )
card
{
writeID(readCard);
programMode = false;
checksum = 0;
}
}
}
}
// Normal Operation...
else
{
if(Serial.available() > 0)
sending data...
{
if((val = Serial.read()) ==
{
getID();
byte bytesread = 0;

// Waits for something to come on the serial line


2)

// First Byte should be 2, STX byte


// Get the ID, sets readCard = to the read ID
// Check to see if it is the master programing

// If not, write the card to the EEPROM sotrage


// Turn off programing mode
// Make sure the checksum is empty

// If the serial port is available and


2)

// First Byte should be 2, STX byte


// Get the ID, sets readCard = to the read ID

for ( int i = 0; i < 5; i++ )


{
if ( readCard[i] < 16 )
Serial.print("0");
Serial.print(readCard[i], HEX);
Serial.print(" ");
}
Serial.println();
Serial.print("Checksum: ");
Serial.print(readCard[5], HEX);

// Loop 5 times
// Print out 0 if < 16 to prepend output
// Print out the hex value read in

// Checksum read from the card

if ( readCard[5] == checksum )
// See if the 5th BYTE (the checksum)
read in from the reader
{
// matches the checksum caculated
checksum = 0;
// If so, we can empty the variable
storing the calculated checksum
//Serial.println(" passed");
//Serial.println();
if ( isMaster( readCard ) )
// Check to see if the card is the master
programing card
{
programMode = true;
// If so, enable programing mode
}
else
{
if ( findID(readCard) )
// If not, see if the card is in the EEPROM
{
openDoor(5);
// If it is, open the door lock
}
else
{
failed();
// If not, show that the ID was not valid
}
}
}
else
// If the checksum failed
{
// Print out the checksum
/*
Serial.println(" error");
Serial.println();
Serial.print("[");
Serial.print(readCard[5], HEX);
Serial.print("] != [");
Serial.print(checksum, HEX);
Serial.print("] ");
*/
}
}
}
}
}
// If the serial port is ready and we received the STX BYTE (2) then this
function is called
// to get the 4 BYTE ID + 1 BYTE checksum. The ID+checksum is stored in
readCard[6]

// Bytes 0-4 are the 5 ID bytes, byte 5 is the checksum


void getID()
{
byte bytesread = 0;
byte i = 0;
byte val = 0;
byte tempbyte = 0;
// 5 HEX Byte code is actually 10 ASCII Bytes.
while ( bytesread < 12 ) // Read 10 digit code + 2 digit checksum
{
if( Serial.available() > 0)
// Check to make sure data is coming on the
serial line
{
val = Serial.read();
// Store the current ASCII byte in val
if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02))
{
// If header or stop bytes before the 10 digit
reading
break;
// Stop reading
}
if ( (val >= '0' ) && ( val <= '9' ) )
// Do Ascii/Hex conversion
{
val = val - '0';
}
else if ( ( val >= 'A' ) && ( val <= 'F' ) )
{
val = 10 + val - 'A';
}
if ( bytesread & 1 == 1 )
// Every two ASCII charactors = 1 BYTE in HEX
format
{
// Make some space for this hex-digit by
// shifting the previous hex-digit with 4 bits to the left:
readCard[bytesread >> 1] = (val | (tempbyte << 4));
if ( bytesread >> 1 != 5 )
{
checksum ^= readCard[bytesread >> 1];
};
}
else
charactor
{
tempbyte = val;
};
bytesread++;
track
}
}
bytesread = 0;
}

// If we're at the checksum byte,


// Calculate the checksum using XOR
// If it is the first HEX
// Store the HEX in a temp variable
// Increment the counter to keep

// Read an ID from EEPROM and save it to the storedCard[6] array

void readID( int number ) // Number = position in EEPROM to get the 5 Bytes
from
{
int start = (number * 5 ) - 4; // Figure out starting position
//Serial.print("Start: ");
//Serial.print(start);
//Serial.print("\n\n");
for ( int i = 0; i < 5; i++ ) // Loop 5 times to get the 5 Bytes
{
storedCard[i] = EEPROM.read(start+i); // Assign values read from EEPROM to
array
/*
Serial.print("Read [");
Serial.print(start+i);
Serial.print("] [");
Serial.print(storedCard[i], HEX);
Serial.print("] \n");
*/
}
}
// Write an array to the EEPROM in the next available slot
void writeID( byte a[] )
{
if ( !findID( a ) )
// Before we write to the EEPROM, check to see if
we have seen this card before!
{
int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores
the number of ID cards
/*
Serial.print("Num: ");
Serial.print(num);
Serial.print(" \n");
*/
int start = ( num * 5 ) + 1;
// Figure out where the next slot starts
num++;
EEPROM.write( 0, num );

// Increment the counter by one


// Write the new count to the counter

for ( int j = 0; j < 5; j++ ) // Loop 5 times


{
EEPROM.write( start+j, a[j] ); // Write the array values to EEPROM in the
right position
/*
Serial.print("W[");
Serial.print(start+j);
Serial.print("] Value [");
Serial.print(a[j], HEX);
Serial.print("] \n");
*/
}
successWrite();
}
else
{
failedWrite();

}
}
// Check two arrays of bytes to see if they are exact matches
boolean checkTwo ( byte a[], byte b[] )
{
if ( a[0] != NULL )
// Make sure there is something in the array
first
match = true;
// Assume they match at first
for ( int k = 0; k < 5; k++ ) // Loop 5 times
{
/*
Serial.print("[");
Serial.print(k);
Serial.print("] ReadCard [");
Serial.print(a[k], HEX);
Serial.print("] StoredCard [");
Serial.print(b[k], HEX);
Serial.print("] \n");
*/
if ( a[k] != b[k] )
// IF a != b then set match = false, one fails,
all fail
match = false;
}
if ( match )
// Check to see if if match is still true
{
//Serial.print("Strings Match! \n");
return true;
// Return true
}
else {
//Serial.print("Strings do not match \n");
return false;
// Return false
}
}
// Looks in the EEPROM to try to match any of the EEPROM ID's with the passed
ID
boolean findID( byte find[] )
{
int count = EEPROM.read(0);
// Read the first Byte of EEPROM that
// Serial.print("Count: ");
// stores the number of ID's in
EEPROM
// Serial.print(count);
//Serial.print("\n");
for ( int i = 1; i <= count; i++ )
// Loop once for each EEPROM entry
{
readID(i);
// Read an ID from EEPROM, it is stored
in storedCard[6]
if( checkTwo( find, storedCard ) )
// Check to see if the storedCard read
from EEPROM
{
// is the same as the find[] ID card
passed
//Serial.print("We have a matched card!!! \n");
return true;
break;
// Stop looking we found it
}

else
// If not, return false
{
//Serial.print("No Match here.... \n");
}
}
return false;
}
// Opens door and turns on the green LED for setDelay seconds
void openDoor( int setDelay )
{
setDelay *= 1000; // Sets delay in seconds
digitalWrite(powerPin, LOW);
digitalWrite(failPin, LOW);
digitalWrite(passPin, HIGH);
digitalWrite(doorPin, HIGH);

//
//
//
//

Turn off blue LED


Turn off red LED
Turn on green LED
Unlock door!

delay(setDelay); // Hold door lock open for 5 seconds


digitalWrite(doorPin, LOW); // Relock door
digitalWrite(passPin, LOW); // Turn off green LED
}
// Flashes Red LED if failed login
void failed()
{
digitalWrite(passPin, LOW);
// Make sure green LED is off
digitalWrite(powerPin, LOW); // Make sure blue LED is off
// Blink red fail LED 3 times to indicate failed key
digitalWrite(failPin, HIGH); // Turn on red LED
delay(500);
digitalWrite(failPin, LOW);
// Turn off red LED
digitalWrite(failPin, HIGH);
delay(500);
digitalWrite(failPin, LOW);

// Turn on red LED

digitalWrite(failPin, HIGH);
delay(500);
digitalWrite(failPin, LOW);
}

// Turn on red LED

// Turn off red LED

// Turn off red LED

// Check to see if the ID passed is the master programing card


boolean isMaster( byte test[] )
{
byte bytesread = 0;
byte i = 0;
// Example card, replace with one of yours you want
to be the master
byte val[10] = {'2','4','0','0','C','A','5','7','8','4' };
byte master[6];
byte checksum = 0;
byte tempbyte = 0;
bytesread = 0;

for ( i = 0; i < 10; i++ ) // First we need to convert the array above into a
5 HEX BYTE array
{
if ( (val[i] >= '0' ) && ( val[i] <= '9' ) )
// Convert one char to HEX
{
val[i] = val[i] - '0';
}
else if ( (val[i] >= 'A' ) && ( val[i] <= 'F' ) )
{
val[i] = 10 + val[i] - 'A';
}
if (bytesread & 1 == 1) // Every two hex-digits, add byte to code:
{
// make some space for this hex-digit by
// shifting the previous hex-digit with 4 bits to the left:
master[bytesread >> 1] = (val[i] | (tempbyte << 4));
if (bytesread >> 1 != 5)
{
checksum ^= master[bytesread >> 1];
};
}
else
{
tempbyte = val[i];
};
bytesread++;
}
if ( checkTwo( test, master ) )
the test ID
return true;
else
return false;
}

// If we're at the checksum byte,


// Calculate the checksum... (XOR)

// Store the first hex digit first...

// Check to see if the master =

// Controls LED's for Normal mode, Blue on, all others off
void normalModeOn()
{
digitalWrite(powerPin, HIGH);
// Power pin ON and ready to read card
digitalWrite(passPin, LOW);
// Make sure Green LED is off
digitalWrite(failPin, LOW);
// Make sure Red LED is off
digitalWrite(doorPin, LOW);
// Make sure Door is Locked
}
// Controls LED's for program
void programModeOn()
{
digitalWrite(powerPin, LOW);
digitalWrite(failPin, LOW);
digitalWrite(passPin, HIGH);
delay(200);
digitalWrite(powerPin, LOW);
digitalWrite(failPin, HIGH);
digitalWrite(passPin, LOW);
delay(200);

mode, cycles through RGB


// Make sure blue LED is off
// Make sure blue LED is off
// Make sure green LED is on
// Make sure blue LED is off
// Make sure blue LED is on
// Make sure green LED is off

digitalWrite(powerPin, HIGH); // Make sure blue LED is on


digitalWrite(failPin, LOW);
// Make sure blue LED is off
digitalWrite(passPin, LOW);
// Make sure green LED is off
delay(200);
}
// Flashes the green LED 3 times to indicate a successful write to EEPROM
void successWrite()
{
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(failPin, LOW); // Make sure blue LED is off
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
}
// Flashes the red LED 3 times to indicate a failed write to EEPROM
void failedWrite()
{
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(failPin, HIGH); // Make sure red LED is on
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(failPin, LOW); // Make sure red LED is off
delay(200);
digitalWrite(failPin, HIGH); // Make sure red LED is on
delay(200);
digitalWrite(failPin, LOW); // Make sure red LED is off
delay(200);
digitalWrite(failPin, HIGH); // Make sure red LED is on
delay(200);
}
/*
ATmega168 with Arduino Bootloader $4.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8846
Crystal 16MHz $1.50
http://www.sparkfun.com/commerce/product_info.php?products_id=536
Capacitor Ceramic 22pF $0.25 (x2)
http://www.sparkfun.com/commerce/product_info.php?products_id=8571
Capacitor Ceramic 0.1uF $0.25
http://www.sparkfun.com/commerce/product_info.php?products_id=8375
Resistor 10k Ohm 1/6th Watt PTH $0.25
http://www.sparkfun.com/commerce/product_info.php?products_id=8374
Mini Push Button Switch $0.35

http://www.sparkfun.com/commerce/product_info.php?products_id=97
Triple Output LED RGB - Diffused $1.95
http://www.sparkfun.com/commerce/product_info.php?products_id=9264
RFID Reader ID-12 $29.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8419
RFID Reader ID-20 $34.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8628
RFID Reader Breakout $0.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8423
Break Away Headers - Straight $2.50
http://www.sparkfun.com/commerce/product_info.php?products_id=116
RFID Tag - 125kHz $1.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8310
Door Fail Secure access control Electric Strike v5 NO $17.50 (kawamall, bay)
http://cgi.ebay.com/Door-Fail-Secure-access-control-Electric-Strike-v5NO_W0QQitemZ350230332833QQcmdZViewItemQQptZLH_DefaultDomain_0?
hash=item518b5ac5a1#ht_3787wt_1167
*/

/*
RFID Door Lock
10/13/2009
Brett Martin
www.pcmofo.com
Modified by Usama on 21st July 2010 for extra features.....
System for controlling access by reading 125khz RFID cards and compairing the
ID tags to stored EEPROM values
Master RFID card used to program new cards into the system.
ID-12/ID-12 RFID reader
Using sparkfun breakout board
[1] GND (Ground)
[2] /RST (Reset Reader) Connect to +5vDC
[3] ANT (NC)
[4] ANT (NC)
[5] CP (NC) (Card Present)
[6] NC
[7] FS (Format select) (ground this for ASCII)
[8] D1 (NC)
[9] D0 (TTL Serial) to arduino RX
[10] Buzzer/LED (Card read indicator) (Connect to transistor + buzzer/led to
indicate card was read)
[11] 5v+ ( +5vDC power)
On Arduino....
[10] (Digital OUT) to Blue LED+
[11] (Digital OUT) to Red LED+
[12] (Digital OUT) to Green LED+
[13] (Digital OUT) to Alarm+
[9] (Digital OUT) to lock relay+
[RX0] (Serial IN) to [9] D0 TTL serial out on ID-20
// Based on code by BARRAGAN
// and code from HC Gilje http://hcgilje.wordpress.com/resources/rfid_id12_tagreader/
// Modified for Arudino by djmatic
// Modified for ID-12 and checksum by Martijn The - http://www.martijnthe.nl/
// Modified for Deleting cards and wiping memory and alarm by Usama.....
//
// Use the drawings from HC Gilje to wire up the ID-12.
// Remark: disconnect the rx serial wire to the ID-12 when uploading the
sketch
*/
#include // Needed to write to EEPROM storage
#define
#define
#define
#define
#define

powerPin 10 // Blue LED


failPin 11 // Red LED
passPin 12 // Grenn LED
doorPin 9 // Relay
alarmPin 13 // Alarm

boolean
boolean
boolean
boolean

programMode = false; // Initialize program mode to false


deleteMode = false; // Initialize delete mode to false
wipeMode = false; // Initialize wipe mode to false
match = false; // initialize card match to false

byte storedCard[6]; // Stores an ID read from EEPROM


byte readCard[6]; // Sotres an ID read from the RFID reader
byte checksum = 0; // Stores the checksum to verify the ID
int alarm = 0; // Extra Security
void setup()
{
pinMode(powerPin, OUTPUT); // Connected to Blue on tri-color LED to indicate
reader is ready
pinMode(passPin, OUTPUT); // Connected to Green on tri-color LED to indicate
user is valid
pinMode(failPin, OUTPUT); // Connected to Red on tri-color LED to indicate
user is NOT valid or read failed
pinMode(doorPin, OUTPUT); // Connected to relay to activate the door lock
pinMode(alarmPin, OUTPUT); // Connected to alarm
alarm = 0;
Serial.begin(9600); // Connect to the serial port
}
void loop ()
{
byte val = 0; // Temp variable to hold the current byte
normalModeOn(); // Normal mode, blue Power LED is on, all others are off
if (alarm == 3)
{
digitalWrite(alarmPin, HIGH); // Alarm!
Serial.begin(9600);
if(Serial.available() > 0) // Waits for something to come on the serial line
{
if((val = Serial.read()) == 2) // First Byte should be 2, STX byte
{
getID(); // Get the ID, sets readCard = to the read ID
if ( isMaster(readCard) ) // Check to see if it is the master programing card
or delete card
{
digitalWrite(alarmPin, LOW);
alarm = 0;
checksum = 0;
}
else
checksum = 0;
}
}
checksum=0;
}
else
{
if ( programMode) // Program mode to add a new ID card

{
programModeOn(); // Program Mode cycles through RGB waiting to read a new card
if(Serial.available() > 0) // Waits for something to come on the serial line
{
if((val = Serial.read()) == 2) // First Byte should be 2, STX byte
{
getID(); // Get the ID, sets readCard = to the read ID
if ( isMaster(readCard) || isDelete(readCard) || isWipe(readCard)) // Check to
see if it is the master programing card or delete card
{
programMode = false;
if (isMaster(readCard))
openDoor(2);
else
failedWrite();
checksum = 0;
}
else
{
writeID(readCard); // If not, write the card to the EEPROM sotrage
programMode = false; // Turn off programing mode
checksum = 0; // Make sure the checksum is empty
}
}
}
}
else if ( deleteMode ) // Delete mode to delete an added ID card
{
deleteModeOn(); // Delete Mode cycles through RB waiting to read a new card
if(Serial.available() > 0) // Waits for something to come on the serial line
{
if((val = Serial.read()) == 2) // First Byte should be 2, STX byte
{
getID(); // Get the ID, sets readCard = to the read ID
if ( isMaster(readCard) || isDelete(readCard) || isWipe(readCard) ) // Check
to see if it is the master programing card or the Delete Card
{
deleteMode = false;
checksum = 0;
failedWrite();
}
else //if ( !isMaster(readCard) && !isDelete(readCard) )
{
deleteID(readCard); // If not, delete the card from the EEPROM sotrage
deleteMode = false; // Turn off delete mode
checksum = 0; // Make sure the checksum is empty
}
}
}
}
else if ( wipeMode ) // Wipe mode to wipe out the EEPROM
{
Serial.end();
wipeModeOn();
for (int i = 0; i < 512; i++) // Loop repeats equal to the number of array in
EEPROM
{

EEPROM.write(i, 0);
}
wipeMode = false;
wipeModeOn();
Serial.begin(9600);
}
// Normal Operation...
else
{
if(Serial.available() > 0) // If the serial port is available and sending
data...
{
if((val = Serial.read()) == 2) // First Byte should be 2, STX byte
{
getID(); // Get the ID, sets readCard = to the read ID
byte bytesread = 0;
for ( int i = 0; i < 5; i++ ) // Loop 5 times
{
if ( readCard[i] < 16 ) // Print out 0 if < 16 to prepend output
Serial.print("0");
Serial.print(readCard[i], HEX); // Print out the hex value read in
Serial.print(" ");
}
Serial.println();
Serial.print("Checksum: ");
Serial.print(readCard[5], HEX); // Checksum read from the card
if ( readCard[5] == checksum ) // See if the 5th BYTE (the checksum) read in
from the reader
{ // matches the checksum caculated
checksum = 0; // If so, we can empty the variable storing the calculated
checksum
//Serial.println(" passed");
//Serial.println();
if ( isMaster( readCard ) ) // Check to see if the card is the master
programing card
{
programMode = true; // If so, enable programing mode
alarm = 0;
}
else if ( isDelete( readCard ) ) // Check to see if the card is the deletion
card
{
deleteMode = true; // If so, enable deletion mode
alarm = 0;
}
else if ( isWipe( readCard ) ) // Check to see if the card is the deletion
card
{
wipeMode = true; // If so, enable deletion mode
alarm = 0;
}
else
{
if ( findID(readCard) ) // If not, see if the card is in the EEPROM
{
openDoor(2); // If it is, open the door lock
alarm = 0;

}
else
{
failed(); // If not, show that the ID was not valid
alarm++;
}
}
}
else // If the checksum failed
{ // Print out the checksum
/*
Serial.println(" error");
Serial.println();
Serial.print("[");
Serial.print(readCard[5], HEX);
Serial.print("] != [");
Serial.print(checksum, HEX);
Serial.print("] ");
*/
}
}
}
}
}
}
// If the serial port is ready and we received the STX BYTE (2) then this
function is called
// to get the 4 BYTE ID + 1 BYTE checksum. The ID+checksum is stored in
readCard[6]
// Bytes 0-4 are the 5 ID bytes, byte 5 is the checksum
void getID()
{
byte bytesread = 0;
byte i = 0;
byte val = 0;
byte tempbyte = 0;
// 5 HEX Byte code is actually 10 ASCII Bytes.
while ( bytesread < 12 ) // Read 10 digit code + 2 digit checksum
{
if( Serial.available() > 0) // Check to make sure data is coming on the serial
line
{
val = Serial.read(); // Store the current ASCII byte in val
if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02))
{ // If header or stop bytes before the 10 digit reading
break; // Stop reading
}
if ( (val >= '0' ) && ( val <= '9' ) ) // Do Ascii/Hex conversion
{
val = val - '0';
}
else if ( ( val >= 'A' ) && ( val <= 'F' ) )
{
val = 10 + val - 'A';
}
if ( bytesread & 1 == 1 ) // Every two ASCII charactors = 1 BYTE in HEX format

{
// Make some space for this hex-digit by
// shifting the previous hex-digit with 4 bits to the left:
readCard[bytesread >> 1] = (val | (tempbyte << 4));
if ( bytesread >> 1 != 5 ) // If we're at the checksum byte,
{
checksum ^= readCard[bytesread >> 1]; // Calculate the checksum using XOR
};
}
else // If it is the first HEX charactor
{
tempbyte = val; // Store the HEX in a temp variable
};
bytesread++; // Increment the counter to keep track
}
}
bytesread = 0;
}
// Read an ID from EEPROM and save it to the storedCard[6] array
void readID( int number ) // Number = position in EEPROM to get the 5 Bytes
from
{
int start = (number * 5 ) - 4; // Figure out starting position
//Serial.print("Start: ");
//Serial.print(start);
//Serial.print("\n\n");
for ( int i = 0; i < 5; i++ ) // Loop 5 times to get the 5 Bytes
{
storedCard[i] = EEPROM.read(start+i); // Assign values read from EEPROM to
array
/*
Serial.print("Read [");
Serial.print(start+i);
Serial.print("] [");
Serial.print(storedCard[i], HEX);
Serial.print("] \n");
*/
}
}
// Write an array to the EEPROM in the next available slot
void writeID( byte a[] )
{
if ( !findID( a ) ) // Before we write to the EEPROM, check to see if we have
seen this card before!
{
int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores
the number of ID cards
/*
Serial.print("Num: ");
Serial.print(num);
Serial.print(" \n");
*/
int start = ( num * 5 ) + 1; // Figure out where the next slot starts
num++; // Increment the counter by one
EEPROM.write( 0, num ); // Write the new count to the counter

for ( int j = 0; j < 5; j++ ) // Loop 5 times


{
EEPROM.write( start+j, a[j] ); // Write the array values to EEPROM in the
right position
/*
Serial.print("W[");
Serial.print(start+j);
Serial.print("] Value [");
Serial.print(a[j], HEX);
Serial.print("] \n");
*/
}
successWrite();
}
else
{
failedWrite();
}
}
// Delete an array stored in EEPROM from the designated slot
void deleteID( byte a[] )
{
if ( !findID( a ) ) // Before we delete from the EEPROM, check to see if we
have this card!
{
failedWrite(); // If not
}
else
{
int num = EEPROM.read(0); // Get the numer of used spaces, position 0 stores
the number of ID cards
int slot; // Figure out the slot number of the card
int start;// = ( num * 5 ) + 1; // Figure out where the next slot starts
int looping; // The number of times the loop repeats
int j;
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
// Serial.print("Count: "); // stores the number of ID's in EEPROM
// Serial.print(count);
//Serial.print("\n");
slot = findIDSLOT( a ); //Figure out the slot number of the card to delete
start = (slot * 5) - 4;
looping = ((num - slot) * 5);
num--; // Decrement the counter by one
EEPROM.write( 0, num ); // Write the new count to the counter
for ( j = 0; j < looping; j++ ) // Loop the card shift times
{
EEPROM.write( start+j, EEPROM.read(start+5+j)); // Shift the array values to 5
places earlier in the EEPROM
/*
Serial.print("W[");
Serial.print(start+j);
Serial.print("] Value [");
Serial.print(a[j], HEX);
Serial.print("] \n");

*/
}
for ( int k = 0; k < 5; k++ ) //Shifting loop
{
EEPROM.write( start+j+k, 0);
}
successDelete();
}
}
// Find the slot number of the id to be deleted
int findIDSLOT( byte find[] )
{
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
// Serial.print("Count: "); // stores the number of ID's in EEPROM
// Serial.print(count);
//Serial.print("\n");
for ( int i = 1; i <= count; i++ ) // Loop once for each EEPROM entry
{
readID(i); // Read an ID from EEPROM, it is stored in storedCard[6]
if( checkTwo( find, storedCard ) ) // Check to see if the storedCard read from
EEPROM
{ // is the same as the find[] ID card passed
//Serial.print("We have a matched card!!! \n");
return i; // The slot number of the card
break; // Stop looking we found it
}
}
}
// Check two arrays of bytes to see if they are exact matches
boolean checkTwo ( byte a[], byte b[] )
{
if ( a[0] != NULL ) // Make sure there is something in the array first
match = true; // Assume they match at first
for ( int k = 0; k < 5; k++ ) // Loop 5 times
{
/*
Serial.print("[");
Serial.print(k);
Serial.print("] ReadCard [");
Serial.print(a[k], HEX);
Serial.print("] StoredCard [");
Serial.print(b[k], HEX);
Serial.print("] \n");
*/
if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail
match = false;
}
if ( match ) // Check to see if if match is still true
{
//Serial.print("Strings Match! \n");
return true; // Return true
}
else {

//Serial.print("Strings do not match \n");


return false; // Return false
}
}
// Looks in the EEPROM to try to match any of the EEPROM ID's with the passed
ID
boolean findID( byte find[] )
{
int count = EEPROM.read(0); // Read the first Byte of EEPROM that
// Serial.print("Count: "); // stores the number of ID's in EEPROM
// Serial.print(count);
//Serial.print("\n");
for ( int i = 1; i <= count; i++ ) // Loop once for each EEPROM entry
{
readID(i); // Read an ID from EEPROM, it is stored in storedCard[6]
if( checkTwo( find, storedCard ) ) // Check to see if the storedCard read from
EEPROM
{ // is the same as the find[] ID card passed
//Serial.print("We have a matched card!!! \n");
return true;
break; // Stop looking we found it
}
else // If not, return false
{
//Serial.print("No Match here.... \n");
}
}
return false;
}
// Opens door and turns on the green LED for setDelay seconds
void openDoor( int setDelay )
{
setDelay *= 1000; // Sets delay in seconds
Serial.end();
digitalWrite(powerPin, LOW); // Turn off blue LED
digitalWrite(failPin, LOW); // Turn off red LED
digitalWrite(passPin, HIGH); // Turn on green LED
digitalWrite(doorPin, HIGH); // Unlock door!
delay(setDelay); // Hold door lock open for 2 seconds
digitalWrite(doorPin, LOW); // Relock door
delay(setDelay); // Hold green LED om for 2 more seconds
digitalWrite(passPin, LOW); // Turn off green LED
Serial.begin(9600);
}
// Flashes Red LED if failed login
void failed()
{
Serial.end();
digitalWrite(passPin, LOW); // Make sure green LED is off

digitalWrite(powerPin, LOW); // Make sure blue LED is off


// Blink red fail LED 3 times to indicate failed key
digitalWrite(failPin, HIGH); // Turn on red LED
delay(1200);
Serial.begin(9600);
}
// Check to see if the ID passed is the master programing card
boolean isMaster( byte test[] )
{
byte bytesread = 0;
byte i = 0; // Example card, replace with one of yours you want to be the
master
byte val[10] = {'2','9','0','0','9','4','0','F','F','3' };
byte master[6];
byte checksum = 0;
byte tempbyte = 0;
bytesread = 0;
for ( i = 0; i < 10; i++ ) // First we need to convert the array above into a
5 HEX BYTE array
{
if ( (val[i] >= '0' ) && ( val[i] <= '9' ) ) // Convert one char to HEX
{
val[i] = val[i] - '0';
}
else if ( (val[i] >= 'A' ) && ( val[i] <= 'F' ) )
{
val[i] = 10 + val[i] - 'A';
}
if (bytesread & 1 == 1) // Every two hex-digits, add byte to code:
{
// make some space for this hex-digit by
// shifting the previous hex-digit with 4 bits to the left:
master[bytesread >> 1] = (val[i] | (tempbyte << 4));
if (bytesread >> 1 != 5) // If we're at the checksum byte,
{
checksum ^= master[bytesread >> 1]; // Calculate the checksum... (XOR)
};
}
else
{
tempbyte = val[i]; // Store the first hex digit first...
};
bytesread++;
}
if ( checkTwo( test, master ) ) // Check to see if the master = the test ID
return true;
else
return false;
}
// Check to see if the ID passed is the wipe memory card
boolean isWipe( byte test[] )
{
byte bytesread = 0;

byte i = 0; // Example card, replace with one of yours you want to be the
master
byte val[10] = {'2','9','0','0','9','3','D','8','7','F' };
byte master[6];
byte checksum = 0;
byte tempbyte = 0;
bytesread = 0;
for ( i = 0; i < 10; i++ ) // First we need to convert the array above into a
5 HEX BYTE array
{
if ( (val[i] >= '0' ) && ( val[i] <= '9' ) ) // Convert one char to HEX
{
val[i] = val[i] - '0';
}
else if ( (val[i] >= 'A' ) && ( val[i] <= 'F' ) )
{
val[i] = 10 + val[i] - 'A';
}
if (bytesread & 1 == 1) // Every two hex-digits, add byte to code:
{
// make some space for this hex-digit by
// shifting the previous hex-digit with 4 bits to the left:
master[bytesread >> 1] = (val[i] | (tempbyte << 4));
if (bytesread >> 1 != 5) // If we're at the checksum byte,
{
checksum ^= master[bytesread >> 1]; // Calculate the checksum... (XOR)
};
}
else
{
tempbyte = val[i]; // Store the first hex digit first...
};
bytesread++;
}
if ( checkTwo( test, master ) ) // Check to see if the master = the test ID
return true;
else
return false;
}
// Check to see if the ID passed is the deletion card
boolean isDelete( byte test[] )
{
byte bytesread = 0;
byte i = 0; // Example card, replace with one of yours you want to be the
deletion
byte val[10] = {'2','9','0','0','9','4','2','0','4','2' };
byte master[6];
byte checksum = 0;
byte tempbyte = 0;
bytesread = 0;
for ( i = 0; i < 10; i++ ) // First we need to convert the array above into a
5 HEX BYTE array
{
if ( (val[i] >= '0' ) && ( val[i] <= '9' ) ) // Convert one char to HEX
{

val[i] = val[i] - '0';


}
else if ( (val[i] >= 'A' ) && ( val[i] <= 'F' ) )
{
val[i] = 10 + val[i] - 'A';
}
if (bytesread & 1 == 1) // Every two hex-digits, add byte to code:
{
// make some space for this hex-digit by
// shifting the previous hex-digit with 4 bits to the left:
master[bytesread >> 1] = (val[i] | (tempbyte << 4));
if (bytesread >> 1 != 5) // If we're at the checksum byte,
{
checksum ^= master[bytesread >> 1]; // Calculate the checksum... (XOR)
};
}
else
{
tempbyte = val[i]; // Store the first hex digit first...
};
bytesread++;
}
if ( checkTwo( test, master ) ) // Check to see if the delete = the test ID
return true;
else
return false;
}
// Controls LED's for Normal mode, Blue on, all others off
void normalModeOn()
{
digitalWrite(powerPin, HIGH); // Power pin ON and ready to read card
digitalWrite(passPin, LOW); // Make sure Green LED is off
digitalWrite(failPin, LOW); // Make sure Red LED is off
digitalWrite(doorPin, LOW); // Make sure Door is Locked
}
// Controls LED's for program mode, cycles through RGB
void programModeOn()
{
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(failPin, LOW); // Make sure blue LED is off
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(failPin, HIGH); // Make sure blue LED is on
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(powerPin, HIGH); // Make sure blue LED is on
digitalWrite(failPin, LOW); // Make sure blue LED is off
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
}
// Controls LED's for delete mode, cycles through RB
void deleteModeOn()
{

digitalWrite(powerPin, LOW); // Make sure blue LED is off


digitalWrite(failPin, HIGH); // Make sure red LED is on
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(powerPin, HIGH); // Make sure blue LED is on
digitalWrite(failPin, LOW); // Make sure red LED is off
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
}
// Flashes the green LED 3 times to indicate a successful write to EEPROM
void successWrite()
{
Serial.end();
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(failPin, LOW); // Make sure red LED is off
digitalWrite(passPin, LOW); // Make sure green LED is on
delay(200);
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
Serial.begin(9600);
}
// Flashes the red LED 3 times to indicate a failed write to EEPROM
void failedWrite()
{
Serial.end();
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(failPin, LOW); // Make sure red LED is on
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(failPin, HIGH); // Make sure red LED is on
delay(200);
digitalWrite(failPin, LOW); // Make sure red LED is off
delay(200);
digitalWrite(failPin, HIGH); // Make sure red LED is on
delay(200);
digitalWrite(failPin, LOW); // Make sure red LED is off
delay(200);
digitalWrite(failPin, HIGH); // Make sure red LED is on
delay(200);
Serial.begin(9600);
}
// Flashes the blue LED 3 times to indicate a success delete to EEPROM
void successDelete()
{
Serial.end();
digitalWrite(powerPin, LOW); // Make sure blue LED is off

digitalWrite(failPin, LOW); // Make sure red LED is off


digitalWrite(passPin, LOW); // Make sure green LED is on
delay(200);
digitalWrite(powerPin, HIGH); // Make sure blue LED is off
delay(200);
digitalWrite(powerPin, LOW); // Make sure blue LED is off
delay(200);
digitalWrite(powerPin, HIGH); // Make sure blue LED is off
delay(200);
digitalWrite(powerPin, LOW); // Make sure blue LED is off
delay(200);
digitalWrite(powerPin, HIGH); // Make sure blue LED is off
delay(200);
Serial.begin(9600);
}
// Controls LED's for wipe mode, cycles through BG
void wipeModeOn()
{
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(failPin, LOW); // Make sure red LED is off
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(50);
digitalWrite(powerPin, HIGH); // Make sure blue LED is on
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
digitalWrite(powerPin, HIGH); // Make sure blue LED is on
digitalWrite(passPin, LOW); // Make sure green LED is off
delay(200);
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(passPin, HIGH); // Make sure green LED is on
delay(200);
digitalWrite(powerPin, LOW); // Make sure blue LED is off
digitalWrite(passPin, LOW); // Make sure green LED is on
delay(200);
digitalWrite(failPin, HIGH); // Make sure green LED is on
}
/*
ATmega168 with Arduino Bootloader $4.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8846
Crystal 16MHz $1.50
http://www.sparkfun.com/commerce/product_info.php?products_id=536
Capacitor Ceramic 22pF $0.25 (x2)
http://www.sparkfun.com/commerce/product_info.php?products_id=8571
Capacitor Ceramic 0.1uF $0.25
http://www.sparkfun.com/commerce/product_info.php?products_id=8375
Resistor 10k Ohm 1/6th Watt PTH $0.25
http://www.sparkfun.com/commerce/product_info.php?products_id=8374

Mini Push Button Switch $0.35


http://www.sparkfun.com/commerce/product_info.php?products_id=97
Triple Output LED RGB - Diffused $1.95
http://www.sparkfun.com/commerce/product_info.php?products_id=9264
RFID Reader ID-12 $29.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8419
RFID Reader ID-20 $34.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8628
RFID Reader Breakout $0.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8423
Break Away Headers - Straight $2.50
http://www.sparkfun.com/commerce/product_info.php?products_id=116
RFID Tag - 125kHz $1.95
http://www.sparkfun.com/commerce/product_info.php?products_id=8310
Door Fail Secure access control Electric Strike v5 NO $17.50 (kawamall, bay)
http://cgi.ebay.com/Door-Fail-Secure-access-control-Electric-Strike-v5NO_W0QQitemZ350230332833QQcmdZViewItemQQptZLH_DefaultDomain_0?
hash=item518b5ac5a1#ht_3787wt_1167
*/

You might also like