Search This Blog

Sunday, September 26, 2010

Back working on the Arduino IR TV sleep timer setter

Now that the GPS is working, i'm back working on a project that stalled.

This project has an IR receiver that looks for any traffic, from multiple remotes.  Point is not to decode them, just to detect them.   A timer runs and if no traffic has been seen for a set time (say 1/2 hour) it sends via an IR diode a sleep timer set code for the TV.  The device is placed in front of the TV where it will see the IR remote and be able to send a code to the TV out the back.   The point is that when someone is watching, they skip commercials, change volume, channel, etc.  When they fall asleep they stop using the remote.  If we mess up and accidentally set the sleep timer on an awake user, so what.  They will notice.

I had been using code from the Arduino playground and successfully detected Sony remote codes at just bout 100% accuracy.
I had some trouble sending the same codes to the TV.  There were two problems.  First the bit order was opposite what i thought, and I think the code on the website was not symmetrical.  After printing the codes out I figured that out.  More vexing however was that the TV ignored the codes I sent.  I tried several Sony TVs.  Luckily the TV I want to use is a Sony, which has easier codes.   I discovered after playing a long while, and looking at the time measurements of the real IR remote versus what I was sending (this took two Arduinos with the same hardware) that my pulses were longer than the real remote.  The real remote times were much less than the spec times of 600us and 1200us .  I think the clock in the Arduinos are off.  By changing the bit transmit times in the code to what i measured, I got the TV to respond.  That took a while to sort out.  However this varies Arduino to Arduino, so you have to tweak the times to the specific Arduino.  Disappointing but I'll live.

The problem that finally stalled me, was that the Arduino IR remote code is using a pulse measurement command and a while loop. 

while(pulseIn(ir_pin, LOW) < 2200) { //Wait for a start bit

} data[0] = pulseIn(ir_pin, LOW);

Problem is that I want a timer to increment, and this command uses up the whole of the Arduino's attention.  Additionally it is reliable with only Sony remotes, but remember i want to notice codes from a variety of remotes.   The 2000us pulse width doesn't apply to the other protocols and doesn't work reliably.

Whoa! ... a google search just turned up this blog, which is much more professional than mine, and has a lot of useful information.   Early posts point to the code i had been using.

Alright.  Off to lick this problem with some new code!!