Access Control w/ Arduino

Posted: May 26, 2011 in Uncategorized
Tags: , , , , ,

Here’s a simple-ish sketch for reading Wiegand access control cards and displaying the card info on a 20×4 LCD. The sketch also contains some testing functionality for access controlled doors. It will check the status of the door position switch as well as the request to exit device and provide feedback about state to the LCD and at the card reader’s LED. This could be used for single person access control system commissioning. Enjoy! This is an old sketch so I apologize that it’s sloppy and almost void of useful comments…. Hopefully you can still find a use for it. More importantly I apologize for not sharing credit for a couple of code excerpts. Please Google “Crazy People Arduino” to see where the inspiration and some of the base sketch came from.

#include
template inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; }

#define rxPin 8
#define txPin 4
#define rexPin 4
#define doorPin 5
#define ledPin 7

volatile long bit_holder = 0;
volatile int bit_count = 0;

long previousMillis = 0;
long interval = 1000;

SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);

void DATA0(void) {
bit_count++;
bit_holder = bit_holder << 1;}

void DATA1(void) {
bit_count++;
bit_holder = bit_holder < interval) {
bit_count = 0; bit_holder = 0;
previousMillis = millis();
delay(10);

mySerial.print(“?f”);
mySerial.print(” REAL TIME STATUS?n”);
mySerial.print(“?n”);

doorStatus = analogRead(doorPin);
doorStatus = (doorStatus/20);
mySerial.print(“Door- “);
if (doorStatus == 4){mySerial.print(“SECURE”);}
else if (doorStatus == 8){mySerial.print(“OPEN”);}
else {mySerial.print(“FAULT”);}

mySerial.print(“?n”);

rexStatus = analogRead(rexPin);
rexStatus = (rexStatus/20);
mySerial.print(“REX- “);
if (rexStatus == 8){mySerial.print(“NORMAL”);}
else if (rexStatus == 4){mySerial.print(“ACTIVE”);}
else {mySerial.print(“FAULT”);}

if (doorStatus == 4 && rexStatus == 8)
{digitalWrite(ledPin, LOW);
delay (1000);}
}

if (bit_count >= 26) {
digitalWrite(ledPin, LOW);
mySerial.print(“?f”);
mySerial.print(“Binary Card Number- “);
mySerial.print(“?n”);
mySerial.print (bit_holder, BIN);
delay (6000);
mySerial.print(“?f”);
mySerial.print(“Card Number- “);
mySerial.print(“?n”);
bit_holder = (bit_holder >> 1) & 0x7fff;
mySerial.print(bit_holder);
delay (2000);

bit_count = 0; bit_holder = 0;
previousMillis = millis();

delay(10); }

if (bit_count) Serial << bit_count << " ";}

void clearinterrupts () {

for(int i = 2; i<4; i++){
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
digitalWrite(i, LOW);
pinMode(i, INPUT);
digitalWrite(i, HIGH);
}
delay(10);}

void InitializeLCD() {

pinMode(txPin, OUTPUT);
mySerial.begin(9600);
mySerial.print("?G420");
delay(100);
mySerial.print("?Bff");
delay(100);
mySerial.print("?c0");
delay(200); mySerial.print("?f");
delay(100);}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s