The first idea that I have had is to create an RFID reader that plays music when the right tag has been read the reason for this is to allow you to listen to your favourite Playlist with the greatest amount of speed without ever having to approach your stereo or laptop. I want to then be able to control this from your phone. I have no Idea if this is even possible but I will start with some research to see if it can be achieved.
What will I need?
I have an Arduino that I have programmed that allows me to read tags from a transponder Below is the piece of code that I have programmed it with and a photograph of what the reader looks like when it has been set up. I want to create a piece of software that allows me to access media files on my computer with the use of a transponder to call up the various media.
/* RFID ID12 */ char val = 0; // variable to store the data from the serial port void setup() { Serial.begin(9600); // connect to the serial port } void loop () { // read the serial port if(Serial.available() > 0) { val = Serial.read(); Serial.print(val, BYTE); } }
This is the ID-12 RFID Reader which is used with Arduino to read various tags that transmits at a frequency of 125kHz
This picture shows some of the wiring used to make it work and below is the schematic of how the reader is connected to the Arduino
To create this software I am going to use a language called processing, processing is an open source language and programming environment that allows you to create animations, images and interactions. Processing and Arduino have been built to communicate with each other very well and allows you to create many great interactive projects for prototyping. This is why I have chosen to build Home Scan using these tools.
After spending hours trying to get a piece of code that will work I have come up with this piece below. It works very effectively and it allows me to open up any file or program on my computer. It has been a long process getting there, at first when I scanned a tag related to the link I wanted to open I ended up opening hundreds of url’s which overloaded my laptops memory and caused it to crash. I have modified this code below to allow me to call on links when a unique tag has been read.
/* import processing.serial.*; import cc.arduino.*; Serial myPort; String tagID = “”; void setup(){ size (600, 200); println(Serial.list()); String portnum=Serial.list()[0]; myPort = new Serial(this, portnum, 9600); myPort.buffer(16); Pfont myFont= createFont(Pfont.list()[2],24); textFont(myFont); } void draw(){ background(0); println (tagID); if(tagID.equals(“000000024C”)) //I Tag { link(“http://www.homescan.org/recipe.html”);//link to be called when tag is read tagID =””; } if (tagID.equals(“”)) { //link (“C:/Users/Brian/Desktop/RFIDAdventureS1.swf”); tagID=””; } if (tagID.equals(“1F001AA747”)) { //link (“C:/Users/Brian/Desktop/RFIDAdventure.swf”); tagID=””; } } void serialEvent(Serial myPort){ String inputString= myPort.readString(); tagID = parseString(inputString); } String parseString (String thisString) { String tagString=””; char firstChar =thisString.charAt(0); char lastChar =thisString.charAt(thisString.length()-1); if ((firstChar==0x02) && (lastChar ==0x03)){ tagString= thisString.substring(1,11); } return tagString; }
Now that I have the code and hardware working the way I want it to I need to link it up to the correct files that I want to play. I have decided to use a band called Muse to signify my music play list and Marina and the Diamonds to represent my girlfriends playlist so that the demo shows how it would work if the house had multiple occupants. I also would like to use key fobs as well as the iPhone to start music and videos the reason for this is that children that are too young to work a phone, DVD player or stereo can access their favourite CD’s or videos by swiping it over the home scan reader.
I have found an application that is going to work perfectly to control the media on my computer to represent how the home scan phone app would work if it was taken past the prototyping stages. The application is called mobile mouse pro and costs about £1.50 from the app store. This app allows me to control media players such as Gom by customising the interface to play pause fast forward and skip music and video. Below is a photo graph of what the interface looks like.
So I have created the media interface but I would like home scan to do more than just call on links from my computer, I envision the use of RFID technology in the future to be a part of our everyday lives at home work and play. I am focusing mostly on how I think it will be used in our homes and what devices we will control with it. I would like to use a lighting system that can be activated using RFID for this I will use some led’s and a piece of code that will allow the Arduino to read a tag and use that information to activate the light. The piece of code that I have been working on can be found below.
#includeNewSoftSerial rfidSerial = NewSoftSerial(8,7); char code[20]; int ledPin = 9; int ledPin1 = 10; int val = 0; int bytesread = 0; char ledOn1[] = "1F001AAC16";//1 //Led 1 On char ledOff1[] ="1F001A9DB6";//2 //Led 1 Off char ledOn2[] = "2800189B40";//3 //Led 2 on char ledOff2[] = "280018B406";//4 //Led 2 Off void setup() { Serial.begin(9600); //open serial rfidSerial.begin(9600); //open serial pinMode ((13), OUTPUT); pinMode(ledPin, OUTPUT); pinMode(ledPin1, OUTPUT); } void loop() {byte brightness; if (Serial.available()) { // read the most recent byte (which will be from 0 to 255): brightness = Serial.read(); // set the brightness of the LED: analogWrite(ledPin, brightness); analogWrite(ledPin1, brightness);} val = 0; if(rfidSerial.available() > 0) { if((val = rfidSerial.read()) == 2) { // check for header bytesread = 0; while(bytesread < 10) if( rfidSerial.available() > 0) { // read 12 digit code val = rfidSerial.read(); if(val == 3) { // if header or stop bytes before the 10 digit reading break; // stop reading } if(val != 2) { code[bytesread] = val; // add the digit bytesread++; // ready to read next digit code[bytesread] = '\0'; // add the NULL } } if(bytesread >= 10) { for(int i=0; i 0) { //pos=map(val,0,12,0,179); //myservo.write(val); //value *= 10; //value = (Serial.read());// //delay(100); brightness = Serial.read(); // set the brightness of the LED: analogWrite(ledPin, brightness); analogWrite(ledPin1, brightness); } } } } int FindValidTag(char *code) { if(strcmp(code, ledOn1) == 0){ digitalWrite(9, HIGH); digitalWrite (10, HIGH); return 1; } else if(strcmp(code, ledOff1) == 0){ digitalWrite(9, LOW); digitalWrite (10, LOW); return 2; } else if(strcmp(code, ledOn2) == 0){ digitalWrite(10, HIGH); return 1; } else if(strcmp(code, ledOff1) == 0){ digitalWrite(10, LOW); return 2; } else{ return 0; } }
In order to control the brightness of the light I first tried to use processing, processing allowed me to use the x coordinates of the mouse to change the brightness, the window I was presented with was very limited in size and only gave me 256 x 196px as the active area I could hover my mouse over.
Below is the code I used in processing to make this possible
import processing.serial.*; Serial port; void setup() { size(256, 150); println(“Available serial ports:”); println(Serial.list()); // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your // Arduino sketch. Port = new Serial(this, Serial.list()[0], 9600); // If you know the name of the port used by the Arduino board, you // can specify it directly like this. //port = new Serial(this, “COM1”, 9600); } void draw() { // draw a gradient from black to white for (int I = 0; I < 256; i++) { stroke(i); line(I, 0, I, 150); } // write the current X-position of the mouse to the serial port as // a single byte port.write(mouseX); }
This amount of space is not good enough for me because I want to use the remote mouse for controlling the LED; this will be done simply by connecting to the server and then using the x coordinates to control the lights. The fact that it is so small I will have to keep the pointer in that one area the whole time for the demo which is not very practical. So I have had a look around and found that if I use a program called MAX/MSP which I have been recently introduced to can also communicate very well with the Arduino. The web page I found the fundamental Arduino code (http://arduino.cc/en/Tutorial/Dimmer) also had a simple patch that carried out the same function. I have learned a bit about this software and have found out that I can create a patch that will track my mouse pointers coordinates numerically; I have also discovered if I attach the numeric data to a slider it will scale up and down in accordance to the numbers it reads. And then by using a message called scale I can set the size of the active area to be the same size of an iPhone screen which in turn when moved along the x axis I can very effectively control the brightness of the led from 0 – 255.
The best thing about the code I have used for the LED dimmer is that I can also include another piece of code I adapted to use RFID to switch the LED on. The advantage of this is that I may be able to scan the tag which will switch on the light then I can use my iPhone to control the brightness
After many trial and error attempts I have finally got a piece of code working that allows me to scan the appropriate tag to switch on the light. Something that started off to be something I thought would be simple has again taken me days to figure out. But I am glad I have stuck with it. I have also decided to drop the processing code to call up media files I mentioned earlier and use a MAX patch for all the functions that I need. I have spent a lot of time developing this patch so that when I demo the various interactions I will not have to switch one program off just to start up another. I have discovered a MAX patch that allows me to use the original Arduino core RFID code along with the patch. When a tag is read it is stored in a list. As each new card is added so too is a numerical output. The numbers ascend as each new tag is added, I can use this output to carry out a range of functions using a bang and select message.
No comments:
Post a Comment