Introduction: Arduino Infrared Remote Tutorial

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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!

Picture of 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

DevinderS5 (author)2017-12-10

I tried it and it worked in first attempt

thanks

Zoe Bell (author)2017-11-26

Worked nicely for me, thank you.

gets a bit dicey if you are too far away but that is a problem with hardware not software.

Simple to use and effective!

AlanMatthews (author)2017-10-31

I've found this to be extraordinarily unreliable at anything less than six inches making it unusable for my application. The electronics work, just the work necessary to count leading and trailing clock edges with precision, coupled with the hash concept (so there's always a reduction of precision) makes it unpredictable. It uses lots of cycles which would be better off offloaded to another chip with better signal processing.

I'm sure each remote has it's own bias which is why there're different profiles with different timings for various manufacturers. Apparently the manufacturers are able to decode their signals though as most remotes I've used work well.

This is an ideal problem for an AI engine. Lots of unpredictability within the time domain yet only certain answers are feasible. While Ken Shirriff's code is all we have and to be applauded, it's not workable for most applications. An AI chip and the learning database wouldn't be cheap either but you get what you pay for, as usual.

daveed.alvarez (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
}
}

this program is not uploading on my board

nooorayyyy (author)nooorayyyy2017-08-14

can you help me out?

SachitC (author)daveed.alvarez2016-08-15

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

SenthilS8 (author)SachitC2016-11-29

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

nooorayyyy (author)2017-08-14

can anybody help me ??

my board is not taking this programe

trickybilly. (author)2017-08-04

Thank you so much, it worked for my TV remote. I have the CAR MP3 remote. It was pretty hard to get out the battery holder. I fed it a 3V Energizer CR2032 battery and I could barely close it's door. Now it won't function? How do you feed this remote/what battery do you use?

nadia95ab (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

عمرج2 (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.

desyanDD (author)عمرج22017-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

BriceL1 (author)2016-04-29

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

desyanDD (author)BriceL12017-07-19

Don't forget to include <IRemote.h>

or

Sketch > include library > IR

fanche (author)BriceL12016-07-14

How did you solve that problem, because I encounter this

Thanks

andthebandplaydon (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 :)

thanushg (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 !!

BenVink (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.

AndrewW360 (author)BenVink2017-04-12

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

P5ychPr0 (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

statbat (author)P5ychPr02016-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.

AndrewW360 (author)statbat2017-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.

PabloS84 (author)statbat2016-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!

Udon (author)P5ychPr02016-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.

AndrewW360 (author)2017-04-12

Thank you so much! This helped greatly! #Set4Lyfe

zeus_is_cool (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?

CalistoH1 (author)zeus_is_cool2017-02-19

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

I found it out.

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

KajaA (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

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

It's work fine!

TheAwesome150 (author)2017-01-08

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

JohnN268 (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?

Saood Fraz (author)2016-12-08

How can i read IR receiver output on Arduino mega

IshaanW (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.

thunderboympm (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)

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 :-)

dattani (author)Wild Hunter2016-11-27

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

William Liisberg (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!

PabloS84 (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!

RifkyR3 (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 ..

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

Hi I need to resolve is there who can help me

Thank you

JUST CHILIN (author)م.رعدا2016-08-24

delete the robort ir library its creating the problem

rafaelnfs (author)م.رعدا2016-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 :)

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

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

munixpx (author)2016-07-14

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

pp1307 (author)2016-06-24

Nice Abstract.

ananth raj (author)2016-01-22

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

statbat (author)ananth raj2016-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.

greenberg70000 (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?

About This Instructable

423,846views

237favorites

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: