Introduction: Control Anything Remotely With Infrared Signals.

Who would have thought that just about every Arduino attachment can be controlled in some way with a TV remote? Now its time to find out how.

Step 1: Setup and Materials

The setup for this is quite basic. The real challenge is finding neat products for this and writing the code.

Materials.
1x Arduino
1x Servo available @ Hobbyking Sparkfun etc.
Jumper wires
1x Infrared receiver diode available @ Sparkfun Allelectronics Radioshack etc.
4x AA Battery and holder Ebay is the cheapest for the holder
1x TV remote

Anything that you want to control

See the attached sketchup for the setup. If you do not have sketchup you can download it here.
http://sketchup.google.com/intl/en/download/

Step 2: Values

The first thing to do is load the below code on to the arduino and open the serial monitor.
Next press a button on the remote aimed at the receiver to see the value printed. Ignore the first value that you see as it may by off.

#include <IRremote.h>

int RECV_PIN = A0; // Analog Pin 0
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 3: Code

Now that you have the values for each button on your remote you can control the servo. Below is also code that you can do without a servo and instead just control the LED on digital pin 13.

You will need to download the infrared library from http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html if you do not have it already.

You may recognize some of this code, and that is to keep everything simple. I am using code widely available on the internet largely from arduino.cc and http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html so that if anyone has questions they can look it up for more reference.

LED code



#include <IRremote.h>

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

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

// 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.
  pinMode(led, OUTPUT);   
}

// 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 == 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
}


}





Servo code



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

unsigned long Value2 = 0xXXXXXXXX; // where XXXXXXXX is on our your remote's values. We will call this Value 1
unsigned long Value1 = 0xXXXXXXXX; // 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(179);
}

if(results.value == Value1) {
servo1.write(1);
}

}

Step 4: Remotely Control Your Life

Everything should be working now. Load the servo code and watch it twist and turn to the values you loaded on the arduino. At this point you could control an entire robot with a TV remote or control appliances. The world is open to being controlled entirely by you with infrared signals.

Please let me know if you have any more ideas or what you have done with infrared signals. Enjoy!

Comments

author
AberieG made it! (author)2015-11-11

My CODE wont work, can somebody help... It says

Arduino: 1.6.4 (Windows 8.1), Board: "Arduino Uno"

sketch_nov11a:5: error: 'IRrecv' does not name a type
sketch_nov11a:6: error: 'decode_results' does not name a type
sketch_nov11a.ino: In function 'void setup()':
sketch_nov11a:8: error: redefinition of 'void setup()'
sketch_nov11a:1: error: 'void setup()' previously defined here
sketch_nov11a:11: error: 'irrecv' was not declared in this scope
sketch_nov11a.ino: In function 'void loop()':
sketch_nov11a:15: error: 'irrecv' was not declared in this scope
sketch_nov11a:15: error: 'results' was not declared in this scope
sketch_nov11a.ino: In function 'void loop()':
sketch_nov11a:21: error: redefinition of 'void loop()'
sketch_nov11a:14: error: 'void loop()' previously defined here
'IRrecv' does not name a type

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

please somebody

author
HishoW made it! (author)2015-09-28

but haded a lot of problems with the variable and hexadecimal values

author
Computothought made it! (author)2015-05-13

Cool.

author
tnowroz made it! (author)2015-05-11

Good Tutorial Man! (Y)

I made something alike using an old TV remote to control several LED lights completely. Playing with Remotes and Signals is really AWESOME! \\m//

author
Daviswatts1234 made it! (author)2015-04-24

HELP I UPLOAD THE SKETCH TO GET SERIAL VALUES AND I OPEN SERIAL MONITOR AND PRESS BUTTONS BUT IT DONT WORK!!!!

author
Daviswatts1234 made it! (author)2015-04-03

Hello!

I have a great idea to use this for a school project

For the project we have to make a small wooden truck

i am making a rocket transporter

I had the idea of making the rocket move upand down at an angle

Ill try and add images when im done

Thanks for the guide though!!!

author
claw5 made it! (author)2014-09-02

I am trying to control a owi robotic arm via a IR remote. I have got the arm to move but as soon as my remote starts sending the FFFFFFFF repeat signal my sketch doesn't recognise it and the motor stops. What is the best way to interpret this signal into my sketch?

author
harshjk made it! (author)2013-06-22

hey, thanks for your tutorial .
But i m facing one major problem i.e.
when i fetch the IR code with help of SM0038 in fluorescent lamp light it fetch wrong code. without light it works correctly .
Please help me .......

author
go4th557 made it! (author)2012-09-09

I finally figured it out but it is only picking up zeroes no matter what button I push on a multitude of remotes.

author
Hammock Boy made it! (author)Hammock Boy2012-09-09

It sounds like you are using it as a button. What pin do you have it attached to? Perhaps try of the PWM pins such as 10 or 11. When you downloaded the library and dropped it into the Arduino folder on your computer there should be a file inside called IRremoteInt.h Inside of that is where you change Wprogram.h to Arduino.h

Can you send me a screen shot of your program with any of the error messages? Sorry this is causing you so much trouble.

author
shail363 made it! (author)shail3632013-04-29

Dear Hammock
I have small issue with controlling servo with remote and will really appreaciate for your help.
I have implemented IRremote to control hobby king Digital Servo motor.Problem I am facing is that there is lot of Servo jittering. It makes sufficient noise.Did you face this problem? I am trying to maintain position of servo to 90 degree in the loop.(Without Iremote is works fine) Can you please let me know whether do you have any solution to elimiate Servo motor jittering?

Thank you in advance.

author
invisiblelight386 made it! (author)2012-04-28

I downloaded the library and put it into the Arduino library folder. I copied your code into a sketch and when i tried to upload it i get a < 'IRrecv' does not name a type > error when compiling. I'm not sure what this means ( still pretty new to the Arduino / C++ platform.

author
Hammock Boy made it! (author)Hammock Boy2012-04-28

I had this exact same problem and spent way to much time trying to fix it. Fortunately there is any easy fix. Open up the Infrared library and change

#include
to
#include
in IRRemoteInt.h.

Please let me know if that doesn't work.

author
Hammock Boy made it! (author)Hammock Boy2012-04-28

For some reason not all of the text posted. The attached photo shows what you need to change in the Infrared library.

Picture 2.png
author
go4th557 made it! (author)go4th5572012-09-09

I did this but when i try to save it, I am given a message that says access denied. I am the Admin of my computer so I have no idea why.

author
Hammock Boy made it! (author)Hammock Boy2012-09-09

You could create a new admin account for all of your arduino projects?

author
Hammock Boy made it! (author)Hammock Boy2012-04-28

I had this exact same problem and spent way to much time trying to fix it. Fortunately there is any easy fix. Open up the Infrared library and change (see picture).

Please let me know if that doesn't work.

Picture 2.png
author
invisiblelight386 made it! (author)invisiblelight3862012-04-29

opened the IRremoteInt.h in text edit and changed the code but i am still receiving the same error message when compiling. any other thoughts?

author
invisiblelight386 made it! (author)invisiblelight3862012-04-29

i deleted the library and re-downloaded it and then change the code again and now it seems to be working fine. thanks. this is going to be the main controls on all my robots for a while.

author
go4th557 made it! (author)2012-09-09

I can not get this program to work no matter how hard i try. I've downloaded the library and no matter what I do, it gives me multiple errors.

author
Hammock Boy made it! (author)Hammock Boy2012-09-09

Have you gone into the library and changed to . I know this gave me an hour of frustration before I changed it.

author
Hammock Boy made it! (author)Hammock Boy2012-09-09

What I was typing disappeared. Anyway if you go into the library at the top you should see WProgram.h in-between greater than, less than signs. If you have not already change that to Arduino.h

author
go4th557 made it! (author)go4th5572012-09-09

Do I find this in the library going through my program files or do I change it in the program itself? I had a little difficulty understanding what you meant.

author
knexpert1700 made it! (author)2012-09-08

Do I have to use a ground terminal on the IR reciever? I have two IR recievers and they only have positive and negative.

author
Hammock Boy made it! (author)Hammock Boy2012-09-08

Can you send me the link to the data sheet? It sounds like each ground will plug into an analog pin and then you will have to use the analogRead() function.

author
invisiblelight386 made it! (author)2012-05-05

One more question. i have been trying to use this code along with code for the Arduino motor shield. the two codes by their self work fine but when put together the motor shield does not work. could there be any conflicting pins or variables that might be interfering? 

author
Hammock Boy made it! (author)Hammock Boy2012-05-05

There is a list of pins that the motor shield uses at http://arduino.cc/en/Main/ArduinoMotorShieldR3

one of them is A0 it also uses A1 so try A2 and see what happens.

author
Hammock Boy made it! (author)Hammock Boy2012-05-05

After reading the motor shield page again it might be better to try using pin A4.

author
coolblue made it! (author)2012-04-26

Hello. This project is a great ideea, tough it sould de more specific since, i guess, you entered for te arduino challenge. Nvermind, i woud like to ask if you could control more than one servo with this. Thanks.

author
Hammock Boy made it! (author)Hammock Boy2012-04-26

You can control up to 12 servos on an arduino (6 on PWM and 6 on analog pins using the servo library). So if you had a remote control with 24 buttons then each servo could have two different values it would move it individually. For example if you pressed the power button on the remote then servo 1 could move to 160 degrees. Then you could press the #2 button and that same servo would move to 50 degrees. All the while the rest of the servos would remain unchanged. To do this in the code you will need 24 unsigned longs (1 for each of the 24 buttons on the remote control. Please Let me know if this is not clear or if you have any questions.

author
Kdemon made it! (author)2012-04-25

I had this idea too, but I wanted to wire it into my light switches should I could just point and turn off the light when watching a movie.

author
Hammock Boy made it! (author)Hammock Boy2012-04-26

You could definitely do that as long as the path to the infrared receiver is not blocked by any solid objects. Great idea.

About This Instructable

38,966views

181favorites

License:

Bio: From solder to zip ties, lead acid batteries and LEDs, and especially Legos, putting things together has always fascinated me. The more challenging the better ... More »
More by Hammock Boy:Chipper Board - ATtiny Programming ShieldBoxhead recreated with Python with TkinterInterface Python and Arduino with pySerial
Add instructable to: