It took some staring at the cryptic documentation and the web site below to figure out the circuit, so I drew it up, since the drawings elsewhere were awful and had errors.
Thanks to http://hcgilje.wordpress.com/resources/rfid_id12_tagreader/ for the head start.
- Rewrote the code so that it keeps a list of tags to be granted access.
- Upgraded to arduino-0021, and replaced the add on NewSoftSerial library with the built in SoftwareSerial libarary. The built in library is not as good as the add on, but it makes it easier for others to get my code running.
- Used a prototype shield and made a permanent hardware version with some LEDs
Photo of the Arduino with the proto shield stacked on top. The RFID module is soldered to a breakout board which is in turn soldered to the prototype shield. Indicator LEDs are installed sticking up high so they will poke out of the box when done.
The unit placed inside the bottom half of the Sparkfun project box. This box fits an Arduino perfectly. If I had the project to do over again, I'd have put the RFID module on the other end of the prototype board so it was centered in the box. I built the unit while i was waiting for the box to come, and didn't plan this ahead properly. I was thinking I might put a small LCD readout on the end of the prototype board, that is why I did it this way. In the end the LCD wasn't really useful and I deleted it.
I'm going to repeat information in the previous post on the prototype version, so the writeup is all in one place.
The RFID module reads out serial ASCII data, and all you have to do is connect that output to a pin on the Arduino. You use the SoftwareSerial library to be able to define any pin as a serial input. Otherwise you have to use the TX/RX pins, and that interferes with serial communication to the computer. Set the RFID reader serial speed to 9600 baud. Other speeds i found spewed garbage.
The sketch looks for codes and compares them to a valid list. I can't imagine anyone could pull the compiled code off the microcontroller to see the list of valid tags. Plus the RFID reader has a good 5 inches of range, so you can put the reader INSIDE the door if you want. It even reads from the back of the RFID module.
I found the reader only reads the tags from Sparkfun. It does not read HID tags (at least the ones I have), it does not read pet chips, or Metro smartcards. I was disappointed as a hacker, but the project still works great.You could add a data logger or an ethernet shield if you want to save a record of what tags were read or send that information across the internet.
Parts List:
The datasheet is here:
http://www.sparkfun.com/datasheets/Sensors/ID-12-Datasheet.pdf
The ID-12 is functionally identical, with a smaller range and uses less power. Pick that one for a battery operated project, or if range isn't important.
http://www.sparkfun.com/commerce/product_info.php?products_id=8310
Parts List:
- Used the RFID Reader ID-20 from Sparkfun:
The datasheet is here:
http://www.sparkfun.com/datasheets/Sensors/ID-12-Datasheet.pdf
The ID-12 is functionally identical, with a smaller range and uses less power. Pick that one for a battery operated project, or if range isn't important.
- This little breakout board for the RFID module is worth the $0.95 to make the pins plug into the breadboard.
- I got a couple of these tags for $1.95 each. RFID Tag - 125kHz. Even if you have your own tags, i'd get one to be sure the reader is working when you build it.
http://www.sparkfun.com/commerce/product_info.php?products_id=8310- Of course you need an Arduino Duemilanove or Uno from http://www.sparkfun.com/commerce/product_info.php?products_id=666 for $25,
- My favorite prototype shield from adafruit $6
- stacking headers $1.50
- A red LED, a green LED, 2 1kohm resistors and a switch for reset. If you don't have the miscellaneous stuff, you can get all this with the protoboard from Adafruit if you buy the proto kit for $12.50.
- A project box. This box is made for the Arduino and is easy to drill. Kinda pricey at 11.95 but I needed something I wouldn't be embarrassed to see hanging on my wall. Arduino and shield drop right in. http://www.sparkfun.com/commerce/product_info.php?products_id=10088
These electric door locks look like they should work, I haven't tried yet. Likely it will need a relay or transistor to boost the current to activate the lock, like an LM293
Electric Door Strike - Mortise Type
This was much cheaper, so i ended up getting this instead. It is really for autos but worked fine.
The sketch code follows the break...
//updated to work with arduino-0021 and Arduino Uno
#include <SoftwareSerial.h>
///format (input, output)
//only the input is used in this example, output is unused
SoftwareSerial SoftwareSerial(8, 2);
int cardPresent = 9; //input from RFID module - not using this
int led_red = 13; //indicates a card was scanned, 1K resistor and red LED to gnd
int led_green = 12; //indicates valid access card, 1K resistor and green LED to gnd
int lock_pin = 10; //connection to solenoid
int speaker = 11; //beeper speaker
String tagstring, validtag1, validtag2, validtag3; //storage of valid tag numbers
char tag [12]; //string to collect the tag being read
int charnum = 0; //index of char number
char someChar;
void setup()
{
Serial.begin(57600);
Serial.println("RFID Reader Active");
pinMode(cardPresent, INPUT);
pinMode(led_red, OUTPUT);
pinMode(led_green, OUTPUT);
digitalWrite(led_red, LOW);
digitalWrite(led_green, LOW);
digitalWrite(lock_pin, LOW);
tone(speaker, 440, 200); //I'm alive beep
//List of tags to grant access, expand as needed
validtag1 = "2400F9914905";
validtag2 = "240012345678";
validtag3 = "240087654321";
// set the data rate for the SoftSerial port, only 9600 seems to work
SoftwareSerial.begin(9600);
}
void loop() // run over and over again
{
// listen for new serial coming in:
someChar = SoftwareSerial.read();
// pull out just the characters that are the tag ID and pack the array
if (charnum != 0) tag[charnum - 1] = someChar;
charnum++;
if (charnum == 13 ) {
charnum = 0;
Serial.print("Tag Detected: ");
Serial.println(tag);
tagstring = String(tag);
if (tagstring.equals(validtag1) | tagstring.equals(validtag2) | tagstring.equals(validtag3)) {
// This tag is valid
Serial.println("Access Granted");
digitalWrite(led_green, HIGH);
digitalWrite(lock_pin, HIGH);
tone(speaker, 1200, 300);
delay(2000);
digitalWrite(led_green, LOW);
digitalWrite(lock_pin, LOW);
} else {
// This tag is not on the list!
Serial.println("No Access");
digitalWrite(led_red, HIGH);
tone(speaker, 440, 300);
delay(300);
digitalWrite(led_red, LOW);
}
}
}
where would i connect the rfid reader? What pins?
ReplyDeleteI am glad to be a visitor of this consummate web site! , appreciate it for this rare info ! . starnfc
ReplyDeleteFor example, hay is a very tricky thing to harvest. If you cut it too soon it can be too wet and go mouldy, if you cut it just a week too late it can go stale and be worth much less money. https://www.farmpally.com/rfid-technology-in-agriculture/
ReplyDeleteGreat information! I??ve been looking for such as this for a little bit now. Thanks! electrical contractors in biloxi
ReplyDelete