Skip to content

Instantly share code, notes, and snippets.

@pingud98
Created May 31, 2017 17:48
Show Gist options
  • Save pingud98/69f2869614c3fc006c756df4944e313f to your computer and use it in GitHub Desktop.
Save pingud98/69f2869614c3fc006c756df4944e313f to your computer and use it in GitHub Desktop.
Grove RFID reader - recognise a tag and blink LED
//Based on example code from SEEED studio wiki
//for 125kHz GROVE RFID reader
//GPL V3
/*
link between the computer and the SoftSerial Shield
at 9600 bps 8-N-1
Computer is connected to Hardware UART
SoftSerial Shield is connected to the Software UART:D2&D3
*/
#include <SoftwareSerial.h>
SoftwareSerial SoftSerial(2, 3);
unsigned char buffer[64]; // buffer array for data receive over serial port
String intest=""; //input string
char buffchar;
int count = 0; // counter for buffer array
int led = 13;
void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
void loop()
{
// if date is coming from software serial port ==> data is coming from SoftSerial shield
RFIDread();
if (intest.equals("5300C59F363F"))
{
Serial.println(" match "); // if no data transmission ends, write buffer to hardware serial port
Serial.println(intest);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
intest = "";
}
else if (intest.endsWith(""))
{
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
delay(100);
digitalWrite(led, HIGH);
delay(100);
digitalWrite(led, LOW);
Serial.println(intest);
intest="";
}
}
void RFIDread()
{
if (SoftSerial.available())
{
while(SoftSerial.available()) // reading data into char array
{
buffchar = SoftSerial.read(); // writing data into array
//Serial.println(int(buffchar));
intest += buffchar;
if (int(buffchar)= 3)break;
//count++;
// if(buffchar=' ')break;
}
}
}
void clearBufferArray() // function to clear buffer array
{
// clear all index of array with command NULL
for (int i=0; i<count; i++)
{
buffer[i]=NULL;
}
intest = "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment