Hey,
I have been starting to build an RFID access control system based off of this code:
int validSiteCodes[] = {196, 452};
int validSerialNumbers[] = {15809, 3285};// see if site code and serial number are in the lists...
volatile long reader1 = 0;
volatile int reader1Count = 0;
void reader1One(void) {
reader1Count++;
reader1 = reader1 << 1;
reader1 |= 1;
}
void reader1Zero(void) {
reader1Count++;
reader1 = reader1 << 1;
}
void setup()
{
Serial.begin(9600);
// Attach pin change interrupt service routines from the Wiegand RFID readers
attachInterrupt(0, reader1Zero, RISING);//DATA0 to pin 2
attachInterrupt(1, reader1One, RISING); //DATA1 to pin 3
delay(10);
// the interrupt in the Atmel processor mises out the first negitave pulse as the inputs are already high,
// so this gives a pulse to each reader input line to get the interrupts working properly.
// Then clear out the reader variables.
// The readers are open collector sitting normally at a one so this is OK
for(int i = 2; i<4; i++){
pinMode(i, OUTPUT);
digitalWrite(i, HIGH); // enable internal pull up causing a one
digitalWrite(i, LOW); // disable internal pull up causing zero and thus an interrupt
pinMode(i, INPUT);
digitalWrite(i, HIGH); // enable internal pull up
}
delay(10);
// put the reader input variables to zero
reader1 = 0;
reader1Count = 0;
//digitalWrite(13, HIGH); // show Arduino has finished initilisation
}
void loop()
{
if(reader1Count >=26){
//Serial.print(" Reader 1 ");
//Serial.println(reader1,HEX);
// Serial.println("A");
//Serial.println(reader1& 0xfffffff);
int serialNumber=(reader1 >> 1) & 0x3fff;
int siteCode= (reader1 >> 17) & 0x3ff;
Serial.print(siteCode);
Serial.print(" ");
Serial.println(serialNumber);
reader1 = 0;
reader1Count = 0;
if(IsTagValid(siteCode, serialNumber)
){
digitalWrite(13,HIGH);
}
else
digitalWrite(13,LOW);
delay(2000);
digitalWrite(13,LOW); // Open the door. It's cold out here!
}
}
boolean IsTagValid(int siteCode, int serialNumber)
{
boolean valid = false;
// Determine how many valid tags there are
int validTagCount = sizeof(validSiteCodes)/sizeof(int);
// Loop through the arrays to see if siteCode
// and serialNumber are present
for(int t=0; t<validTagCount; t++)
{
if(validSiteCodes[t] == siteCode &&
validSerialNumbers[t] == serialNumber)
{
valid = true;
break;
}
}
return valid;
}
So, I would like to add a couple of functions to this code but I don't exactly know how. First function I would like to add is a website where I can unlock the electric strike, and add cards, as well as view the entry logs. I would be using a ethernet shield to host the website, which would be port forwarded. I would also like to add time restrictions to some cards when I add them on the website, such as card 124-8930 only has access on week days from 7:00am to 8:00pm. Somebody Please give me some help on this!
Thanks and happy New Year!
Anders