Thursday, August 11, 2011

Arduino + IR Detector = PC Remote

So on Monday I received some mail which included the RTC chip from my last post, and other things such as  some Surface Mount capacitors for my Arduino Clones , and a little IR (infra red) detector. I think the one i have is made by Sharp but i got it from Jameco.com (part number : 2129844)  but i also had one i got from radio shack which is the one shown here and the one i used for this project.

Not to be confused with another product that radio shack offers which is an IR transmitter packaged with a phototransistor. Anyways the good thing about this as oppose to regular phototransistors is that while both are extremely sensitive to infra red light this one has some sort of "decoder"  that filters out any other infra red or ambient light that is not modulated at around 36-40 khz which is what most remote controls for electronic devices use.
So once the IR detector recognizes a certain frequency of light then it outputs , i guess the raw code so to speak. However this great man by the name of Ken Shirriff wrote a library for these detectors to use with an Arduino.
So with that library on stock along with my Arduino and Visual Basic I ventured on to make a remote control for my PC. The concept is simple. the library provides a record function, in which you wire the detector to your arduino and then get a remote press some buttons and it prints to serial the code. So if i press volume down on the remote and it gives me a code like FF4AD, then i send that to serial, while i have a visual basic program waiting for data on the same COM port as my arduino and it checks for certain codes, so if it receives the FF4AD code then i know that button was volume down so then i have it send some "send key" functions to my pc to turn the volume down. Of course i can make it do anything but obviously if i press a volume button im going to make it adjust my volume which is basically all i wanted because sometimes i am in  bed listening to music and i want to change tracks or turn down the volume but too lazy to get up.


To the far left is the IR detector connected to an arduino clone which is connected to  a USB serial interface and then the remote which actually controls a speaker bar i have on top of my tv but now it also controls my PC :)

Okay i was about to post the Visual Basic code as well as the Arduino code but it looks very messy here so shoot me an email or send me a message on here if you want a copy of the Sketch and Visual Basic form. Here is the link to Kens site.
Ken Shirriff Arduino IR library

the only set back i had which took me about 10 minutes to figure out was that while sending the code to serial with Arduino Serial.println(FFA4D); and then receiving it in Visual Basic there was an issue, VB was not responding to the code , so i had VB echo back to me what ever it was reading from serial and in fact it was FF4AD  but when i pased an if statement saying something like if code is FF4AD then do this, it was not doing it and i could not figure out for the life of me why it was not doing it.
Then it hit me when i send a println command from Arduino it adds a line terminator at the end , and when echoing this on VB the line terminator is invisible but it still is there so "FF4AD" is not the same as FF4AD/n" and thats why my if statement was doing nothing, so a simple change to print instead of println was all it needed.
Here is a very ugly video of my showing it off.
At first i am showing you an indicating led that just flashes every time the Arduino receives some IR codes.
After that i open up Visual Studio and i execute the program, which is just some buttons i made at first to test out the send keys functions but are no longer needed since i have the code running on a timer instead of pressing buttons, then after i run the program i start to type in what COM Port i am going to use and then i show you the volume going up and down as well as mute. the actual volume control does not have to be open for it to work i just used it to show you and the window of the VB program does not have to be in focus either i can be minimized or even hidden on the task bar and it works just fine.
In the future  i would like to make a universal programmable remote. Using Kens Library to read codes and then save them on either on or off board memory and then use that to send them out to the waiting device such as a TV or stereo. I would like to make it a touch screen remote using the Nintendo DS touch screen which has already been used with the Arduino since it a very simple 4 wire screen , X Y ground and power. I would like to have some sort of LCD screen under it to draw buttons and menus but i think that is beyond my reach right now. So basically I will just use some nicely designed paper  with text such as volume down or up and mute and what ever other functions  i want to use it for. then i will overlay the screen on top of the paper. After that proceed to check the X and Y coordinates of where the buttons are. for example if the Volume UP text is under the screens 23 , 78 then I will make Arduino send out whatever code i recorded for volume UP when i press on that general area or proximity because it is hard to press an exact spot with a finger tip so it will be based on rangers/ thresholds of  coordinates. The nintendo Ds touch screen , or rather digitizer is only $9.95 at Sparkfun , i forgot to mention its a transparent little thing that is how i will lay my button drawings underneath it. 
 You might also be wondering how you will connect that little thing to the arduino , well they do sell a breakout board that you plug that little strip into which connects to 4 nice big and spaced out pins that you can use . But to save some cash you could just grab a blade or exacto knife and cut through the strip to separate the 4 wires and then solder some longer wire or pins to the tips. I dont know what ever floats your boat, or mine in this case.

No comments:

Post a Comment