Created
January 19, 2012 00:36
-
-
Save lpereira/1636774 to your computer and use it in GitHub Desktop.
RFID Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Ebay RFID decoder by Aaron Christiansen | |
// Original article: http://thetransistor.com/2011/10/hacking-cheap-rfid-readers/ | |
// Optimizations by Leandro Pereira | |
// NOTE: this uses the NewSoftwareSerial beta 11 | |
// by Mikal Hart, available here: | |
// http://arduiniana.org/2011/01/newsoftserial-11-beta/ | |
#include <SoftwareSerial.h> | |
SoftwareSerial rfid(7, 4); | |
void setup(){ | |
rfid.begin(9600); | |
Serial.begin(9600); | |
} | |
void loop(){ | |
if (rfid.available()) { | |
int len; | |
char *in; | |
in = readRFID(&len); | |
if (!len) return; | |
Serial.print("Read RFID; len="); | |
Serial.print(len); | |
Serial.print("; code="); | |
Serial.println(in); | |
} | |
} | |
char* readRFID(int *length) | |
{ | |
static char output[10]; | |
unsigned long timer = millis() + 250; | |
int index = 0; | |
while (index < sizeof(output) && timer > millis()) { | |
if (!rfid.available()) continue; | |
const int temp = rfid.read(); | |
if (temp >= 29 && temp <= 39) | |
output[index++] = (temp - 29) % 10 + '0'; | |
} | |
rfid.flush(); | |
*length = index; | |
return output; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment