An Arduino universal remote: record and playback IR signals

I've implemented a simple IR universal remote that will record an IR code and retransmit it on demand as an example for my IR library. Handling IR codes is a bit more complex than it might seem, as many protocols require more than simply recording and playing back the signal.

To use the universal remote, simply point your remote control at the IR module and press a button on the remote control. Then press the Arduino button whenever you want to retransmit the code. My example only supports a single code at a time, but can be easily extended to support multiple codes.

The hardware

The IR recorder
The above picture shows the 9V battery pack, the Arduino board, and the proto board with (top-to-bottom) the IR LED, IR receiver, and pushbutton.

The circuitry is simple: an IR sensor module is connected to pin 11 to record the code, an IR LED is connected to pin 3 to transmit the code, and a control button is connected to pin 12. (My IR library article has details on the sensor and LED if you need them.)
Schematic of the IR recorder

The software

The code can be downloaded as part of my IRremote library download; it is the IRrecord example.

Handling different protocols

The code supports multiple IR protocols, each with its own slight complications:

Sony codes can be recorded and played back directly. The button must be held down long enough to transmit a couple times, as Sony devices typically require more than one transmission.

The common NEC protocol is complicated by its "repeat code". If you hold down a button, the remote transmits the code once followed by multiple transmissions of special repeat code. The universal remote records the code, not the repeat code. On playback, it transmits the code once, followed by the repeat code.

The RC5 and RC6 protocols handle repeated transmissions differently. They use two separate codes for each function, differing in a "toggle bit". The first time you hold down a button, the first code is transmitted repeatedly. The next time you hold down a button, the second code is transmitted repeatedly. Subsequent presses continue to alternate. The universal remote code flips the toggle bit each time it transmits.

The universal remote handles any other unknown protocol as a "raw" sequence of modulated IR on and off. The main complication is that IR sensor modules typically stretch out the length of the "on time" by ~100us, and shorten the "off time" correspondingly. The code compensates for this.

Most likely there are some codes that that can't handle, but it has worked with the remotes I've tried.

The code also prints debugging information to the serial console, which can be helpful for debugging any problems.

In conclusion, this is intended as a proof of concept rather than a useful product. The main limitation is supporting one code at a time, but it's straightforward to extend the code. Also note that the record and playback functions can be separated; if you know the IR codes you're dealing with, you can use just the necessary function.

73 comments:

Charles said...

Very interesting - now if I just had a use for it, it would also be usefull.

electrosthetics said...

I found a use for it, thanks for the library!

http://electrosthetics.blogspot.com/2009/11/arduino-universal-remote-and-more.html

Gordon Gadget said...

I am using a JVC remote from what I can tell its like a NEC in alot of aspects. But I don't understand where to put in the numbers to decode in IRremote to add JVC as a type.

Andrew Akeroyd said...

Thank you for the library. Very easy to use.

I'll be using it to trigger an Olympus camera based on a flying insect.
I can also see a lot of uses in a home automation setup.

tom_eaton said...

The code works very well, however I cannot seem to get it to store and repeat more than one! Do you have any example code for this?

Martin said...

This started to work for me after increasing RAWBUF in IRremote.h to 256. Indeed, 129 bytes were collected from the non-standard remote of my aircondition. Maybe the default buffer is a bit tight here.

To the poster who wonders how to replay what's been received: Copy the received code sequence from the serial terminal, remove the s and m characters and pass the numbers to the sendRaw call.

My proof-of-concept sketch is here: http://pastebin.com/EzNNrYey

Thanks Ken for the great library!

Alex said...

This is one of the easiest thing to check for so you might as well be up front and honest.

Robert C. Fisher said...

I am a noob to Arduino so learning this is a bit difficult so please forgive me. I am trying to control a Tascam DR-100 any ideas where I should start. The DR-100 is controllable by IR and they have a little converter that will make the IR Remote wired but I figured that maybe start with the IR thing then try to get the wired working since it must be the same codes. What I want to do is to have an RTC in arduino start the DR-100 recording at a specific time then stop. There is no sleep in the DR-100 so no need to wake it up. Any clues?

Thanks

soabotics said...

I'm doing all this reading and investigation because I've lost the remote for an old receiver & pre-amp and am hoping to get this to work in place of the missing remotes. I've found the proper pronto hex codes on remote-central but i'm still not quite sure how to take the pronto hex info from remote central and get it to be used in the arduino? I guess the part that is confusing to me is that there seems to be so many different modulation frequencies and i'm not sure how or even if that matters? any help would be greatly appreciated.

Anonymous said...

I am using the Library to control Channel master box....
Here are the commands:
#define cmUP 0x35CA8877
#define cmDOWN 0x35CA08F7
#define cmPOWER 0x35CA38C7
#define cmKEY0 0x35CA00FF
#define cmKEY1 0x35CA807F
#define cmKEY2 0x35CA40BF
#define cmKEY3 0x35CAC03F
#define cmKEY4 0x35CA20DF
#define cmKEY5 0x35CAA05F
#define cmKEY6 0x35CA609F
#define cmKEY7 0x35CAE01F
#define cmKEY8 0x35CA10EF
#define cmKEY9 0x35CA906F

BobW said...

Can someone give me some guidance please?
Am trying to make an Arduino based, dedicated "Closed Caption (CC) toggler".
In order to Toggle the CC, my set-top box's native remote requires eight (yes, eight) keystrokes.

This remote is not RC5. RC6, Sony or NEC.

Have built Arduino send/capture device and have captured RAW data from the set-top box's remote.

Problem:

Have attempted to use "IRrecord" to retransmit codes using Arduino apparatus described in the blog.

CAN do this with RC5 codes, thus demonstrating that hardware works properly.

HOWEVER: not able to do it with the set-top box remote that I actually need to use.

Can anyone direct me to a solution for this problem please?

To summarize:
1. Hardware has been built and tested for RC5
2. Have captured codes from remote, which I wish to retransmit from Arduino driven IR LED.
3. How do I send a sequence of eight sets of RAW to the IR LED and have it be readable by my set-top box.

Thank you for your help with this.

BobW

PS: Have successfully built Ken's Arduino TV-Begone.

Martin said...

BobW: See my comment above from April 9 on how I replayed the received raw codes. Still works for me.

BobW said...

Thank you Martin.
Will get to work on this tomorrow.

BobW

BobW said...

Martin:

I'm up and running thanks to your advice. Thanks so much for your help !

BobW

Putteh said...
This comment has been removed by the author.
Putteh said...

I have no success with this. Trying to use it with a Creative DDTS-100. I've used values from http://lirc.sourceforge.net/remotes/creative/DDTS-100 and changed IrremoteInt.h like this:
// pulse parameters in usec

#define NEC_HDR_MARK 8973

#define NEC_HDR_SPACE 4760

#define NEC_BIT_MARK 591

#define NEC_ONE_SPACE 1675

#define NEC_ZERO_SPACE 567

#define NEC_RPT_SPACE 2308

I then use IRsendDemo and change the send command:

irsend.sendNEC(0x15EA, 16);

The DDTS doesn't react. I see the IR-beam in my digital camera and have placed the transmitter Led really close to the DDTS.

Duncan said...

I used the library to control some costumes in a play. Three characters had LEDs, a 9volt battery,an Ardweeny and a IR receiver. Using a Sony TV remote I was able to send codes to all three costumes simulaneously.
Worked great!

Putteh said...

I found the error! Yes!! The answer is in this comment: "Hi reconnnn: I'm in the process of writing an explanation of LIRC data, but for your case LG usually uses 32-bit NEC protocol. Take the pre_data bytes in the LIRC file and join them to the bytes for the button you want to control to make a 4-byte hex number, and use sendNEC. Power on is probably 0x20df10ef; some LG devices use 0x897641be or 0x34347887. If you have an IR detector, you can read out what your remote sends, rather than looking in the LIRC files.
September 26, 2009 3:17 PM " from http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html.
If I use "irsend.sendNEC(0x8322E11E, 32);" the device turns on. Happy, now I can use the DDTS altough the remote went missing.

Putteh said...

I've wrote down the process to use a Lirc file with Irremote: http://www.patrikhermansson.se/?q=node/430

Anonymous said...

Thanks for the great library! Unfortunately IRremote has
side effects on the build-in tone() library. Either sounds are
crippled or - after playing a tone - the receive library stops
working and returns 0 for any IR event.

Is there a way to fix this problem?
Or a workaround?

Anonymous said...

After a bit of searching and experimenting I stumbled upon this side: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1176970454.

So the solution to the tune() imcompatibility is simply this code:
void freqout(int freq, int t)
{
int hperiod; //calculate 1/2 period in us
long cycles, i;
hperiod = (500000 / freq) - 7; // subtract 7 us to make up for digitalWrite overhead - determined empirically
// calculate cycles
cycles = ((long)freq * (long)t) / 1000; // calculate cycles

/* Serial.print(freq);
Serial.print((char)9); // ascii 9 is tab - you have to coerce it to a char to work
Serial.print(hperiod);
Serial.print((char)9);
Serial.println(cycles); */

for (i=0; i<= cycles; i++){ // play note for t ms
digitalWrite(outpin, HIGH);
delayMicroseconds(hperiod);
digitalWrite(outpin, LOW);
delayMicroseconds(hperiod - 1); // - 1 to make up for fractional microsecond in digitaWrite overhead
}
}

It works like charm with IRremote...

OatlandsBoy said...

I'm trying to run this with a 56KBaud signal (TSOP1156 Receiver) but getting nowhere. As I'm new to Arduino can somebody tell me if I need to change anything anywhere please?

I have no idea of the signal format as it's not a domestic equipment remote that I'm trying to 'grab' and emulate - all I know is that the original equipment uses a TSOP1156 and (according to the info sheet) "The address is encoded into the IR sequence with 5 hamming code bits
and then manchester encoded to give a 32 bit complete code. Since manchester encoded then every transmitter sends 16 high and 16 low pulses. Giving an equal power on the beam. any erroroneous data is ignored by a recevier."
Tham eans absolutely nothing to me bot hopefully it may do to somebody...
Any assistance would be very welcome.

OatlandsBoy said...

I have this working now (a well known make of prototyping board with a power rail that didn't run the full length!!!) but...

According to my camera phone, the IR LED stays on after the code has been sent - making for short battery life.

Has anyone else noticed this? Anyone have a fix?

It's using RAW, I don't know if that means anything in relation to the problem.

Thanks

Spike said...

Ken, this library is awesome, thanks a bunch. Anyway, I was playing around with sending multiple codes with a single button press. I have one button to turn on the TV and the AV receiver, another button that selects the audio mode on the receiver, etc. This library is so powerful that with macros you can build a serious universal remote rivaling some of the commercial ones available.

I was just stringing commands together with a delay of (40) between each transmission and it seems to work ok. Just wondering if you have a different way of creating macros or if you could recommend optimum delay values, etc.

Chris said...

Thanks for the library Ken. Question: will your examples work with an UNO? I think I have everything right and the codes I recorded match a work lirc configuration but I just don't seem to be able to get the stereo device to recognize the output. Any help is greatly appreciated.

--Chris

Anonymous said...

I Need a little help with RC5, I was able to transmit using NEC with no problems but my television will not respond to codes using the RC5 protocol.

#include

IRsend irsend;

void setup() {
}

void loop() {
irsend.sendRC5(0x26, 20);
delay(100);

}

what am i doing wrong? what should the number of bits be? 26 is whats reported (in hex) as being the power code.

MbarK said...

I am setting up an Arduino Uno to control remote control lights. IRRecord seems perfect to get the data I need. I modified IRRecord to output codelen and to output rawCodes after the irsend.sendRaw command.

Serial output:
Received unknown code, saving as raw
23
m1450 s300 m1250 s400 m450 s1300 m1250 s400 m400 s1300 m400 s1300 m1250 s400 m450 s1250 m400 s1300 m400 s1300 m400 s1250 m400
Pressed, sending
Sent raw
1450 300 1250 400 450 1300 1250 400 400 1300 400 1300 1250 400 450 1250 400 1300 400 1300 400 1250 400
Released

This does not activate the lights. However, if I cut/paste the codes into an array as per Luckylarry's example, it works.

Any idea why IRRecord does not?

Thanks for the library. I am using IRHashdecode for another application with no problems.

Mike

Termsl said...

Thanks for the great library!
All remote capture is perfect, but one remote for panasonic tv not recognized.
I try to use panasonic decode function- it do not recognize.

Remote work in Pronto format
dum of recive codes:

1
Raw (76):
-17316 3550 -1650 500 -350 550 -1200 450 -400 550 -350 500 -350 500 -400 450 -400 450 -400 500 -400 500 -350 500 -350 500 -400 450 -400 500 -1250 450 -400 500 -350 500 -400 450 -400 500 -350 500 -400 500 -350 450 -400 500 -400 450 -1300 450 -400 500 -350 500 -400 450 -400 500 -350 500 -400 450 -400 500 -350 500 -400 500 -350 500 -350 550 -350 450

2
Raw (76):
-10870 3450 -1700 500 -350 500 -1250 500 -350 500 -350 500 -400 450 -400 500 -350 450 -450 450 -400 450 -400 500 -350 500 -400 450 -400 450 -1300 450 -400 500 -350 500 -350 450 -450 450 -400 450 -400 500 -400 500 -350 450 -400 500 -1250 500 -350 450 -400 500 -400 450 -400 500 -350 500 -400 450 -400 500 -350 450 -1300 450 -400 500 -350 500 -400 450

3
Raw (76):
-892 3500 -1700 500 -350 500 -1250 450 -400 450 -400 500 -400 450 -400 450 -400 500 -350 500 -400 450 -400 500 -350 450 -450 450 -400 450 -1250 500 -400 450 -400 500 -350 500 -400 500 -350 450 -400 500 -350 550 -350 450 -400 500 -1250 450 -400 450 -400 500 -350 500 -400 450 -400 500 -350 450 -450 450 -400 450 -400 500 -1250 450 -400 500 -350 500

Termsl said...
This comment has been removed by the author.
Anonymous said...

A hint for the new Arduino 1.0 version:

To get this library running under Arduino 1.0 you need to change one line of code in the file IRremoteInt.h:

line 15: from WProgram.h -> Arduino.h

That is all...

Marco Giglio said...

Hello, I need help to send a IR command. It is a signal from a IR fan remote. It is 0xC08, 11 bit, but it isn't sony, nec or the other protocol. How can I send it?
Thanks!!
Excuse my bad english, I'm Italian!

fatmi said...

At First I was using this, thanks for the guide-lines.

Arduino

furiano said...

Hi,
sorry for my bad english.
I want create a bluetooth remote infrared with Arduino and Android.
I find a java parser for lirc conf file and I want test it.
It is possible create a most generic send function on arduino for codes parsed by Android?
I have all info and data from lirc file and i think it is possible compute a raw send data with Android and send it to arduino via bluetooth. The arduino decode it to IR Led.

Anonymous said...

First off, awesome library. Works great.

I plan on using multiple infrared sensors. How would the library support that?

I'm looking in the neighborhood of 15-20 infrared sensors.

will said...

I Love this project! I am putting this circuit into a pocket watch. Because of the limited space I am using an attiny85. I cannot laod this program onto it without an error however:

IRrecord.cpp: In function ‘void setup()’:
IRrecord.cpp:36:3: error: ‘Serial’ was not declared in this scope
IRrecord.cpp: In function ‘void storeCode(decode_results*)’:
IRrecord.cpp:55:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:72:37: error: ‘DEC’ was not declared in this scope
IRrecord.cpp:78:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:86:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:89:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:92:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:95:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:96:30: error: ‘DEC’ was not declared in this scope
IRrecord.cpp:99:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:99:36: error: ‘HEX’ was not declared in this scope
IRrecord.cpp: In function ‘void sendCode(int)’:
IRrecord.cpp:109:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:113:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:114:33: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:119:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:120:31: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:131:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:132:33: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:137:7: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:138:33: error: ‘HEX’ was not declared in this scope
IRrecord.cpp:144:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp: In function ‘void loop()’:
IRrecord.cpp:154:5: error: ‘Serial’ was not declared in this scope
IRrecord.cpp:159:5: error: ‘Serial’ was not declared in this scope


How can I use this sketch with the attiny85?

Anonymous said...

Hello Ken, i am trying to work with your library in one Arduino MEGA 2560. The sendRaw function is not working. I tested all PWM ports, from 2 to 13 on board, and i could not see the IR Led blinking with my camera. Any ideas ? Thanks a lot!!!!

Matthew B said...

I just wanted to echo what someone said higher up - the default sending example, using delay(100), does not work with my Sony receiver. Changing it to delay(50) works perfectly. Lower than delay(50) seems to cause issues.

Christian L said...

Hi

I have attached a Beolink IR eye (455kHz carrier frequency)

The receiver is picking up a lot of noise when my room is dark and can be canceled by turning on the light.

Also the raw codes I receive with the IRrecvDump is pretty much the same for all the buttons on my remote (a Bang & Olufsen Beo4 remote).

This it what I get when I press the up/down button:

Raw (26): -13900 1650 -1450 1650 -4600 1600 -4600 1650 -4550 1650 -4600 1600 -4600 1600 -4600 1650 -4600 1600 -4600 1600 -4600 1600 -4650 1600 -4650 1600

And I receive the exact same code/pattern for different buttons, but with less/more codes. 22/24/26 raw codes...

Can anyone help my with this?

Thanks!

Anonymous said...

Hi thanks for the library its great I was just wondering how the IR receive works,is it constantly polling for an interrupt which would then be triggered by the code read in?.

Anonymous said...

Port this to an android app, whit an IR led plugged in the (mini)USB and you got a winner.

javed said...

Hi,
i've used the IRrecvDump example and got the following code for my sony tv:


A90
Decoded SONY: A90 (12 bits)
Raw (26): -8278 2400 -600 1200 -600 600 -550 1250 -550 600 -600 1200 -600 600 -600 600 -600 1200 -550 650 -550 600 -600 600 -600 600
A90
Decoded SONY: A90 (12 bits)
Raw (26): -25750 2400 -550 1200 -600 600 -600 1200 -600 600 -550 1250 -550 600 -600 600 -600 1200 -600 600 -550 650 -550 600 -600 600


Now wondering how to play back the IR signal , I already got the IR sender setup properly on my board and trying to under the following codes as from example :


#include

IRsend irsend;

void setup()
{
Serial.begin(9600);
}

void loop() {
if (Serial.read() != -1) {
for (int i = 0; i < 3; i++) {
irsend.sendSony(0xa90, 12); // Sony TV power code
delay(100);
}
}
}


However am not sure what I need to take from the result of IRrecvDump to use in the sending bit , can anybody help please by posting an answer ?

thanks,
javed

Patrik Hermansson said...

Maybe my page can give you some leads? http://patrikhermansson.se/?q=node/430
Try to use a code from Lirc maybe?

Ryan Han said...

Hi, very interesting projects. Is there a limitation to the distance of the IR transmitter LED with respect to the reciever? Thinking of using your project to build a IR controller that will be mounted on the ceiling center of my room and control all the IR devices remotely.

devlware said...

Hi Ken,

I'm trying to decode a NEC code in my board but I receive the following messages:
8F846BAD
Could not decode message
Raw (72): 27436 1100 -600 50 -50 100 -200 50 -250 50 -50 100 -50 100 -50 50 -100 50 -200 100 -200 50 -250 50 -50 100 -200 50 -100 50 -200 100 -200 50 -100 50 -200 100 -50 100 -200 50 -100 50 -50 100 -50 100 -50 50 -100 50 -100 50 -200 100 -50 50 -250 50 -200 100 -200 50 -200 100 -200 100 -4950 1100 -300 50
DF5D6B92
Could not decode message
Raw (72): 18116 1150 -550 50 -100 50 -200 100 -200 50 -100 50 -100 50 -50 100 -50 100 -200 50 -200 100 -200 50 -100 50 -200 100 -50 100 -200 50 -250 50 -50 100 -200 50 -100 50 -200 100 -50 100 -50 50 -100 50 -50 100 -50 100 -50 100 -200 50 -100 50 -200 50 -250 50 -200 100 -200 50 -250 50 -4950 1150 -300 50
942539A0
Could not decode message
Raw (72): 1016 1100 -550 100 -50 50 -250 50 -200 100 -50 50 -100 50 -100 50 -50 100 -200 50 -250 50 -200 100 -50 100 -200 50 -100 50 -200 100 -200 50 -100 50 -200 100 -50 50 -250 50 -50 100 -50 100 -50 50 -100 50 -100 50 -50 100 -200 50 -100 50 -200 100 -200 50 -250 50 -200 100 -200 50 -5000 1100 -300 50
310CFF35
Could not decode message
Raw (72): 11780 1150 -550 50 -100 50 -200 100 -200 50 -100 50 -50 100 -50 100 -50 100 -200 50 -200 100 -200 50 -100 50 -200 100 -50 100 -200 50 -200 100 -50 100 -200 50 -100 50 -50 100 -200 50 -100 50 -100 50 -50 100 -50 100 -50 50 -250 50 -200 100 -50 50 -250 50 -200 100 -200 50 -200 100 -4950 1150 -250 100
BAAC716C
Could not decode message
Raw (72): 9344 1150 -550 100 -50 50 -200 100 -200 50 -100 50 -100 50 -100 50 -50 100 -200 50 -250 50 -200 100 -50 50 -200 100 -50 100 -200 50 -250 50 -50 100 -200 50 -100 50 -200 100 -50 100 -200 50 -100 50 -50 100 -50 100 -50 50 -250 50 -50 100 -200 50 -100 50 -200 100 -200 50 -250 50 -5000 1100 -300 50
DE14404C
Could not decode message
Raw (72): -27698 1150 -550 50 -100 50 -200 100 -200 50 -100 50 -50 100 -50 100 -50 50 -250 50 -200 100 -200 50 -100 50 -200 100 -50 50 -250 50 -200 100 -50 50 -250 50 -50 100 -200 50 -100 50 -200 100 -50 100 -50 100 -50 50 -100 50 -200 100 -50 100 -200 50 -50 100 -200 100 -200 50 -200 100 -4950 1150 -250 100
3F3E464F
Could not decode message
Raw (72): 19416 1100 -600 50 -50 100 -200 100 -200 50 -50 100 -50 100 -50 100 -50 50 -250 50 -200 50 -250 50 -100 50 -200 100 -50 50 -250 50 -200 100 -50 50 -100 50 -200 100 -50 100 -50 50 -250 50 -50 100 -50 100 -50 50 -250 50 -50 100 -200 50 -250 50 -50 100 -200 50 -250 50 -200 100 -4950 1150 -250 100
248C15D9
Could not decode message
Raw (72): 8388 1100 -550 100 -50 100 -200 50 -200 100 -50 100 -50 50 -100 50 -100 50 -200 100 -200 50 -200 100 -50 100 -200 50 -100 50 -200 100 -200 50 -100 50 -50 100 -200 50 -100 50 -100 50 -200 100 -50 50 -100 50 -100 50 -200 100 -50 100 -200 50 -200 100 -50 100 -200 50 -200 100 -200 50 -5000 1100 -300 50

I created a small board with ATmega16U4 to receive a 38Khz code but its not working. Its strange because the code runs fine in the Arduino Leonardo.

I don't know what I'm missing, BTW, I have incremented MARK_EXCESS to 500 but it didn't work.

Regards,

Andrew Kent Morris said...

Has anyone tried to record the IR signals for things other than TVs? My Nikon DSLR uses IR for remote control but there is already a library for that, however, I have a small model helicoptor that uses IR instead of RF for control. So yeah... Anyone ever try recordning non TV signals?

Forrest Ruhge said...

Thank you for the great library! I have been wirking on an IR Translator for my entertainment system and have been greatful for all the hints and comments left by others. For others withing to do similar projects remember to use irrecv.enableIRIn(); after you are finnished with irsend as irsend disables irrecv. Also I found it useful to delay the transmission of the translated IR signal. if i did not the devices i was talking to would not respond.

Example code in void loop:
...
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
switch (results.value) {
case 0x181803FC:
//do something when power button is pressed
Serial.println("power button pressed");
delay(500);
irsend.sendNEC(0x4B20D32C,32); //Bose power code
delay(500);
irsend.sendNEC(0xC1AA09F6,32); //Projector Power Code
Serial.println("Sent NEC 0xC1AA09F6");
delay(500);
irsend.sendNEC(0xC1AA09F6,32); //Projector Power Code
Serial.println("Sent NEC 0xC1AA09F6");
break;
case 0x18E710EF:
//do something when chanel up pressed
Serial.println("channel up pressed");
break;
...
//after switch use
irrecv.enableIRIn();

Thanks again for all the hard work on this.

Frost369 said...

Is this library compatible with the arduino due? I have tried to compile and run the example program IRrecvDemo but I have had the following compile error.

C:\Users\Dresden\Desktop\Indicia\Projects\Arduino Due\arduino-1.5.1r2\libraries\IRremote\IRremote.cpp:23: fatal error: avr/interrupt.h: No such file or directory
compilation terminated.

I tried copying the avr directory and pasting it in the IRremote directory, and the specific compilation error went away but now I have a whole lot more errors.

I am not an expert in programming, but it seems like the necessary files are not being located, how do I fix this?

fxmech@cammotion.net said...

Has anyone decided any Samsung flat screen tvs?
Or know what format they use??? I tried but got the could not decide message

John said...

Hi, I am currently trying to change the software on our student laser tag system (running due boards) (who says you can't use violence to teach) to incorporate this brilliant library. So that the kids can also hack old remote controls to use as game components.

I can get it to repsond correctly to The ir codes and transmit. However when you transmit it prevents any further Ir codes being received. I have tried (I think every variation of using irecv.resume() in different locations. Both in the main loop and the subroutines. A snippet of the code is below.

I know it is probably that I can't see the wood for the trees...but does anyone have concrete suggestions as to where the irrecv.resume needs to go.

(ie, can it just go in the second set of subroutines in loop or does it need to be called in every subroutine?, or have I misinterpreted something very basic.)

Regards
John


void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
translateIR();
for (int z=0; z<2; z++) // ignore 2nd and 3rd signal repeat
{
irrecv.resume(); // receive the next value

}
}
//othercodehere

if(FIRE != 0){ //acts on trigger state
shoot();//performs send function

}
triggers(); // detects trigger state and sets FIRE value

}

john said...

estoxeAll sorted, used IR dump demo as the base to solve this. Am now calling the subroutines from within a series of if statements, each with their own resume command.
thanks

Anonymous said...

Hi.. I was facing a problem that I was not able to playback the IR code using the IRrecord example code. The code was displaying the hexcodes read from the remote control. But it was not replaying the hex code. The circuit used was the same.. except had I used mega2560..I used IRsenddemo also.. but no results..
Please help..

Ron Henderson said...

I am having trouble with when I try to load or run the program (IRrecDump)Error is: IRrecv irrecv(RECV_PIN); Also the IRremote.h is not turning color orange in any IR program. I am using Arduino MEGA 2560. Would anyone be so kind and help??

Santo said...

Thank you very much!!

arvind said...

Hi Ken, Thanks a lot for this library. Could you let me know how do I convert the codes received from the remote using IRrecvdump code, into hexadecimal?

Cheers!

Giuseppe Barbesino said...

I have tried is excatly as decsribed and cannot get it to work. It gets the code, responds to the button, but the IR LED does not shoot. I have troubleshot it in different ways: trying different leds, different resistors different remotes, it won't work. What am I doing wrong???

mrx23dot said...

http://ubiyubix.wordpress.com/2012/05/05/porting-the-arduino-irremote-library-to-the-attiny4313/

MOHIT ADITYA said...

how can we use this circuit for multiple functions ?? like for different functions of television by adding more push buttons in the circuit (say 4 functions) ????

Surya123 said...

Can you please tell me how to change IR library for SAMSUNG LED TV UE40B8000?? Reply me ASAP..Thanks in advance

Surya123 said...

Can you please tell me how to change IR library for SAMSUNG LED TV UE40B8000?? Reply me ASAP..Thanks in advance

mohaideen said...

I have use follwing program. but it gives the error like

sketch_jan27a:3: error: 'IRSend' does not name a type

and i incuded IRremote file into library



#include
IRsend irsend

void setup()
{
Serial.begin(9600);
}

void loop()
{
if(Serial.read()!=-1)
{
for(int i=0; i<3; i++)
{
irsend.sendSony(0xa90,12);
delay(40);
}
}
}

mohaideen said...

I have use follwing program. but it gives the error like

sketch_jan27a:3: error: 'IRSend' does not name a type

and i incuded IRremote file into library



#include
IRsend irsend

void setup()
{
Serial.begin(9600);
}

void loop()
{
if(Serial.read()!=-1)
{
for(int i=0; i<3; i++)
{
irsend.sendSony(0xa90,12);
delay(40);
}
}
}

par said...

Hi Ken, thanks a bunch for your work on IR/Arduino, it is amazing and very helpful! I'd like to build a universal remote, that can read in codes from any remote and store them. Do you think the right thing to do is use raw codes or hex codes? I am guessing that if I use hex, then I am at the mercy what I can decode, is that correct?

Ian Scott said...

Hi I've being playing with the irRecord code for a while but I cant figure out on how to do something. Is there some way I can record at least four IR signals and have 4 buttons to send them again

Tyrone Williams said...

Thank you so much for this marvellous library, which has taught me a lot. I have an 8 gang relay system for controlling different lighting and items in my living room, and as a beginner am getting a bit stuck. I use a universal remote which when pointed at the IR receiver on the arduino board, can successfully receive the eight desired buttons (I have all 10 number keys 0-9 set. My problem is that when I try to modify the program in which a button press toggles on or off the relay, I cannot get it to work with other buttons (1 to 8)

My code is:

#include

int RECV_PIN = 2;
int relay1 = 9;
int relay2 = 10;
int relay3 = 3;
int relay4 = 4;
int relay5 = 5;
int relay6 = 6;
int relay7 = 7;
int relay8 = 8;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
pinMode(13, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8 , HIGH);
}
int on = 0;
unsigned long last = millis();

void loop() {
if (irrecv.decode(&results)) {
if (results.value == 16724175)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay1, on ? HIGH : LOW);
last = millis();
irrecv.resume();
}}}

I tired to add other buttons as the dec codes in between the loop. I copied the HEX codes read from the remote, then converted to DEC via windows calulator. Each code works if I alter the above code to a specific number, but I cannot set it to, for example, Switch on relay 4 then switch off relay 5 then switch oof relay 4 by simply toggle pressing the buttons.Times eight! (though I would be happy to get it to work with four or six. Maybe I have to use arrays in some magical way? Please help, or perhaps point me in the right direction... any thanks, Tyrone

Tyrone Williams said...

Hi,

After much hair-tugging, I have finally got it all working remote buttons 1 to 8 toggle the 8 gang relay, button 9 switches all on to test and 0 shuts down all eight. :) here's the code if it helps anyone.

#include

int RECV_PIN = 2;
int relay1 = 9;
int relay2 = 10;
int relay3 = 3;
int relay4 = 4;
int relay5 = 5;
int relay6 = 6;
int relay7 = 7;
int relay8 = 8;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
pinMode(13, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8 , HIGH);
}

int on = 0;
unsigned long last = millis();

void loop() {
if (irrecv.decode(&results)) {
if (results.value == 16724175)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay1, on ? HIGH : LOW);
}
if (results.value == 16718055)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay2, on ? HIGH : LOW);
}
if (results.value == 16743045)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay3, on ? HIGH : LOW);
}
if (results.value == 16716015)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay4, on ? HIGH : LOW);
}
if (results.value == 16726215)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay5, on ? HIGH : LOW);
}if (results.value == 16734885)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay6, on ? HIGH : LOW);
}
if (results.value == 16728765)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay7, on ? HIGH : LOW);
}
if (results.value == 16730805)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay8, on ? HIGH : LOW);
}
if (results.value == 16738455)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
digitalWrite(relay7, HIGH);
digitalWrite(relay8 , HIGH);
}
if (results.value == 16732845)
if (millis() - last > 250) {
on = !on;
digitalWrite(relay1, LOW);
digitalWrite(relay2, LOW);
digitalWrite(relay3, LOW);
digitalWrite(relay4, LOW);
digitalWrite(relay5, LOW);
digitalWrite(relay6, LOW);
digitalWrite(relay7, LOW);
digitalWrite(relay8 , LOW);
}
last = millis();
irrecv.resume(); // Receive the next value
}}

thomas said...

Can anyone figure out why my Visio TV will come on with the 0x20DF10EF NEC code as duplicated from two different remotes with one power button, but not turn back off?

Anonymous said...

Thank you very much for your awesome library! But I have a strange behavior: I use both (Ir receiver and Ir transmitter) on my Arduino development (based on ATMega2560). The reception works fine, but the receiver sometimes doesn't work properly. I notice it's when Ir transmitter receive something, just after, or almost, the transmitter doesn't send something; the next try is fine after. I can't analyse what. But I think this trouble comes from interrupt function in IRremotelib.
Thanks for your help guys!

xnaron said...

What is the range of the IR supposed to be for the transmitter IR led? I am only getting about 6 inches.

Ricardo said...

Is there possible to control two or more IR emitters independently using IRremote library?

David Wayne said...

Hi, my name is David and I built a remote to control the power, volume, and channels of my TV. While away at school it works but when I got home I hooked it back up to the Comcast Cable box I have and the channels no longer work (because its changing the TV channels, and not the cable channels)(the TV needs to stay on channel 3) Ive been trying to figure out how to get my remote to send out the comcast remote channel codes but can't seem to figure it out. Anyone have any ideas? Id really appreciate it. Thank you!!!

Anonymous said...

How can I translate Codes from the LIRC Format to your IRSend-Format?

An example would be nice.

Anonymous said...

I found the description of the LIRC Format: http://winlirc.sourceforge.net/technicaldetails.html

Jake said...

I'm curious about what the maximum distance that it can receive signals. Where I live, emergency vehicles use a system of IR blasters and receivers to manipulate traffic lights. If I could somehow record a signal from an ambulance/firetruck it would be easy to reproduce. This of course is all just a concept.
George w bush passed a bill in 2004 making it a federal crime to manipulate traffic controls.
I've done some research online and I couldn't find any instances of this being done before. I would still like to look into this further. Email me your thoughts and comments. jacobpflug@gmail.com