Introduction: Arduino Infrared Remote Tutorial

It is really easy to control an Arduino using an infrared remote. There is one particular remote that is available from multiple sources and is really quite cheap, they look and operate in a very similar way.

NEOMART Raspberry Pi HX1838 Infrared Remote Control Ir Receiver Module DIY Kit.  Amazon
Kootek Raspberry Pi Infrared Remote Control Ir Receiver Module DIY Kit. Amazon
KIT,IR REMOTE,IR RECIVER,ARDUI,COMPATIBLE  Jameco

The problem is that documentation seems to be scarce for these particular remotes. Here is how I figured out how to use them.
 

Step 1: Assemble Circuit

You will need one Arduino for this. I used a UNO, but just about any Arduino should work. First wire up the infrared receiver that came with your kit. There are 3 wires, PWR, GND, and SIG, I used port 11 for SIG. Note! some readers have reported that their sensor has different wiring, double check it yourself.

Step 2: Download IR Library

In order to reverse engineer the remote and obtain the codes for each button we are going to need to download and install the following library.

https://github.com/shirriff/Arduino-IRremote

Extract the file in your libraries directory. e.g.  ( C:\electronics\arduino-1.0.5\libraries )
note: I had to rename the library because the name was too long, I just renamed it to IR.

 

Step 3: Add Library to Sketch

With the IR folder ( or whatever you named it) now in your libraries directory, we can import it into a new sketch.

Start a new sketch and the Click  

        Sketch->Import Library->IR.

Step 4: Paste Code and Compile

Paste the following code into the new sketch. Then verify it compiles.


#include <IRemote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
  if (irrecv.decode(&results))
    {
     Serial.println(results.value, HEX);
     irrecv.resume(); // Receive the next value
    }
}

 

Step 5: Open the Serial Monitor

Connect the Arduino to your computer using the usb port, then upload the sketch. Open up the Serial Monitor, get the remote and press the buttons. Some hex codes should appear on the Serial Monitor.

        

Step 6: Record Button Codes

Here are the codes that I got for the white remote. FFFFFF is a repeat command, you'll get a stream of them if you hold down a button.

PWR       FF629D     
CH          FFE21D        
|<<          FF22DD  
>|            FFC23D              
>>|          FF02FD               
-              FFE01F 
Plus        FFA857         
EQ          FF906F          
0             FF6897            
100         FF9867           
200         FFB04F           
1             FF30CF                 
2             FF18E7                 
3             FF7A85                  
4             FF10EF                   
5             FF38C7                    
6             FF5AA5                  
7             FF42BD                  
8             FF48B5             
9             FF52AD 

and here are the codes I got from the black remote.

PWR                               FD00FF
VOL                                FD807F
FUNC/STOP                    FD40BF
|<<                                   FD20DF
>|                                     FDA05F
>>|                                   FD609F
DOWN                             FD10EF
VOL                                 FD906F
UP                                   FD50AF
0                                      FD30CF
EQ                                   FDB04F
ST/REPT                         FD708F
1                                      FD08F7
2                                      FD8877
3                                      FD48B7
4                                      FD28D7
5                                      FDA857
6                                      FD6897
7                                      FD18E7
8                                      FD9867
9                                      FD58A7       

Step 7: Works on Any Remote!

Now go grab a bunch or remotes from around the house, and give those a try! I got a direct-tv remote and the smartphone pod/remote for a Helo TC remote controlled helicopter. This circuit showed the code for both of these remotes.

Here is the project that inspired me to write this up!

http://2manyprojects.net/arduino-remote-control/

Comments

author
nadia95ab made it! (author)2017-07-22

hi

all i'm getting is FFFFFFFF

it doesn't change when i press other buttons

i don't know what the problem is

help plz

author
عمرج2 made it! (author)2017-07-18

I found this error plz help :

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:16: error: 'TKD2' was not declared in this scope

int RECV_PIN = TKD2; // the pin the IR receiver is connected to

^

Multiple libraries were found for "IRremote.h"

Used: C:\Program Files (x86)\Arduino\libraries\RobotIRremote

Not used: C:\Users\umer\Documents\Arduino\libraries\Arduino-IRremote-master

exit status 1

Error compiling for board Arduino Nano.

author
desyanDD made it! (author)desyanDD2017-07-19

Delete your folder RobotIRremote in arduino libraries.

then don't forget to include <IRemote.h> in your code. or go to Sketch > include library > add .ZIP library >> and choose your zip file of IR library that you've downloaded

author
BriceL1 made it! (author)2016-04-29

I'm getting a compiling error: 'TKD2 was not declared in this scope'. Anyone know how to fix this? Thanks

author
desyanDD made it! (author)desyanDD2017-07-19

Don't forget to include <IRemote.h>

or

Sketch > include library > IR

author
fanche made it! (author)fanche2016-07-14

How did you solve that problem, because I encounter this

Thanks

author
andthebandplaydon made it! (author)2017-06-01

In my case, using HEX to return the values from the remote always caused an error. If the same ever happens to anyone reading this, use OCT or DEC instead of HEX. These return values containing only digits, but are almost equally useful :)

author
thanushg made it! (author)2017-04-21

hi there... i need 2 noe.. is there any way we can send or display temperature from the temp sensor in arduino at the lcd of a ir remote control which also has ir receiver ... can v send commands for the remote to display some info collected by arduino??? USING IR ONLY !!

author
BenVink made it! (author)2016-11-16

Wow great tutorial.

I have one question, do somebody know how it's possible that i get only numbers, like 808, 26, 7 and i dont get hex codes.

author
AndrewW360 made it! (author)AndrewW3602017-04-12

In the Serial.println bit of code, just take away "HEX."

author
P5ychPr0 made it! (author)2015-12-27

OK I have got this remote and it is the king of weird codes. Heres what I get when a press the power button and hold it for sometime-

C722B335

8651F175

D440F4BA

673D41A

D440F4BA

673D41A

C722B335

673D41A

C722B335

673D41A

D440F4BA

673D41A

C722B335

673D41A

Heres what i get when I press it shortly so that i get only one reading per press-

D440F4BA

EDB7BF84

C722B335

7B33B312

C722B335

EDB7BF84

D440F4BA

EDB7BF84

C722B335

8651F175

C722B335

EDB7BF84

D440F4BA

EDB7BF84

C722B335

EDB7BF84

C722B335

F8D5FDE7

D440F4BA

EDB7BF84

I have previously cloned Sony, Samsung and LG remotes, but this DTH remote is a b**ch. The company isn't international and I live in India, so I can't find a module for it. Any help would be welcome.

Thanks

author
statbat made it! (author)statbat2016-05-23

YES. I also at times get these codes. I dont understand WHY. sometimes i get correct code and sometimes I get these codes. Such an un-reliable remote.

author
AndrewW360 made it! (author)AndrewW3602017-04-12

I know why... I did some experimenting and I realised that you have to point the remote at a close range, and it also has to be level - I mean, at the same position. It gives the same result if you press the button at the same position.

author
PabloS84 made it! (author)PabloS842016-10-31

I was also having this issue, I however realised it was because of the batteries in the remote were dying. Swapped them for new ones and they now detect a steady hex!

author
Udon made it! (author)Udon2016-08-06

Don't want to resurrect a dead horse and then beat him - this post is a bit old.

But my ten cents....

.....is that maybe the codes ARE actually the same on each press, but perhaps the arduino gets lost in the the bits and doesn't catch where start and end is. Especially if you're holding the button down, then it just gets a really long set of pulses and doesn't know whats going on....whereas the TV or aircon knows what to look for among the mess...

Aircon to self:"oh look! A power on/off command! That must be it! What are the chances of it being something else...?"

Arduino:"..............................ugh...........................oh man................wha?..........................................gaaaaaaaaaa! TMI! TMI! TMI! It doesn't make any sense! Why are you doing this to me!?"

Among the frequency of pulsing, start bits, stop bits, and length of the train of pulses that is a single signal, maybe it just is too much for it sometimes.

So what I mean is, it might not be as bad as you think. Maybe code can fix it, or maybe some cheap logic analyzer can help you see what's going on.

author
AndrewW360 made it! (author)2017-04-12

Thank you so much! This helped greatly! #Set4Lyfe

author
zeus_is_cool made it! (author)2016-12-26

Hey guys,

I'm relatively new to arduino, and keep getting this error code with this program.

avrdude: ser_open(): can't open device "\\.\COM4": The system cannot find the file specified.

Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#up... for suggestions.

Anyone help?

author
CalistoH1 made it! (author)CalistoH12017-02-19

just click on tools, then under com it should say the port its conected to, click on it and compile again

author
zeus_is_cool made it! (author)zeus_is_cool2016-12-26

I found it out.

I just forgot to choose the port to hook up the arduino.

author
KajaA made it! (author)2017-01-18

Hello, I found the solution for compiling errors!

1.) You must download this folder:

https://github.com/z3t0/Arduino-IRremote

2.) Place folder in C:\Program Files (x86)\Arduino\libraries

3.) Rename it to "IRremote"

4.) Delete "RobotIRremote" folder.

5.) There is error in code at very top #include <IRemote.h> -->r is missing,

put in: #include <IRremote.h>

I managed it to work that way. Hope you will too! cheers

author
MarcusB57 made it! (author)2017-01-11

It's work fine!

IMG_20170111_231129.jpg
author
TheAwesome150 made it! (author)2017-01-08

SORRY, IT DOESNT WORK!!! It Says the sketch has errors when i compile it...

author
JohnN268 made it! (author)2017-01-07

Watch out, some IR receivers have the OUT on pin#1.

How can I clear the input buffer for the next IR read?

author
Saood Fraz made it! (author)2016-12-08

How can i read IR receiver output on Arduino mega

author
IshaanW made it! (author)2016-12-05

the code just wont compile!

Arduino: 1.6.13 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from C:\Users\...\Documents\Arduino\recieverCode\recieverCode.ino:4:0:

C:\Users\...\Documents\Arduino\libraries\Arduino-IRremote-master/ir_Lego_PF_BitStreamEncoder.h: In member function 'int LegoPfBitStreamEncoder::getRepeatStopPause() const':

C:\Users\...\Documents\Arduino\libraries\Arduino-IRremote-master/ir_Lego_PF_BitStreamEncoder.h:107:38: warning: integer overflow in expression [-Woverflow]

return STOP_PAUSE_DURATION + 5 * MAX_MESSAGE_LENGTH - messageLength;

^

This application has requested the Runtime to terminate it in an unusual way.

Please contact the application's support team for more information.

Cannot create temporary file in C:\Users\...\AppData\Local\Temp\: Permission denied

exit status 3

Error compiling for board Arduino/Genuino Uno.

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

author
daveed.alvarez made it! (author)2016-07-31

The sketch won't compile:

It gets the following errors:

sketch_jul31b:3: error: 'IRrecv' does not name a type

sketch_jul31b:4: error: 'decode_results' does not name a type

sketch_jul31b.ino: In function 'void setup()':

sketch_jul31b:9: error: 'irrecv' was not declared in this scope

sketch_jul31b.ino: In function 'void loop()':

sketch_jul31b:14: error: 'irrecv' was not declared in this scope

sketch_jul31b:14: error: 'results' was not declared in this scope

The code:

#include <IRemote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}

void loop()
{
if (irrecv.decode(&results))
{
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}
author
SachitC made it! (author)SachitC2016-08-15

do you have the library installed for it and included for the IR receiver at the top of the code?

author
SenthilS8 made it! (author)SenthilS82016-11-29

if the IRremote is used these errors don't appear. If IRemote is used the above errors appear

author
thunderboympm made it! (author)2014-09-03

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: sketch_sep04a.cpp.elf section .text will not fit in region text

c:/program files (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: region text overflowed by 722 bytes

I got am error like this? what can i do? how i solve this? my board is arduino with atmega8 (FREEDUINO)

ardino error.png
author
Wild Hunter made it! (author)Wild Hunter2014-09-13

Hi @thunderboympm

You made mistake in writing the header file,

If you see your attached image, you have written "#include<IRremote.h>"

Correct it by writing; "#include<IRemote.h>

Happy :-)

author
dattani made it! (author)dattani2016-11-27

What can I do if i want to Compare two IR received Strings ???

author
William Liisberg made it! (author)2016-11-08

Didn't get anything on the serial monitor... Then i realized i had forgotten to change the pin you read on. Haha!

author
PabloS84 made it! (author)2016-11-01

Great tutorial! I broke apart a small IR Helicopter toy I had around. I used its IR sensor for this tutorial. What's strange, is the IR Sensor won't detect any signal from it's original remote, but it reads signals from any other TV remotes I got hanging around.

Anyone has any clue what I can be missing?

The Remote has 3 "chanels" or 3 comm protocols so that you can fly up to 3 of these things without the signals interfering, but the IR sensor won't pick up any kind of signal whatsoever!

Cheers again for this great piece of info!

author
RifkyR3 made it! (author)2016-10-08

IR remote does not display in the serial monitor IRreceive I think I uploaded the code that nothing is wrong as well, but when I stick my hand into IRreceiver monitor displays the serial code ..

author
م.رعدا made it! (author)2016-01-22

Hi I need to resolve is there who can help me

Thank you

aaaa.PNG
author
JUST CHILIN made it! (author)JUST CHILIN2016-08-24

delete the robort ir library its creating the problem

author
rafaelnfs made it! (author)rafaelnfs2016-05-01

you have open arduino librarys in your case, E:\arduino-nightly\libraries and delete this library (RobotIRremote). close arduino and open again & Ready :)

author
Piriax made it! (author)2016-08-23

Works like a charm(and yes, it's not connected atm)

2016-08-21 19.31.50.jpg
author
munixpx made it! (author)2016-07-14

Nice and easy, works also with my Android phone as a remote!!

author
pp1307 made it! (author)2016-06-24

Nice Abstract.

author
ananth raj made it! (author)2016-01-22

Thanks a lot.... I have been breaking my head to understand IR buttons coding. Helped a lot.

author
statbat made it! (author)statbat2016-05-23

Mine too. This guy is so bad, he should atleast have decency to update his tutorial and mention about it. I fried mine also.

author
greenberg70000 made it! (author)2016-05-11

How can you take this and make it do something when you press a button. Such as Print a line or run a motor?

author
Brandon_214 made it! (author)Brandon_2142016-05-18

Yes I have programmed it to receive code from a Sony remote and move a servo

author
greenberg70000 made it! (author)greenberg700002016-05-18

Can you post that if pressed code?

author
Roboguy2811 made it! (author)2016-05-05

Do you have a program to connect motors to arduino and control them using IR remote?

author
rafaelnfs made it! (author)2016-05-01

my code for one led and remote control of MP3 player.

160501-214539.jpg
author
rafaelnfs made it! (author)rafaelnfs2016-05-01

#include <IRremote.h> // libraria IR control remoto.

int RECV_PIN = 11;// pin donde recibiremos la señal

#define ON 0xFFA25D // direccion es FFA25D pero se le agrega el 0x

// porque asi se le dice al arduino que es HEXADECIMAL.

#define OFF 0xFF629D // tecla control stop

unsigned int led = 13;

boolean estado = false;

IRrecv irrecv(RECV_PIN); //

decode_results results;

// aca guardamos el dato que nos del el IR

void setup()

{

//Serial.begin(9600);

irrecv.enableIRIn(); // Inicia el IR in

pinMode(led,OUTPUT); // configuramos el led como salida

}

void loop() {

// si el IR recibe una señal se habilita la funcion.

if (irrecv.decode(&results)) {

switch (results.value)

// si el resultado obtenido esta en el case se ejecuta

{

case ON:

// en el caso que sea la direccion 0xFFA25D

// se ejecuta lo siguient

if (estado ? false : true){

// si es estado del es false se ejecuta

// y se asigna al estado true.

estado = true;

digitalWrite(led,estado);

}else

{

//sino se le asigna false nuevamente para que el led

// permanezca apagado

estado = false;

digitalWrite(led,estado);

}

break;

}

delay(200); // 1/5 second delay for arbitrary clicks. Will implement debounce later.

irrecv.resume(); // Receive the next value

}

}

author
SamL74 made it! (author)2016-04-10

Will any IRreceiver work with any remote? OR do I need a specific one? I've been trying to do this project, however my receiver and my remote don't seem to be working. Is there a way that my project could have failed?

author
rafaelnfs made it! (author)rafaelnfs2016-05-01

work with any Remote control I tested the skecth but I have to delete de RobotIRemote (included as default )
this is my code:
apagar = FFA25D

stop = FF629D

mute = FFE21D

mode = FF22DD

back-row = FF02FD

EQ = FFC23D

back = FFE01F

adelante = FFA857

play/stop = FF906F

vol+ = FF6897

vol- = FF9867

Numero 0 = FFB04F

Numero 1 = FF30CF

Numero 2 = FF18E7

Numero 3 = FF7A85

Numero 4 = FF10EF

Numero 5 = FF38C7

Numero 6 = FF5AA5

Numero 7 = FF42BD

Numero 8 = FF4AB5

Numero 9 = FF52A

About This Instructable

390,388views

229favorites

License:

Bio: I am a full time software engineer and enjoy working on various projects in my spare time, especially Arduino, electronics, 3D printing and woodworking.
More by astrodan3:Arduino 6 wire Stepper Motor Tutorial how to make vermicompostArduino Infrared Remote tutorial
Add instructable to: