Skip to content

Instantly share code, notes, and snippets.

@lpereira
Created January 19, 2012 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpereira/1636774 to your computer and use it in GitHub Desktop.
Save lpereira/1636774 to your computer and use it in GitHub Desktop.
RFID Arduino
// 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