RFID Bar application

Apr 18, 2012 4 Comments by

I bought a RFID module that operates on 13.56Mzh a while back and have never really goten around to test it out much, but since this is the last weeks of my master thesis I might as well spend some time finding out how it works.

After googling the device I found no example code for the device, only a lot of resellers that stated that you could get the code after purchasing it. So I contacted the guy who sold me one and I got the code. I found out that my student card operates on the same frequency and that the device is capable of writing to cards, so I had to remove that part of the code in order to dare to use it with my student card.  The complete code example is available here: http://www.b2cqshop.com/best/rfidQ00415203.rar

I modified the code so that it would recognize a card and print a statement depending on wich card it was, after that my loop would look like this:

void loop(){
  uchar i,tmp;
  uchar status;
  uchar str[MAX_LEN];
  uchar RC_size;
  uchar blockAddr;

  status = MFRC522_Request(PICC_REQIDL, str);	//don't know if this line is needed
  status = MFRC522_Anticoll(str);
  memcpy(serNum, str, 5);
    if (status == MI_OK)
    {
    if(serNum[0] == 0x12 && serNum[1] == 0xD7 &&  serNum[2] == 0xAA && serNum[3] == 0x50 && serNum[4] == 0x3F){
       Serial.println("Vodka");
       delay(1000);
    }
     if(serNum[0] == 0x93 && serNum[1] == 0x1F && serNum[2] == 0x40 && serNum[3] == 0xA8 && serNum[4] == 0x64){
       Serial.println("Bacardi");
       delay(1000);
    }
     if(serNum[0] == 0x42 && serNum[1] == 0x15 && serNum[2] == 0x06 && serNum[3] == 0xB7 && serNum[4] == 0xE6){
       Serial.println("Cognac");
       delay(1000);
    }
  }
  MFRC522_Halt();
}

Now it is time to do something fun with all of this, and what is more fun then letting the electronics what you should drink depending on the type of booze you choose. So I wrote a quick and dirty processing application, I didn’t bother to abstract things into methods, I just wanted it to work and display nice results as fast as I could, and in fact the application was done in less then ten minutes, so I was in fact happy with my performance. The code for my processing application is right here:

import processing.serial.*;

Serial myPort;
String val = "";
PImage b;

void setup()
{
  size(600, 400);
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
}

void draw()
{
  if ( myPort.available() > 0) {
    val = myPort.readStringUntil('\n');
    background(255);
    if (val != null) {
      val = trim(val);
      if ( val.equals("Bacardi")) {
        b = loadImage("Bacardi.jpg");
        textSize(32);
        image(b, 0, 0, 300, 400);
        fill(0, 102, 153, 51);
        text("Bacardi", 320, 40);
        fill(0, 102, 153);
        text("Bacardi", 320, 60);
        fill(0, 102, 153, 51);
        text("Bacardi", 320, 80);
        fill(0, 0, 0);

        textSize(24);
        text("Drink Suggestion", 320, 130);
        textSize(22);
        text("Otter Pop", 320, 160);
        textSize(16);
        text("1/2 oz Bacardi® white rum", 320, 200);
        text("1/2 oz Blue Curacao liqueur", 320, 220);
        text("1/4 oz sweet and sour mix", 320, 240);
        text("1/4 oz 7-Up® soda", 320, 260);
      }
      if ( val.equals("Cognac")) {
        b = loadImage("Cognac.jpg");
        image(b, 0, 0, 300, 400);
        textSize(32);
        image(b, 0, 0, 300, 400);
        fill(0, 102, 153, 51);
        text("Braastad XO", 320, 40);
        fill(0, 102, 153);
        text("Braastad XO", 320, 60);
        fill(0, 102, 153, 51);
        text("Braastad XO", 320, 80);       

        fill(0, 0, 0);
        textSize(24);
        text("Drink Suggestion", 320, 130);
        textSize(16);
        text("Pour 4cc in a glass, enjoy", 320, 180);
      }
      if ( val.equals("Vodka")) {
        b = loadImage("vodka.jpg");
        image(b, 0, 0, 300, 400);
        textSize(32);
        image(b, 0, 0, 300, 400);
        fill(0, 102, 153, 51);
        text("Vikingfjord", 320, 40);
        fill(0, 102, 153);
        text("Vikingfjord", 320, 60);
        fill(0, 102, 153, 51);
        text("Vikingfjord", 320, 80);
        fill(0, 0, 0);
        textSize(24);
        text("Drink Suggestion", 320, 130);
        textSize(22);
        text("Vikingfjord Vodka Mojito", 320, 160);
        textSize(16);
        text("2 oz Vikingfjord Vodka", 320, 200);
        text("¾ lime cut into wedges", 320, 220);
        text("8-10 mint leaves", 320, 240);
        text("granulated cane sugar", 320, 260);
      }
    }
  }
}

Now I taped my tags underneath three bottles, and when I scanned them processing displayed a picture of the bottle and a recipe on a drink made with that type of booze. The video have some glitching and weird zoom effects, but that is just youtube trying to fix my shaky hand.

And screenshots from the program:

The next step in this project is to get hold of a lot more tags, stick them to all the bottles. Fill up a database with a lot of recipes. Make a random recipe chooser, and of course buy a big house with a bar section and build everything into the bar.

App, Arduino, DIY, Processing

About the author

Sometime I write, sometime I don't. But most of the time I program, build a curcuit or just do something completely different.

4 Responses to “RFID Bar application”

  1. rick retter says:

    hi. do you have the source code and could you email it to me please? the link in your article is broken. thank you.

  2. SJManta says:

    Hi Could you provide the full code you used to achieve this. I have the B2CQ code, but I’m not sure how you integrated the processing application. Is it in the same sketch or a different one? Where do you store the specific ID card names for comparison?

    • Jan Ole says:

      Hi, I do unfortunately not have easy access to the code any more. But if you have have access to the B2CQ code, then you probobly already know how to scan the RFID tags and displaying their number. In the arduino scetch, each card is hard coded in in theese if statements: if(serNum[0] == 0×42 && serNum[1] == 0×15 && serNum[2] == 0×06 && serNum[3] == 0xB7 && serNum[4] == 0xE6)

      So you manually have to split the RFID cards ID and hardcode them in, elternately send the complete ID to processing and handle it there.

      As for the Processing integration, I just used simple serial communication, there is a simple example on how to do that here:
      http://playground.arduino.cc/Interfacing/Processing

      I hope you figure it out :)

Leave a Reply to rick retter

Cancel Reply