How to use a universal TV remote to trigger LED responses with the Arduino

in a nut shell, i have a spare universal TV remote and the desire to build a light/lamp/projector. My thought was "can i use the universal remote to turn the light on and off, use the volume controls as a dimmer, trigger different blinking patterns, etc?"

I'm not looking to have a spoon fed answer, i just have zero idea of where to start or if this is feasible. I assume that when you push a button on the remote is pulses the IR led on the end. So one would assume that this could be read by the Arduino (given the right sensor, which im not entirely sure which one that is)- sort of like morse code- and once i have the "messages" from the remote, i could assign behaviors to them.

I'm fairly good with the Arduino; just never done any IR projects.

Any tips to get me started would be most appreciated!

thanks in advance,
shields

You will need a ir receiver module. these are available for a number of frequencies. I believe the most common is 38kHz.
You will also need a library to decode different remotes. One can be found here

That stuff of Ken Shirriff is very good.

I used it to firstly decode my remote, to see what codes were generated by each button. Then, once I knew that, I had another sketch to act on the various codes and control the motors on a robot. So like "volume up" would be "increase speed" etc.

I used a Vishay TSOP34838 sensor... the "38" on the end means 38kHz.

thanks for the good info! and it seems like your robot is pretty close to the behavior that i'm trying to accomplish (just with light instead of motion... although now you have me thinking of motion)

google for "sb projects ir"
.. a good resource that explains IR protocols very well.

+1 on IRremote and also IRLib

thanks for all the help in pointing me in the right directions. as soon as i get some free time, i'd like to try to get started on this. thanks!

update- i'm waiting for my ir receiver to arrive.

Another way to approach this project is to build a "generic" IR to ASCII receiver module and use a serial port on the main uC to poll for IR responses.

Like MIM 5383H4 Infrared Module with ATtiny85 (UNO set time/date menu sample) - Exhibition / Gallery - Arduino Forum

This approach moves all the tricky IR off to a dedicated uC and really simplifies the state-machine approach in the main uC. It is also applicable to multiple projects across all host Arduinos.

Ray

So, I got my IR receiver, downloaded the libraries and tried the IRrecvDemo. I point my remote at the arduino with the serial monitor open and i'm getting something. Problem is that I'm getting a different code each time.

The remote is an universal remote, RCA, model RCU703SPR

Say I push the #1 on the remote (which i just did) and the following appears on the Serial Monitor:

3CE4CDB7

Now i push i again and get:

6BC6597B

Again:

769B133A
FFFFFFFF

And one last time:

63A20C20

So i'm not sure what to make of this or how to work with these codes. For example, let's say that when i push the #1 button, an LED on the arduino pin 13 lights up. Push it again, the LED turns off. I can do the on/off part with a simple momentary button on a bread board, but i'm not sure how to get the remote to do it. Well, I can get it to turn on and off if ANY button is pushed but i'd like it to be dependent on particular buttons to preform different actions. Right now, I'm just using an LED for testing, but I'd like to expand this to more complex things (robotics, etc).

Any help would be appreciated- thanks!!!!

use the IRrecvDump sketch in the examples and post the results again (include the long hex buffer), with several examples of the same key press.

You may have to use the RAW method to send & receive if the library cannot decode the RCA signal.

what IR receiver model are you using?

I found with an old tv remote I picked up, that each button gave two codes, one each on alternate presses. But it was, luckily, only two codes so I just did an if (mycode==A || mycode==B) and it was easy after that.

JimboZA:
I found with an old tv remote I picked up, that each button gave two codes, one each on alternate presses. But it was, luckily, only two codes so I just did an if (mycode==A || mycode==B) and it was easy after that.

That's a common occurrence & is normally referred to as a toggle bit, mainly found in protocols similar to RC5 & RC6. However, this issue does not appear to be linked to the toggle bit.

AnalysIR:

JimboZA:
I found with an old tv remote I picked up, that each button gave two codes, one each on alternate presses. But it was, luckily, only two codes so I just did an if (mycode==A || mycode==B) and it was easy after that.

That's a common occurene & is normally referred to as a toggle bit, mainly found in protocols similar to RC5 & RC6. However, this issue does not appear to be linked to the toggle bit.

Yep it was RC5. Intersting point though: would my alternate codes have been literally one bit different? I didn't spot that, not that it mattered, since I just told it to look for A or B withou caring abou the relationship between them. I'll stick those codes into a binary calculator and have a look.

Yep it was RC5. Intersting point though: would my alternate codes have been literally one bit different? I didn't spot that, not that it mattered, since I just told it to look for A or B withou caring abou the relationship between them. I'll stick those codes into a binary calculator and have a look.

RC5 is 14 bits & the values you were getting are longer. If its RC5 then only one bit would toggle each time.

see SB Projects

Thanks for such a quick reply!

what IR receiver model are you using?

IR Receiver Module 38 kHz TSOP4838
here's the data sheet:http://www.taydaelectronics.com/datasheets/A-1551.pdf
FYI, if it wasn't already obvious, i know zilch about remotes.

AnalysIR:
use the IRrecvDump sketch in the examples and post the results again (include the long hex buffer), with several examples of the same key press.

You may have to use the RAW method to send & receive if the library cannot decode the RCA signal.

First Press of key #1:

6BC6597A
Unknown encoding: 6BC6597A (32 bits)
Raw (52): 16608 4000 -3900 550 -1950 550 -1900 600 -1900 550 -1900 550 -1050 450 -950 550 -1900 550 -1950 550 -950 500 -1000 500 -950 550 -1900 600 -950 500 -1000 500 -950 550 -1000 500 -1900 550 -1950 550 -950 500 -950 550 -1950 550 -1900 550 -1950 550 -1100 350

Second:

FF26DD67
Unknown encoding: FF26DD67 (32 bits)
Raw (50): -21016 4000 -3900 600 -1900 600 -1850 600 -1900 550 -1900 600 -900 600 -900 550 -1900 600 -1900 550 -950 550 -900 600 -950 500 -1950 500 -1300 150 -1000 550 -1100 350 -1050 450 -1950 550 -1950 500 -2450 550 -1950 500 -1950 500 -2000 500 -1300 200

Third:

68D1027E
Unknown encoding: 68D1027E (32 bits)
Raw (52): 10334 4100 -3800 650 -1850 600 -1850 650 -1850 600 -1900 600 -1050 350 -1000 500 -1950 500 -1950 550 -1050 450 -1000 500 -1050 400 -1950 550 -1050 450 -1000 450 -1000 500 -1000 500 -1900 550 -1950 550 -1050 450 -1050 450 -1900 550 -1950 550 -1900 550 -1000 500

Fourth:

63A20C20
Unknown encoding: 63A20C20 (32 bits)
Raw (52): -6160 4150 -3800 650 -1800 600 -1900 550 -1900 600 -1900 600 -900 550 -1000 500 -1900 600 -1900 550 -950 500 -1050 500 -1000 450 -1900 600 -900 600 -900 550 -950 550 -1050 450 -1900 550 -1900 600 -950 500 -950 600 -1900 550 -1900 600 -1900 550 -950 550

OK the TSOP4838 is a good receiver.

The signals are consistent with the exception of signal 2 which has some errors in it.

I imported your 4 signals & have attached a signal trace image from AnalysIR - see attached. It a 24 bit signal with lead-in mark/space & trailer mark.

I am just showing signal 1 and signal 2 in the image. Signal 1 is the good one and you may be able to see some signal degradation on signal 2(yellow).
Signal 3 & 4 are similar to 1.

The bad news is that this protocol is not supported by IRremote and you will have to use RAW mode to send. You will have to write your own code or modify the library to detect this signal (or you could just change the definitions in the library for NEC to match your signal)

Finally, I have included some automatically generated code from AnalysIR to send each of these signals in RAW mode

(you will need to define khz as 38// int khz=38;// and you may run out of RAM if you try them all together. Also signal #2 looks bad)

/*
Automatically Generated by AnalysIR - Batch Export Utility
Registered to: xxx
Session History
Type : Key : Value : Bits
0 : RAW : 4th :  : 0
1 : RAW : 3rd :  : 0
2 : RAW : 2nd :  : 0
3 : RAW : 1st :  : 0
*/

// NB: Not all protocols are supported by IRremote or IRLib. You may need to edit the code below manually
// Automatically Generated by AnalysIR for xxx, visit http://www.AnalysIR.com or email info@....... for further details

unsigned int Signal_4th_0[] = {4150,3800,650,1800,600,1900,550,1900,600,1900,600,900,550,1000,500,1900,600,1900,550,950,500,1050,500,1000,450,1900,600,900,600,900,550,950,550,1050,450,1900,550,1900,600,950,500,950,600,1900,550,1900,600,1900,550,950,550,1000}; //AnalysIR Batch Export - RAW

irsend.sendRaw(Signal_4th_0, sizeof(Signal_4th_0)/sizeof(int), khz); //AnalysIR Batch Export - RAW
 // AnalysIR IR Protocol: RAW, Key:  4th

unsigned int Signal_3rd_1[] = {4100,3800,650,1850,600,1850,650,1850,600,1900,600,1050,350,1000,500,1950,500,1950,550,1050,450,1000,500,1050,400,1950,550,1050,450,1000,450,1000,500,1000,500,1900,550,1950,550,1050,450,1050,450,1900,550,1950,550,1900,550,1000,500,1000}; //AnalysIR Batch Export - RAW

irsend.sendRaw(Signal_3rd_1, sizeof(Signal_3rd_1)/sizeof(int), khz); //AnalysIR Batch Export - RAW
 // AnalysIR IR Protocol: RAW, Key:  3rd

unsigned int Signal_2nd_2[] = {4000,3900,600,1900,600,1850,600,1900,550,1900,600,900,600,900,550,1900,600,1900,550,950,550,900,600,950,500,1950,500,1300,150,1000,550,1100,350,1050,450,1950,550,1950,500,2450,550,1950,500,1950,500,2000,500,1300,200,1000}; //AnalysIR Batch Export - RAW

irsend.sendRaw(Signal_2nd_2, sizeof(Signal_2nd_2)/sizeof(int), khz); //AnalysIR Batch Export - RAW
 // AnalysIR IR Protocol: RAW, Key:  2nd

unsigned int Signal_1st_3[] = {4000,3900,550,1950,550,1900,600,1900,550,1900,550,1050,450,950,550,1900,550,1950,550,950,500,1000,500,950,550,1900,600,950,500,1000,500,950,550,1000,500,1900,550,1950,550,950,500,950,550,1950,550,1900,550,1950,550,1100,350,1000}; //AnalysIR Batch Export - RAW

irsend.sendRaw(Signal_1st_3, sizeof(Signal_1st_3)/sizeof(int), khz); //AnalysIR Batch Export - RAW
 // AnalysIR IR Protocol: RAW, Key:  1st

So this is odd. While trying to solve this for myself, i reprogrammed to remote to a Sony TV (it had been manually programmed to a Sony TV previously) that i had a factory remote for. Then I ran the dump program again hitting #1 with the stock remote:

10
Decoded SONY: 10 (12 bits)
Raw (26): 29662 2450 -500 700 -500 650 -550 650 -500 700 -500 650 -550 650 -550 650 -500 1300 -500 650 -550 650 -500 700 -500 700

Then again #1 on my remote:

10
Decoded SONY: 10 (12 bits)
Raw (26): 29662 2450 -500 700 -500 650 -550 650 -500 700 -500 650 -550 650 -550 650 -500 1300 -500 650 -550 650 -500 700 -500 700

I tried this with other buttons on the factory remote and the universal- both match in outputs.

So now that I have the remote working, I need to work through the issue of gathering the codes, applying them and debugging.

I can't thank you enough for your help!!!

Great

yes this signal decodes to Sony 0X10 12 bits on AnalysIR also.

Remember to use the hex value 0x10 as it is not decimal!

Hopefully, you can get the main project going now.....

Example code...

irsend.sendSony(0x10, 12); // AnalysIR IR Protocol: SONY, Key:

I will. I have lots to learn.

Now, if I can ask you another question. Why is the code from the remote turned into a HEX code?

Serial.println(results.value, HEX);

Verses just being printed in decimal form?

Serial.println(results.value);

Unrelated, I just noticed your from Dublin. What a great city. And country! Going back is on my bucket list.

Its just easier to see the differences in bit patterns with hex - between different signals.
Typically there will be only one or 2 binary bits changing between the code for adjacent buttons, Easy to see in binary or HEX, much more difficult with decimal.

But it is not neccessary - you can use HEX, Binary or Decimal as you wish, as long as the syntax is correct.
so

irsend.sendSony(0x10, 12); // AnalysIR IR Protocol: SONY, Key:

works the same as

irsend.sendSony(16, 12); // AnalysIR IR Protocol: SONY, Key:

to learns more about IR signals google "sb projects ir"....its all explained there!