Instructables

How to Use IR Remotes with Arduino (Current and Updated!!!)

Picture of How to Use IR Remotes with Arduino (Current and Updated!!!)
I'm tired of these complicated tutorials on how to use certain things. I like simple, easy to understand, step by step instructions. My biggest problem was with IR and POV*. I've finally mastered how to control my project with any TV remote in a few minutes. In this i'ble I'm going to show you simple, step by step instructions on how to control just about anything with your IR remote.

By the way this tutorial is new and updated and works! Last update [ 8/1/13 ]
 
Remove these adsRemove these ads by Signing Up

Step 1: Ingredients:

Electronics:
  • Arduino
  • Any IR remote
  • IR receiver
  • Breadboard
  • Jumper Cables
  • LED

And here is the Make-To-Learn contest questions! - don't forget to vote!

What did you make?
Well I didn't make anything specific in this instructable but it is more of a guide to how to make your other projects 'wireless'.
My projects works by taking TV remotes and other remotes, converting their signals to numbers, and using them.
How did you make it?
I've been working on trying to use IR remotes. All the tutorials I found didn't really put the all the bits and pieces together for me. My main goal was to make an easy tutorial for others to follow.
Where did you make it?
At my computer. I am now able to control my robots and other stuff, like lights and lighting. For instance, I could make it so that whenever I hit the play button on my DVD player remote, the lights in the room dim, or go out.
What did you learn?
My biggest challenge was finding a IR decoder that worked, and then finding installing the proper library.

Step 2: Downloads

Here is the link to all the downloads in this instructable.
(Sorry for some odd reason the link won't work so just copy and paste it in your browser)

http://www.mediafire.com/download/cv0r5191fvtq0y2/IR_I'ble_Package.zip
evikartika7 days ago

I've installed the IRremote library. Opened IR Decode, compiled and uploaded to Arduino. All looks as it should yet nothing prints in the serial monitor. I've tried ALL the baud rates (although I imagine you used 9600) yet the issue persists.What should i do??i have been stuck here..please help me..

PM me your code.

i've used your IR Decode sketch to get the recognizing IR signal and follow the step given,nothing wrong when i uploaded the sketch..but the problem is when nothing prints in the serial monitor.

#include <IRremote.h>

int IRpin = 11;

IRrecv irrecv(IRpin);

decode_results results;

void setup()

{

Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver

}

void loop()

{

if (irrecv.decode(&results))

{

Serial.println(results.value, DEC); // Print the Serial 'results.value'

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

}

}

OK I used your code and everything works fine for me. Please refer to the last step for trouble shooting. If you still have trouble you may have issues with your serial monitor. Try making another project and see if you can print to the serial.

zulkola16 days ago

why my button number keep changes, sometimes 16720605, sometimes 50470553..it is not stable..why?

Enjoying Electronics (author)  zulkola15 days ago
I can't be sure maybe you just have a really cheap remote, its malfunctioning, or there's interference.

What I would do is to use a switch/case statement for both numbers but have them do the same thing, so no matter which of the two numbers comes out, it'll do the same thing.

That help a little?
kminton31 month ago

I cant get the switch cases to work like the last LED test the LED just stays on and shuts off for a brief moment when i press a remote button heres the code:

#include <IRremote.h>

int IRpin = 11; // pin for the IR sensor

int LED = 13; // LED pin

IRrecv irrecv(IRpin);

decode_results results;

boolean LEDon = true; // initializing LEDon as true

void setup()

{

Serial.begin(9600);

irrecv.enableIRIn(); // Start the receiver

pinMode(LED, OUTPUT);

}

void loop()

{

if (irrecv.decode(&results))

{

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

}

switch(results.value)

{

case 1637875967:

if (LEDon == true) // is LEDon equal to true?

{

LEDon = false;

digitalWrite(LED, HIGH);

delay(100); // keeps the transistion smooth

}

else

{

LEDon = true;

digitalWrite(LED, LOW);

delay(100);

}

Enjoying Electronics (author)  kminton31 month ago

This my code and I know that it works, so you must be doing something wrong. Make sure you open up Serial Monitor and see what's going on in there. What do the numbers look like? What numbers are shown when you press a button on your remote?

You are also missing the break; statement

steinie441 month ago

The fix:

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

belongs at the end if the

if (irrecv.decode(&results))

here is a example:

[code]
/*
DVR IR Receiver 03 March 2014 JDS
* See: http://www.instructables.com/id/The-Easiest-Way-to-Use-Any-IR-Remote-with-Ardiuno/?ALLSTEPS

The IR sensor's pins are attached to Arduino as so:
Pin 1 to Vout (pin 11 on Arduino)
Pin 2 to GND
Pin 3 to Vcc (+5v from Arduino)
*/

#include <IRremote.h>

int IRpin = 11; // pin for the IR sensor
int LED = 13; // LED pin
IRrecv irrecv(IRpin);
decode_results results;

boolean LEDon = true; // initializing LEDon as true

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

void loop()
{
digitalWrite(LED, LOW);
if (irrecv.decode(&results))
{

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


switch(results.value)
{
case 16720350:
Serial.println("MULT");
break;

case 16763190:
Serial.println("POWER");
break;

case 16716270:
Serial.println("SEARCH");
break;

case 16714230:
Serial.println("|<");
break;

case 16718310:
Serial.println("||<");
break;

case 16724430:
Serial.println("|>");
break;

case 16728510:
Serial.println(">||");
break;

case 16726470:
Serial.println(">>");
break;

case 16761150:
Serial.println(">|");
break;

case 16771350:
Serial.println("ADD");
break;

case 16746870:
Serial.println("FN");
break;

case 16742790:
Serial.println("MENU");
break;

case 16767270:
Serial.println("Left");
break;

case 16750950:
Serial.println("Right");
break;

case 16755030:
Serial.println("Up");
break;

case 16734630:
Serial.println("Down");
break;

case 16769310:
Serial.println("1");
break;

case 16736670:
Serial.println("2");
break;

case 16752990:
Serial.println("3");
break;

case 16765230:
Serial.println("4");
break;

case 16732590:
Serial.println("5");
break;

case 16748910:
Serial.println("6");
break;

case 16773390:
Serial.println("7");
break;

case 16740750:
Serial.println("8");
break;

case 16757070:
Serial.println("9");
break;

case 16730550:
Serial.println("0");
break;

case 16738710:
Serial.println("ESC");
break;

case 16722390:
Serial.println("-/--");
break;

default:
digitalWrite(LED, HIGH);

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

}


[/code]

wildbananas1 month ago

As promised I learnt this in a few minutes, thanks to all the links within,

kleinjm1 month ago

Great job! Much simpler than what I have been doing. Thanks!

Enjoying Electronics (author)  kleinjm1 month ago
Awesome! Glad I could help!
visakan222 months ago

Hi, Thanks for a good tutorial. It works great. But I am unable to use pin 8 or pin 0 on my Uno (there is no signal and Tx led does not flash). Any thing special about pin 11?. Thanks again.

Enjoying Electronics (author)  visakan222 months ago
Did you re-write this line to other pins?

int IRpin = 11; // pin for the IR sensor

change to

int IRpin = 8; // pin for the IR sensor

Other than that I'm pretty sure that the library is written for reading only on pin 11. You'd have to go into the library code itself and change it. I'm not sure how to do that.
skeedes6 months ago
hi, thanks a lot for the simple tut. a lot of heavy lifting gets done by the library!
but i have one issue i want to solve-

In the switch-case code you have shared, i have put a serial.println line in each of the 'case' sections. it shows the 'case' getting called even when i am not pressing the remote button anymore. it only changes once i press another button. how to avoid that? thanks


Enjoying Electronics (author)  skeedes6 months ago
Hey!

Are you forgetting to put 'break;' at the end of each case?
Hi

The breaks are there, please see the sketch below.
The problem seems to be in the 'delay' statement in the last line. Value below 1000 is causing the sensor to frequently go into a loop, repeating the same code in the serial monitor. Keep the value low like 100 or so, and you can see the result. Can my IR sensor be bad? Or do I need to pull down or something?
Thanks!

/*
* Sketch modified by Enjoying Electronics: http://www.instructables.com/member/Enjoying+Electronics/
Code based off of:
* IRremote
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* For details, see http://arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

* Special thanks to dablondeemu http://www.instructables.com/member/dablondeemu/
* and his instructable listed below, IR Remote Controlled Color Changing Cloud (Arduino)
* http://www.instructables.com/id/IR-Remote-Controlled-Color-Changing-Cloud-Arduino/


* Lets get started:

The IR sensor's pins are attached to Arduino as so:
Pin 1 to Vout (pin 11 on Arduino)
Pin 2 to GND
Pin 3 to Vcc (+5v from Arduino)

*/

#include

int IRpin = 11; // pin for the IR sensor

IRrecv irrecv(IRpin);
decode_results results;


// IR buttons STB remote #1
const long int uparrow = 2153764903;
const long int downarrow = 2153773063;
const long int rightarrow = 2153732263;
const long int leftarrow = 2153740423;
const long int okbutton = 2153765413;


/*
// IR buttons univ remote #2

const long int uparrow = 484659885;
const long int downarrow = 484651725;
const long int rightarrow = 484692525;
const long int leftarrow = 484676205;
const long int okbutton = 484661415;

*/

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

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

switch(results.value)
{

case uparrow: // up arrow
Serial.println(results.value, DEC);
break;

case downarrow: // down arrow
Serial.println(results.value, DEC);
break;

case rightarrow: // right arrow
Serial.println(results.value, DEC);
break;

case leftarrow: // left arrow
Serial.println(results.value, DEC);
break;

case okbutton: // ok button
Serial.println(results.value, DEC);
break;

delay(100);
}

}
Enjoying Electronics (author)  skeedes4 months ago
(removed by author or community request)

Hi,

Its the same, even after removing delay. You can see in this video I made of the problem. thanks

https://vimeo.com/84850648

Enjoying Electronics (author)  skeedes4 months ago
That's really not going to work, having a 1 second delay. Think about it. It runs all the code before the delay, which takes a tiny fraction of a second, then you have it pause for 1 second, then going back looking for a signal in the tiny fraction of a second. Take out the delay and it will work fine.
oyvdahl3 months ago

Hey, thanks a lot for this! This was really simple to follow.

I used some parts of your tutorial and created a tutorial for copying a remote control function: http://www.build-electronic-circuits.com/arduino-remote-control/

Thanks again!

Oyvind

MattyJ664 months ago
Great work man, Thanks heaps
plamba4 months ago
Which IR sensor/receiver did you use? They don't all have the same pin assignments and won't necessarily match what you've shown.
Enjoying Electronics (author)  plamba4 months ago
http://www.ebay.com/itm/121152972311?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649
kinaronash4 months ago
hi,
Thank you for this post it was very helpful. I have a question though, can i use more than one IR detector using this library?
ARJUNSS4 months ago
i have a problem ir library is not working it is giving error on compiling ,plz help me.

i have unzip that downloaded that zip file and i have copied that IRremote folder into arduino library folder but still it is giving error while compile.
what should i do
plzz help me.
Enjoying Electronics (author)  ARJUNSS4 months ago
What is the error? Post a picture of it. Also post your code so I can see it. What board are you using?
i am using arduino uno at mega 8 and having problem with IR library. that is giving error (C:\Users\admin\Documents\Arduino\libraries\IRremote\IRremote.cpp:13: C:\Users\admin\Documents\Arduino\libraries\IRremote\/IRremoteInt.h:87: error: 'uint8_t' does not name a type)
 
Enjoying Electronics (author)  ARJUNSS4 months ago
You installed the library wrong. Delete the old library. Download and unzip the a new one from the links I gave. Open up the IDE. Then drop down the menu 'sketch' then 'add library'. Select the IRremote folder. MAKE SURE you DO NOT rename it.
MIMB5 months ago
Hi, this has been the most successful tutorial and set of instructions I have come across. I did run into a problem. one of my (2) LEDs blinked instead of just turning on. I ran the serial monitor and the program and noticed the signal was being sent more than once, like when a button bounces. I was wondering if you had any solutions or have run into the same problem. Thanks!
kltran016 months ago
After importing the IRemote library, I try to upload the sketch but i get this:
Decode_IR:28: error: 'IRrecv' does not name a type
Decode_IR:29: error: 'decode_results' does not name a type
Decode_IR.ino: In function 'void setup()':
Decode_IR:34: error: 'irrecv' was not declared in this scope
Decode_IR.ino: In function 'void loop()':
Decode_IR:39: error: 'irrecv' was not declared in this scope
Decode_IR:39: error: 'results' was not declared in this scope

i did a straight copy from the code you posted. Help?
Enjoying Electronics (author)  kltran016 months ago
That's what I got when I imported the library wrong. Check to make sure it its in the right folder and unzipped.
Tony326 months ago
Hey man, really liked your guide. Really easy to follow. Everything seem to work as it should, but when I double tab the button something breaks and the led starts flashing until I press the button again.

This is an example of what happened when I double tapped:
16753245
3810010651 <-- This number seems to screw things up and the led starts flashing. Any idea why?
Raphango Tony326 months ago
I'm having the same problem.... =T did you manage to find why is that ocurring?
Enjoying Electronics (author)  Raphango6 months ago
Are you in the USA? Every remote I've used doesn't do that. What you could do is make the second number turn the LED on (or off) as well as the first to eliminate the 'mystery' number.
I'm from Brazil. Actually, the remote I use (from a Global Village Telecom decoder) gives me 3 kinds of "first-number" with the same button. I guess that's because it's made to work with a whole bunch of brands, using the remote function "Aux", but not quite sure. One of the 3 numbers is more frequent than the others.

Example:
Situation 1:
456465
2135564651
2135564651
2135564651
2135564651

Situation 2:
54212
2135564651
2135564651
2135564651
2135564651

Situation 3:
42
2135564651
2135564651
2135564651
2135564651

I manage to get one of these 3 first-numbers more frequently than the others. Anyway, I made a switch-case using the 2 most frequent. Besides, if I use the remote in the "Decoder" function, it  only gives me 1 unique number for each button.
There's a third situation: There are buttons that aren't recognised at all. Maybe these work with a different IR range, other than the IR receiver is capable of capting.

Regards!
Enjoying Electronics (author)  Raphango6 months ago
I'm sorry I don't know what to tell you!
abibi17 months ago
Hello,
Thanks for this lovely toturial.
I have a question! Do you you any means that I can use to resend the signal using the IR transmitter?
Like if I had the power button to be damaged and there was a button that I never used, I want to use the arduino to send the IR code (PWM signal) on that button instead of the power button?
So basically all I want to know is how to send a similar signal via IR transmitter.
Raphango abibi16 months ago
Basically you'll have to use the Step 5: Recognizing IR Signals sketch to get all the codes that you need from your remote. For example, if you press the "mute" button, wich code appeared in the first line? You have to copy-paste that code in a Arduino controller sketch made to use a IR emitter. Just attach the IR led to any PWM port in Arduino and command the code using the IR library, got it? Regards!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!