Introduction: Control Your Arduino With a Remote

Wondering about how to control anything in your house with a simple remote control? It's pretty simple and cheap.

Step 1: Collect Stuff

Here is what you will need:

- Arduino (I use UNO)
- Solderless breadboard
- An infrared receiver
- Solderless wires
- Any kind of remote control

Step 2: Assemble the Receiver

Plug in the ir receiver to the beradboard and connect it to your Arduino.

Connect the right pin to the 5V of the Arduino, the center pin to GND, and the left pin to digital pin 11.

Step 3: The Code

I used the IRremote library for arduino.
You can download it here: IRremote

Close the Arduino IDE and unzip it into the arduino/libraries folder.

Start Arduino IDE and open the IRrecvDemo example sketch. Rewrite "HEX" to "DEC" as the image shows.
Upload the sketch to your board.

Step 4: Identify Remote Buttons

After uploading the program open the serial monitor and start pushing the buttons on your remote. If you have done everything well, you have to see the codes appearing.

Remember which button was pressed and take notes of the codes appearing.
For example:
Code 50088119 appeared and you pressed the On/Off button.
Code 50073839, Open/Close button etc...

Step 5: Control Stuff

Now you know which code the buttons give. To control something you have to write them into the program.

Here is the code you have to use. It's not the best solution I think but it's simple.

switch(results.value){
    case 50088119:
    // do something
    break;
    case 50073839:
    // do something else...
    break;
  }


Have fun ;)

Comments

author
simonlote98 (author)2016-05-01

this works without the computer connected ?

author

yup, just give it a power source thru the circular port.

author
the16thDoctor (author)2016-07-29

when i try to send the file to my arduino uno, it gives me this error message=

GetFileAttributesEx C:\Users\user\Downloads\IRremote\IRremote\examples\IRrecvDemo\IRrecvDemo.pde: The system cannot find the file specified.

Error compiling.

author

so what do i do?

author
oldsmarracin (author)2012-01-03

hi im sorry to bother you again but i was wondering if it is possible to block a certain value from being wrote to the serial

F7708F
F7708F
FFFFFFFF
FFFFFFFF
F7708F
F7708F
F7708F
F7708F
F7708F
FFFFFFFF
F748B7
FFFFFFFF
F748B7
F748B7
FFFFFFFF
FFFFFFFF
i want to block the F's

author
phorvath92 (author)oldsmarracin2012-01-04

It is not neccessary but if it disturbs you simply write an if statement to filter the F-s.

author
oldsmarracin (author)phorvath922012-01-04

i am a little new to arduino and i was using this with winlirc and the config was picking up the F's

author
techlv (author)oldsmarracin2016-02-06

Hi, i saw your post and I'd like to know if you managed to use WinLirc with Arduino? Does arduino make the IR decoding?

author
phorvath92 (author)oldsmarracin2012-01-05

I really don't know winlirc so sorry i don't have an idea :S

author
oldsmarracin (author)phorvath922012-01-05

its good i just need to block the FFFFFFFF string cause its picking it up as a remote code causing false readings. could you help with that part cause i have tried and failed

author
phorvath92 (author)oldsmarracin2012-01-05

Insert this:

if(results.value != 4294967295){
Serial.println(results.value, DEC);
}


4294967295 is the decimal value for FFFFFFFF

The F-s won't be shown ;) enjoy

Patrik

author
oldsmarracin (author)phorvath922012-01-05

Awesome now to figure the rest on my own lol
i didnt think bout inverting the line

author
NalithU (author)2015-11-08

I need to do a function only while I'm pressing a key of the remote, which means that the function stops when I take my hand off the button. How can I write the program to that? Plz help!!!

author
makeosaurus (author)2015-07-19

For some reason its trying to read from the RobotIRremote library. Should I delete or move the folder as i am using an UNO?

Here are my errors:

Arduino: 1.6.5 (Windows 7), Board: "Arduino Uno"

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:5:1: error: missing terminating " character

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

^

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

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

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp: In function 'void beginIRremote()':

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:10:2: error: 'irrecv' was not declared in this scope

irrecv.enableIRIn(); // Start the receiver

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp: In function 'bool IRrecived()':

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp:14:9: error: 'irrecv' was not declared in this scope

return irrecv.decode(&results);

^

C:\Program Files (x86)\Arduino\libraries\RobotIRremote\src\IRremoteTools.cpp: In function 'void resumeIRremote()':

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

irrecv.resume(); // resume receiver

^

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

author
makeosaurus (author)makeosaurus2015-07-19

I have deleted it and now it says there is no IRremote.h but there is!!

author
CooperG (author)2015-05-10

in expansion of macro 'HEX'
Error compiling.

and

expected unqualified-id before numeric constant
#define HEX 16

are causing me problems

author
tashvin (author)2013-12-23

hi please help me i already had all the codes for the IR
what if i want to light 2 leds with the IR? which connections should i make? am new please hlep :(

author
Vel0ceD3v (author)tashvin2015-04-19

I think you'll have to take two (or four) button's readings and apply them to two different LEDs.

Something like:

switch(results.value) {

case 1:

digitalWrite(13,HIGH);

break;

case 2:

digitalWrite(12,HIGH);

break;

case 3:

digitalWrite(13,LOW);

break;

case 4:

digitalWrite(12,LOW);

break;

}

author
universallvr (author)2015-03-21

IRrecvDemo.ino:9:22: fatal error: IRremote.h: No such file or directory
compilation terminated.

author
Vel0ceD3v (author)universallvr2015-04-19

Maybe the IR library isn't present on your PC. Try downloading it from here: http://arcfn.com/files/IRremote.zip (from the tutorial).

After downloading it, open your IDE, click on "Sketch", click on "Import Library...", click on "Add Library", and finally, browse for your library.

author
antley (author)2015-03-14

I did make it! But I have no image. Awesome job! you have the most simple way to solve this problem of Remote Controlling projects, and it only requires 1 pin!

author
OnePiece0039. (author)2015-01-02

im receiving this error?

C:\Program Files\Arduino\libraries\IRremote\IRremote.cpp:529: error: 'volatile struct irparams_t' has no member named 'rawlen'

author

how did you fix it?

author

already fixed it

author
Fission Chips (author)2014-08-30

Awesome! Thank you so much for this. You are very smart, and thank you for making this.

author
daniel.valverdesanchez (author)2014-08-29

Hi, I do not get anything in the serial monitor

author
bayarfaj2004 (author)2014-03-26

hi, thanks for you work

i switch, when i press 0 for example

switch(results.value){

case 16738455:

Serial.println(0);

irrecv.resume();

break;

i want it to print 0, but it loops forever, can you help me?

author
Kamokaki (author)2014-01-25

hi im trying to controll my arduino to move a servo.

Could you help me put in the code?

The controll gives off the infrared as i press left: FF22DD and right FFC23D. Please help me figure this out.

#include <Servo.h>
#include <IRremote.h>

unsigned long Value1 = 0xFF22DD; // where XXXXXXXX is on our your remote's values
unsigned long Value2 = 0xFFC23D; // where XXXXXXXX is another button on your remote

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

Servo servo1;

// the setup routine runs once when you press reset:
void setup() {

Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

// initialize the digital pin as an output.

servo1.attach(10); // attack servo to digital pin 10
}

// the loop routine runs over and over again forever:
void loop() {

if (irrecv.decode(&results)) {

Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}

if(results.value == Value1) {
servo1.write(160);
}
else if (results.value == Value2){
servo1.write(75);
}
}

author
vek11 (author)2013-06-10

Hello,
Whenever I plug my Arduino(with the IR receiver), it always turns off as soon as I plug it into the computer. Any advice?
(btw, my arduino works fine with anything else plugged into it.)

author
divemasterbill (author)2013-06-01

hello I get this ' IRrevc' does not name a type

author
jukees (author)2013-02-01

lidl remote FTW :D

author
triple5timer (author)2013-01-19

I hade a small white IR receiver with only 2 leads. Would this work?

author
dmiller37 (author)2012-12-03

Excellent tutorial, very helpful. I have a quick question, what is the best way to deal with on/off of the same button. Since each button has two keys, i thought I could use them to turn on and off. it works, but the timing is an issue since the other key comes quickly after the first. What is the best way to deal with it?

I tried: (but the button pressing has to be timed perfectly)
case key1:
digitalWrite(LED, HIGH);
delay(150);
break;

case key2:
digitalWrite(LED, LOW);
delay(150);
break;

Thanks!

author
3tuxedo (author)dmiller372012-12-26

I have done this before, but I did it with pins so I could check the current state of the pin and then decide whether or not to make it on or off. The way I did this in an Instructable of mine was

switch (results.value)
case (blahblah)
{
if (digitalRead(pin) == LOW)
{
digitalWrite(pin, HIGH);
}
else
{
digitalWrite(pin, LOW);
}
}
}

If you have multiple pins to check, just make it a function, call it for each case and pass in the pin number. Hope this helped.

author
lawand4 (author)2012-09-10

help when i upload it marks that IRrecv irrecv(RECV_PIN); and says does not name the type

author
LexanPanda (author)2011-12-13

Which IR receiver did you use?

author
phorvath92 (author)LexanPanda2011-12-14

I don't know the type because I soldered it out maybe from an old dvd player but I'm not sure. I think it works on 38kHz.

author
Hammock Boy (author)phorvath922012-09-09

Sparkfun has a great one for $1.95

author
the seaker (author)2012-05-10

Okay so i have a problem. I have already been able to get the ir codes from the remote that i wish to us but it will send something like this:
4035
4035
4035
4035
4035
2553
2553
2553
so the code is actually being send 5 times then another 3 are the end code. but sometimes if i press the button again the first number will either send 4 or 6 times. im not sure how to filter out the codes because if i just look for say 4035 it will repeat 4 to 6 times... um please if any one has an idea please help

author
Hammock Boy (author)the seaker2012-09-09

Try an unsigned long so that in your program it looks like

#include

unsigned long someValue = 0xXXXXXXXX; // where XXXXXXXX is on our your remote's values.

void loop(){

if(results.value == someValue) {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

}

author

make a method that catches the first time that you receive the signal. then tell it to ignore the rest until you recieve the 2553 signal... something like this:

boolean ignore=false;

void setup(){
...
}

void loop(){
int sig= ;
//set your input here, sending your input to the to sig.
if (!ignore&&sig==4035)doSomething();
else ignore==true;
}

}

author
go4th557 (author)2012-09-09

Mine shows zeroes no matter what button I push on any remote.

author
roachburn (author)2012-04-02

How would i use the case function to turn on an led. What I want to do is have the led turn High as long as I hold the button and go low when I release. The problem though is that there are 2 codes for every button on my remote. I press it once and it gives 458. then if I press it again it gives 10458. If I hold the button down It spams the one code and If i release then hold it down again it spams the other code.
thanks

author
pikmin205 (author)2012-03-08

I've been receiving error codes saying "error: 'EE008FC9' was not declared in this scope", how do i fix this? (BTW, EE008FC9 is a remote key code)

author
phorvath92 (author)pikmin2052012-03-08

put it in decimal :)

author
pikmin205 (author)phorvath922012-03-09

new error: `.' cannot appear in a constant-expression

author
pikmin205 (author)pikmin2052012-03-09

nvm fixed that now its expected ';' before break

author
Bot1398 (author)2012-02-21

Is that the original arduino UNO

author
phorvath92 (author)Bot13982012-02-21

No, probably it is not. But it is fully functional as well as the original.

author
Bot1398 (author)phorvath922012-02-22

I thought of it cause the power light in the original UNO is green and not blue

About This Instructable

38,970views

91favorites

License:

More by phorvath92:Control your Arduino with a remote
Add instructable to: