ID-12 RFID reader set-up with an arduino and Spark Core

Hello :smile:

We are a group of students from Denmark who are currently trying to store RFID Data from an ID-12 reader to a cloud server somehow. We would like to list these ID’s and acces them with a web application.

Here is our current setup:

So far we have setup the Arduino with the ID-12 reader so that when a registered tag is read, a green LED flashes.

This is done with this Arduino code:

int RFIDResetPin = 12;

//Register your RFID tags here
char tag1[13] = "4D006A7AFDA0";
char tag2[13] = "4D006A7AFDA0";
char tag3[13] = "4D006A7AFDA0";
char tag4[13] = "4D006AC4C82B";
char tag5[13] = "01023C0A4376";
char tag6[13] = "4D006AA52DAF";
char tag7[13] = "01023C0A3207";
char tag8[13] = "4D006";
char tag9[13] = "4D006AC";
char tag10[13] = "4D006AC4C";

void setup(){
  Serial.begin(9600);

  pinMode(RFIDResetPin, OUTPUT);
  digitalWrite(RFIDResetPin, HIGH);


  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop(){


  char tagString[13];
  int index = 0;
  boolean reading = false;

  while(Serial.available()){

    int readByte = Serial.read(); //read next available byte

    if(readByte == 2) reading = true; //begining of tag
    if(readByte == 3) reading = false; //end of tag

    if(reading && readByte != 2 && readByte != 10 && readByte != 13){
      //store the tag
      tagString[index] = readByte;
      index ++;
    }
  }

  checkTag(tagString); //Check if it is a match
  clearTag(tagString); //Clear the char of all value
  resetReader(); //eset the RFID reader
}

void checkTag(char tag[]){
  ///////////////////////////////////
  //Check the read tag against known tags
  ///////////////////////////////////

  if(strlen(tag) == 0) return; //empty, no need to contunue

  if(compareTag(tag, tag1)){ // if matched tag1, do this
    lightLED(2);
    Serial.println("Brown Elastic");

  }
  else if(compareTag(tag, tag2)){ //if matched tag2, do this
    lightLED(2);


  }
  else if(compareTag(tag, tag3)){
    lightLED(2);



  }
  else if(compareTag(tag, tag4)){
    lightLED(2);
    Serial.println("Yellow Clip");

  }
  else if(compareTag(tag, tag5)){
    lightLED(2);


  }
  else if(compareTag(tag, tag6)){
    lightLED(2);
    Serial.println("Green Clip");


  }
  else if(compareTag(tag, tag7)){
    lightLED(2);


  }
  else if(compareTag(tag, tag8)){
    lightLED(2);

  }
  else if(compareTag(tag, tag9)){
    lightLED(2);

  }
  else if(compareTag(tag, tag10)){
    lightLED(2);

  }
  else{
    lightLED(5);
    Serial.println(tag); //read out any unknown tag

  }

}

void lightLED(int pin){
  ///////////////////////////////////
  //Turn on LED on pin "pin" for 250ms
  ///////////////////////////////////
  Serial.println(pin);

  digitalWrite(pin, HIGH);
  delay(750);
  digitalWrite(pin, LOW);
}

void resetReader(){
  ///////////////////////////////////
  //Reset the RFID reader to read again.
  ///////////////////////////////////
  digitalWrite(RFIDResetPin, LOW);
  digitalWrite(RFIDResetPin, HIGH);
  delay(150);
}

void clearTag(char one[]){
  ///////////////////////////////////
  //clear the char array by filling with null - ASCII 0
  //Will think same tag has been read otherwise
  ///////////////////////////////////
  for(int i = 0; i < strlen(one); i++){
    one[i] = 0;
  }
}

boolean compareTag(char one[], char two[]){
  ///////////////////////////////////
  //compare two value to see if same,
  //strcmp not working 100% so we do this
  ///////////////////////////////////

  if(strlen(one) == 0) return false; //empty

  for(int i = 0; i < 12; i++){
    if(one[i] != two[i]) return false;
  }

  return true; //no mismatches
}

This is our tags(125khz):

We are able to print the tag ID in serial (Serial.println() ) via RX on the arduino, which is great. However we need to send this information to a web application.

We feel that this should be fairly simple since that we only want to add() the tag to a list, if scanned. And remove() it again if it is scanned again.

We have read @bko tutorials about “Reading Spark Variables with Your Own HTML File” and “Using Spark.publish() with Simple JSON Data”. Which were great, and we were wondering if it were possible to read the RFID data to a HTML file(like the temperature example)?

We should probably wire the ID-12 up with the Spark Core, and thus eliminating the need to the Arduino entirely, but the communication would still be via serial, so we feel that wouldn’t really do much for us.

We are quite new to the whole Spark Core/Server side of things, so any input would be greatly appreciated(links, tutorials, general discussion)

Thanks! :smile:

1 Like