Good morning everyone.
I just finally got an Arduino when SparkFun had their Free Day. ;D
Well, I had an RS232 RFID reader from Parallax and a 4x20 Blue/White LCD with a serial backpack laying around and decided to try something that I haven't tried in a while. I thought I would put them all together and see if I could get them to work together like good little children. :-/
Well, I got them to play nice but I still have a problem. The rfid reader reads the tags and sends the numbers to the arduino. The arduino checks the tags to see if it matches the one stored. If it matches, it lights up an led to simulate a door lock and tells you it's a good tag on the screen then resets. If it doesn't match, it tells you so on the screen then resets.
What I need help with is being able to have more than one tag number stored and be able to search through them all to see if the scanned tag matches any of the stored numbers. When I was using my PicAxe, I had no problem with that. I just don't know how to do it on the Arduino.
If anyone can help, I would be SOOooooooooo grateful.
I have included my code below. Any ideas on cleaning it up would be great too.
Thanx in advance.
Dan
// rfid_security.pde
// By Daniel Wright
// 2010.JAN 22
// daniel@thewrightproject.com
// www.thewrightproject.com
// This is a simple security system using the following hardware:
// Arduino Duemilanove + Parallax RS232 RFID Reader + 4x20 LCD with Serial Backpack
// The system waits for an RFID tag to be scanned and then verifies if it is valid. If it is valid, it displays
// a message on the screen indicating that it is valid and opens a door lock(red led for now).
// If it is invalid it says so on the screen and resets.
// The firmware currently only has one rfid tag coded into it as I don't yet know how to create a database
// and be able to check multiple tag numbers for a good one. That's coming as soon as I figure it out.
#include <SoftwareSerial.h>
#define TAG_LEN 12
char tag[12] = {'0', 'F', '0', '3', '0', '2', '8', '4', '8', '8'};
int val = 0;
char code[12];
int bytesread = 0;
#define rxPin 8 // RFID reader SOUT pin connected to Serial RX pin 8
#define txPin 9 //Not used but needs declaring
#define rxPinl 4 //Not used but needs declaring
#define txPinl 14 //Output on Analog 0 to LCD
void setup()
{
delay(3000); // pause to allow LCD to start up
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, HIGH); // De-Activate the RFID reader
pinMode(7,OUTPUT); // Set digital pin 7 as OUTPUT to connect to Door Striker
digitalWrite(7, LOW); // De-Activate the Door Striker
pinMode(txPinl, OUTPUT); //Set Analog pin 0 as output to LCD
}
void loop()
{
// SoftwareSerial setup for LCD
SoftwareSerial mySerial = SoftwareSerial(rxPinl, txPinl);
mySerial.begin(2400); // Software serial for LCD 2400bps
mySerial.print("?G420"); // set display geometry, 4 x 20 characters in this case
delay(500); // pause to allow LCD EEPROM to program
mySerial.print("?Bff"); // set backlight to ff hex, maximum brightness
delay(1000); // pause to allow LCD EEPROM to program
mySerial.print("?s6"); // set tabs to six spaces
delay(1000); // pause to allow LCD EEPROM to program
mySerial.print("?f"); // clear the LCD
delay(10);
digitalWrite(2, LOW); // Activate the RFID reader
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
mySerial.print("RFID Security");
delay(500);
mySerial.print("?x00?y3"); // move cursor to beginning of line 3
mySerial.print("Please Scan Tag....");
// SoftwareSerial setup for RFID reader
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);
// Main program functions start here
if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.read();
if((val == 10)||(val == 13))
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
if(bytesread == 10)
if(strcmp(code, tag) == 0) {
// if 10 digit read is complete
digitalWrite(2, HIGH); // De-Activate the RFID reader
mySerial.print("?f"); // clear the LCD
delay(10);
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
mySerial.print("RFID Tag Valid");
mySerial.print("?x00?y2"); // move cursor to beginning of line 2
mySerial.print("Tag #: ");
mySerial.print(code); // print the TAG code
digitalWrite(7, HIGH); // De-Activate the RFID reader
delay(3000); // wait for a couple seconds
digitalWrite(7, LOW); // De-Activate the RFID reader
}
else {
digitalWrite(2, HIGH); // De-Activate the RFID reader
mySerial.print("?f"); // clear the LCD
delay(10);
mySerial.print("?x00?y1"); // move cursor to beginning of line 1
mySerial.print("RFID Tag Invalid!");
delay(3000);
}
bytesread = 0;
mySerial.print("?f"); // clear the LCD
delay(500);
mySerial.print("?x00?y2"); // move cursor to beginning of line 2
mySerial.print("Please Wait....");
}
}