Arduino Infrared Remote Tutorial

469,673

245

123

Published

Introduction: Arduino Infrared Remote Tutorial

About: I am a full time software engineer and enjoy working on various projects in my spare time, especially Arduino, electronics, 3D printing and woodworking.

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/

10 People Made This Project!

Recommendations

  • Oil Contest

    Oil Contest
  • Water Contest

    Water Contest
  • Creative Misuse Contest

    Creative Misuse Contest

123 Discussions

i got the hexa codes in my remote but how can i send the codes to the consumer products please help me

thanks

Hi i tried this project bur I'm getting error messages about undeclared types any haelp would be appreciated, thanks

heres the error code

Arduino: 1.8.5 (Mac OS X), Board: "Arduino/Genuino Uno"

IR_receiver_test:2: error: 'IRrecv' does not name a type

IRrecv irrecv(RECV_PIN);

^

IR_receiver_test:3: error: 'decode_results' does not name a type

decode_results results;

^

/Users/kilian/Documents/Arduino/IR_receiver_test/IR_receiver_test.ino: In function 'void setup()':

IR_receiver_test:8: error: 'irrecv' was not declared in this scope

irrecv.enableIRIn(); // Start the receiver

^

/Users/kilian/Documents/Arduino/IR_receiver_test/IR_receiver_test.ino: In function 'void loop()':

IR_receiver_test:13: error: 'irrecv' was not declared in this scope

if (irrecv.decode(&results))

^

IR_receiver_test:13: error: 'results' was not declared in this scope

if (irrecv.decode(&results))

^

exit status 1

'IRrecv' does not name a type

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

0
user
DaanB12

Question 3 months ago

Hello?


what does this error mean why i dont see anyting on the serial Monitor

the hole error is this

C:\Users\Daan\Desktop\sketch_mar11b\sketch_mar11b.ino:9:23: fatal error: IRemote.h: No such file or directory

#include <IRemote.h>

^

compilation terminated.

exit status 1
Fout bij het compileren van board Arduino/Genuino Uno

2018-03-20.png20180320_185435.jpg
0
user
DaanB12

Question 4 months ago

what does this error mean

2018-03-18.png
0
user
DaanB12

Question 4 months ago

now i get this error

dit i need to conect my arduino board

2018-03-15.png
2 more answers

hello i'm sorry but I do not see the whole mistake for screenhot

did you add the IRremote library from Arduino IDE? checked please

I do not see the whole mistake

help1.pnghelp2.JPG

HELLO! you forgot: #include <IRremote.h>

there is an error in the tutorial "<IRemote.h>" instead of "<IRremote.h>"

help.png
0
user
SathR

5 months ago

Some pictures have only the sensor attached to the protoboard and then to the Arduino. Others have the sensor attached to that little module. Got confused with this also while looking to buy the components. Is that any difference? If so, what is the difference?

I tried it and it worked in first attempt

thanks

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!

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.

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
}
}
4 replies

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

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

can anybody help me ??

my board is not taking this programe

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?