In this project you’ll use an infrared (IR) receiver and an Arduino to control 3 LEDs with a remote control. This is useful to re-use old remote controls or give some functionally to some of your remote’s buttons.
Updated 17 December 2024
This project is divided into two parts:
- You’ll decode the IR signals transmitted by your remote control
- You’ll use that info to perform a task with your Arduino (control 3 LEDs)
Parts required
To follow this project you need the following parts:
- Arduino UNO – read Best Arduino Starter Kits
- 1x Breadboard
- 1x Remote control
- 1x IR receiver ( I’ll be using TSOP4838)
- 3x LED’s
- 3x 220 Ohm resistors
- Jumper wires
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Introducing the Infrared (IR) Receiver
The infrared receiver is the component shown in the figure below. This is the TSOP4838.
Infrared receiver pins:
- First pin: Vout
- Second pin: GND
- Third pin: Vcc
When you press your remote control, it sends infrared modulated signals. These signals contain information that your receiver collects.
Each button sends specific information. So, we can assign that information to a specific button.
Decode the IR signals
In this part of the project you need to decode the IR signals associated with each button.
Schematics
Connect the IR receiver accordingly to the schematics below.
Code
To control the IR receiver, you need to install the IRremote Library in the Arduino IDE.
Installing the IRremote library
- Go to Sketch > Include Library > Manage Libraries.
- The Library Manager should open at the left sidebar of the IDE. Search for IRremote.
- Install the library by shirriff. We’re using version 4.4.1.
Copy the following code to your Arduino IDE, and upload it to your Arduino board. Make sure that you have the right board and COM port selected.
#include <IRremote.h>
const int RECV_PIN = 11;
void setup() {
Serial.begin(9600);
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Initialize the receiver
}
void loop() {
if (IrReceiver.decode()) { // Check if data is received
// Filter out unknown protocols
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
IrReceiver.resume(); // Resume receiving for the next signal
return; // Skip this loop iteration
}
// Print only valid data
IrReceiver.printIRResultShort(&Serial); // Print complete received data in one line
IrReceiver.resume(); // Resume receiving for the next signal
}
delay(100);
}
Open the serial monitor at a baud rate of 9600.
In this project you want to control 3 LEDs. Choose 6 keys on the remote control for the following tasks:
- LED1 – ON
- LED1 – OFF
- LED2 – ON
- LED2 – OFF
- LED3 – ON
- LED3 – OFF
Press, for example, the button number 1 of your remote control. You should get some information about that key in the Serial Monitor. Save the “command” value for that key.
Do the same for the other buttons.
Write down the code associated with each button, because you’ll need that information later.
Building the final circuit
In this part, you’ll build the circuit with three LEDs that will be controlled using your remote.
Schematics
Assemble all the parts by following the schematics below.
Code
Now, grab the command values you captured in the previous step for each button. You’ll need to insert them on the following code.
/*
* Modified by Rui Santos, http://randomnerdtutorialscom
* based on IRremote Library - Ken Shirriff
*/
#include <IRremote.h>
const int RECV_PIN = 11;
const int bluePin = 10;
const int greenPin = 9;
const int yellowPin = 8;
void setup() {
Serial.begin(9600); // Start serial communication
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
pinMode(bluePin, OUTPUT); // Set the pins as output
pinMode(greenPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
}
void loop() {
// Decode the infrared input
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
IrReceiver.resume(); // Resume receiving for the next signal
return; // Skip this loop iteration
}
// Print the received command for debugging
IrReceiver.printIRResultShort(&Serial);
switch (IrReceiver.decodedIRData.command) {
case 0x01: // Command to turn ON the blue LED
digitalWrite(bluePin, HIGH);
Serial.println("Blue LED ON");
break;
case 0x02: // Command to turn ON the green LED
digitalWrite(greenPin, HIGH);
Serial.println("Green LED OFF");
break;
case 0x03: // Command to turn ON the yellow LED
digitalWrite(yellowPin, HIGH);
Serial.println("Yellow LED ON");
break;
case 0x04: // Command to turn ON the yellow LED
digitalWrite(bluePin, LOW);
Serial.println("Blue LED OFF");
break;
case 0x05: // Command to turn ON the yellow LED
digitalWrite(greenPin, LOW);
Serial.println("Green LED OFF");
break;
case 0x06: // Command to turn ON the yellow LED
digitalWrite(yellowPin, LOW);
Serial.println("Yellow LED OFF");
break;
default: // Unknown command
Serial.println("Unknown Command");
break;
}
IrReceiver.resume(); // Receive the next value
}
delay(10);
}
After adding the commands for each key in the previous code, you can upload it to your Arduino IDE.
Demonstration
In the end, you can control each LED individually using the buttons of your remote control.
Watch the video demonstration
Wrapping Up
This is a great project to learn about the IR receiver. There are endless possibilities for what you can do with it.
For example, you can replace those LEDs with a relay to control your house appliances. Associate a button to turn off or turn on all the LEDs at the same time, etc.
This can be particularly useful because some remotes have a bunch of buttons that you never use. So, why not use them to do something useful?
This is an excerpt from our course: Arduino Step-by-step projects. If you like Arduino and you want to build more projects, we recommend enrolling in the Arduino Step-by-step projects course.
dá me um erro a fazer o uploud para o arduino
instalaste correctamente a IR library?
From Ken Shirriff
Unfortunately the Robot library copied some of the IRRemote code in a way that breaks the IRRemote library. I believe the solution is to remove the files libraries\RobotIRremote\IRremoteTools.cpp and libraries\RobotIRremote\IRremoteTools.h
Hi Jan,
Thank you for adding that information, I’ve never experienced any problem with that file though.
secalhar nao
como é que se faz corretamente? Podes me dar os passos sff
É bastante simples vais a este link
https://github.com/shirriff/Arduino-IRremote
fazes download (segue a read me file que está em baixo)
se tiveres algum problema dps avisa!
Rui
Na compilaçao da o seguinte erro
sketch_apr13a.ino: In function ‘void loop()’:
sketch_apr13a:112: error: expected `;’ before ‘}’ token
Nao consigo resolver, pode me ajudar
quer dizer que falta um “;” antes do }. isto quer dizer que ou sem querer apagaste um “;”
ou nao copiaste o código todo, tenta ver se tem os ponto e virgulas todos e todos os {}
Does it matter what kind of IR receiver I use for this project? Or should any IR receiver be okay?
In theory i think any receiver should work. But some people is having some trouble when they try to make this project with a 2 Legs IR receiver,
So if you want to make this project and I recommend you to use any 3 legs IR receiver and you should be fine
Estou com alguns problemas no unitypro. Achas que o “Help” é uma boa ferramenta?
ahah Sem dúvida que resolve o problema !
ahah Sem dúvida que é a melhor forma de resolver o problema !
cant get this to work with the arduino motor shield, please help.
#include
int IR_Recv = A8; //IR Receiver Pin 3
int pinI1=8;//define I1 interface
int speedpinA=9;//enable motor A
int speedpinB=10;//enable motor B
int pinI2=11;//define I2 interface
int pinI3=12;//define I3 interface
int pinI4=13;//define I4 interface
int spead =125;//define the spead of motor default is 125
IRrecv irrecv(IR_Recv);
decode_results results;
void setup() { //Set’s up the code to be ran from a fresh start this code only runs once
// initialize serial communication output
Serial.begin(9600);// comment this out when not debugging
irrecv.enableIRIn(); // Starts the receiver
//set pinmodes for motor controllers first run
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
}
void loop(){
//decodes the infrared input
if (irrecv.decode(&results)){
long int decCode = results.value;
Serial.println(decCode);
//switch case to use the selected remote control button
switch (results.value){
case 4064352766: //when you press the Forward button
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
Serial.println(“forward”);
break;
case 3028878891: //when you press the Reverse button
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
Serial.println(“backward”);
break;
case 3308754100: //when you press the left button
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
Serial.println(“Spin Left”);
break;
case 197779206: //when you press the right button
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
Serial.println(“Spin Right”);
break;
case 1974032039: //when you press the select button
digitalWrite(speedpinA,LOW);// Unenble the pin, to stop the motor. this should be done to avid damaging the motor.
digitalWrite(speedpinB,LOW);
Serial.println(“Stopping”);
break;
default:
Serial.println(“waiting”);
}
irrecv.resume(); // Receives the next value from the button you press
}
}
when using the serial monitor and watching the leds on the motor shield it appears everything works execpt the analog.write commands as there is no movement of the motors.
Board is the arduino MEGA 2560 and the shield is the seed studio motor shield V1.2
the code seems correct for me… and if it’s working with the arduino serial monitor…
Does your IR receiver works with a simple project?
test a simple Control one LED or something… and see if its working.
I hope this helps.
hy
i wanted to try this a few days ago and found your ir per accident cause of an other article ^^
hm i wrote the programmer of the library also but not sure WHEN i get an answer so maybe you also have an idea
when i include it under c/…/arduino/…/libraries and just want to rund an example from the library i get this errors:
In file included from sketch_dec09a.ino:13:
C:\Program Files\Arduino\libraries\IRremote/IRremoteInt.h:87: error: ‘uint8_t’ does not name a type
C:\Program Files\Arduino\libraries\IRremote/IRremoteInt.h:88: error: ‘uint8_t’ does not name a type
C:\Program Files\Arduino\libraries\IRremote/IRremoteInt.h:89: error: ‘uint8_t’ does not name a type
C:\Program Files\Arduino\libraries\IRremote/IRremoteInt.h:92: error: ‘uint8_t’ does not name a type
sketch_dec09a.ino: In member function ‘void IRsendDummy::useDummyBuf()’:
sketch_dec09a:87: error: ‘volatile struct irparams_t’ has no member named ‘rcvstate’
sketch_dec09a:88: error: ‘volatile struct irparams_t’ has no member named ‘rawlen’
sketch_dec09a:93: error: ‘volatile struct irparams_t’ has no member named ‘rawlen’
sketch_dec09a:98: error: ‘volatile struct irparams_t’ has no member named ‘rawlen’
sketch_dec09a:104: error: ‘volatile struct irparams_t’ has no member named ‘rawlen’
sketch_dec09a:109: error: ‘volatile struct irparams_t’ has no member named ‘rawlen’
sketch_dec09a:113: error: ‘volatile struct irparams_t’ has no member named ‘rawlen’
sketch_dec09a:114: error: ‘volatile struct irparams_t’ has no member named ‘rawlen’
well im not a too good programmer to get into the library itself and find out whats wrong
do you ahve any experince or knowledge which can solve my trouble
i use atm an arduino 1.04 software
thx
thanks for trying my project Vance.
That library works fine with Arduino IDE 1.04.
What you need to do is to install the library properly… you probably skipped one step or moved the folder to the wrong place.
that’s totally normal!
Please download that entire folder:
https://github.com/shirriff/Arduino-IRremote
and install it just like the Readme tells you.
Let me know if this worked for you,
Rui
hm under 1.04 i didnt get it running only under 1.5.5 now
but sadly NOT like in the readme described
as you might noticed im no native ^^ – so if i understood that correct to only install it under c\..\arduino\libraries
that didnt work – i also had to install it under userxyz\documents\arduino\libraries\….
somehow weird but ok it works now
maybe also for you a worth a test – it gets conflicted with the NewPing library for ultrasonic moduls
give that an try 😉
maybe also just an error i receive ^^
all in all – still an interresting topic to “work” at ^^
thx for replies
I noticed that you knew what you were talking about! 🙂
I wasn’t trying to treat you as a noob, I was just explaining.
The library works fine for me, with 1.04 and 1.5 IDE versions and it doesn’t conflict either with the NewPing library.
Sometimes there are errors that we can’t explain, that might be one of them xD
But Its working now?
(except the conflict between the NewPing library?)
yep it works now but still only with 1.5.5 after a few trials (only in doc/lib, only in c/lib, both of them, … ) but after a few tries it works now ^^
but it doestn work fine
only if i hit the button estimated 0,3-0,6 sec (just very fast) it reads somehow correct
if i push the button to long or keep it pressed
(im talkon about a button on the remote)
then i only get “FFFFFFFF” values – overflow ?
Thats how it works.
when you press the button it will read one value correct.
and the other values after that will be “trash”.
that’s how the library was developed and it’s how it works…
Your experience may vary if you use a different remote/IR sensor.
Some sensors will work better then others.
ah ok – well – or not well – cause as i said i tried it like in the readme and it didnt work – only when i copied the library in every library folder available :D:D
now i try it again with a few other methodes out there
and with the library and 2 other sensor one from an saint smart kit … which doesnt tell what sensor the gave me and a tsop2838 for whom there are nearly good datasheets out there ^^
ahhhh ok … good to know that the overflow or whatever is normal – thx !
Yeah that overflow or random numbers happen to me…
I don’t know exactly the answer for that.
Read the Sensor datasheet it will definitely help.
At Sainsmart you probably find the sensor that came with the kit.
Usually they have everything detailed on their website.
If you want more project examples we will find on the web using this library too.
just search on google or instructables.com.
Good luck,
Rui Santos
hm good and simple tip.. as i ordered it from an retail via amazon (eu)
i thought that clumsy documentation is “normal”
if you want to see a “free” and even more funny english arduino text i can recomend this little projects where i ordered the set
and here the link to the arduino fiels + “documentation”
the realy realy tried it and even go a bit in transmission protocoll details and pwm explanation ^^
enjoy:
😉
Thanks for sharing Vance.
I’ll definitely take a look at it!
All the best,
Rui
Viva Rui Santos!
Estou a começar a aprender a utilizar o arduino, e o vosso site parece-me excelente! Gosto muito da maneira como disponibiliza os seus projectos e o site está muito apelativo!
Estou a pensar em controlar um motor DC com um remote control. No vosso vídeo você diz que posso aplicar tbm a motores, certo?
Outra pergunta, qualquer comando com IR funciona?
Olá José,
Muito obrigado pelo feedback.
Peço desculpa pela demora a responder, mas tenho tido imenso trabalho.
Se seguir o meu tutorial, vai começar a perceber melhor como funciona o controlo remoto.
O primeiro objectivo é ler os valores que o controlo remoto envia, e que o receptor lê.
Depois de cosneguir codificar esses valores, basta utilizar o meu codigo de arduino e alterar as condiçoes, com os valores que o seu controlo remoto transmite.
Por fim, alterar as condições if, com o codigo que vai controlar o DC motor.
Espero ter ajudado,
Abraço
these errors keep happening can you help me
IRrecvDemo:13: error: expected unqualified-id before ‘=’ token
IRrecvDemo:15: error: ‘decode_results’ does not name a type
IRrecvDemo.pde: In function ‘void setup()’:
IRrecvDemo:20: error: request for member ‘enableIRIn’ in ‘irrecv’, which is of non-class type ‘int’
IRrecvDemo.pde: In function ‘void loop()’:
IRrecvDemo:24: error: request for member ‘decode’ in ‘irrecv’, which is of non-class type ‘int’
IRrecvDemo:24: error: ‘results’ was not declared in this scope
IRrecvDemo:26: error: request for member ‘resume’ in ‘irrecv’, which is of non-class type ‘int’
You need to install the IR library…
That is provided in the top of this post.
Go to github and follow the read me file.
Thanks for trying my project lester!
helo..i have little problem & confuse 😀
(i’m sory with my english 🙂 )
i try your code and add Password.h library to cntrol leds, when password true, green led HIGH & pasword false, red led HIGH. Green ledpin = 13, red ledpin = 12.
Now the problem is when green led HIGH & red led high too, red led did not light like green, the light is very small.
Thanks…sory with my english 😀
Hi Eddy,
Thanks for trying my project.
That’s a problem with your LED’s…
try with another LED … are you using an equal resistor for both LED’s?
Hi Rui..
sory late reply..
yes, i’m using 220ohm resistor for both LED’s. i try different value of resistor for each led but still could not. I’ve tried another led but still not work,,only pin13 normal. 😀
oh ya, do you have an example code to input password Validation using keypad with 3 attempts??
sample: If it is entered password incorrectly serial monitor displaying “password error”
If it is a wrong password user received another 3attempts to enter the correct one. If he couldn’t enter password correctly by these attempts he have to wait 3 minutes time more to re logged in to the system.
Thanks Rui 🙂
hye i wanna ask you….what if I want to use voice to control the LED instead of remote..what should I do?…really need help here..Thank you
Hi eddie,
Thanks for asking there’s a good project for that:
youtube.com/watch?v=0Jr8dKyXrzA
Please check that project it will help you do exactly that.
Can I Use Any Remote For That And Any three pin ir Reciever
Yeah it should work just fine with most remote controls
thnx
you’re welcome!
i can not run a project IR remote control with arduino uno coz when compile it saw like this
c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: IRrecvDemo.cpp.elf section .text will not fit in region text
c:/program files/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: region text overflowed by 50 bytes
pls help me
Hi Kong,
You didn’t install the Arduino library properly.
Make sure you unzip the library provided and move it to the Arduino IDE libraries folder.
It should work fine after you do that!
Thanks for trying my projects
i not sure properly or not about unzip the library
//
in the Arduino IDE libraries folder
have ir library ready but still erro
how i can sent picture to you about install arduino library.
the decimal iget from the conversion is too large for a long type please help
Can you show me what you’re trying to convert?
Getting a error that irrecv does not name a type
Hi Rui….
I wanna do this project and I would like to do in PCB….still I’ve not get the exact circuit…Can you please send me…
You can download the schematics right here on this page: https://randomnerdtutorials.com/wp-content/uploads/2013/02/leds-ir.png
hi. Rui santos.
I would like to take remote code air conditioner merk LG , but when sent over IR send the air conditioner was not working ..
and when tried on TV merk SHARP, IR send its success ..
You should be able to replicate the signal from any remote using the library I show in this project.
Is your IR emitter broken? Can you try with a different one?
Esto es realmente genial, eres un blogger muy profesional. Me he unido a tu RSS y deseo encontrar más cosas en este gran blog. Además, !he compartido tu sitio en mis redes sociales!
Saludos
For the info let me add instead of using a hexadecimal to Decimal converter you can simply change Serial.printIn(results.value,DEC);
Thanks for that suggestion.
That’s definitely an easier way to do the same thing.
Thank you
Regards,
Sara
I followed this tutorial, there were compile errors referred to the file IRremote.cpp. I did the corrections and there were no errors. I checked with NEC, panasonic and another (Sky). How can we know the format of the IR code from this sketch. I added another Serial.print to output the decimal value.
I followed exactly what you did and controlled the LED using my arduino board first time. it is so simple. Thank you so much. Keep helping us.
Great!
Do you have any tutorials like this for the esp8266?
Thanks
Bob
Sara,
All I get when running the sketch in this tutorial is:
The function decode(&results)) is deprecated and may not work as expected! Just use decode() – without any parameter.
The function decode(&results)) is deprecated and may not work as expected! Just use decode() – without any parameter.
The function decode(&results)) is deprecated and may not work as expected! Just use decode() – without any parameter.
The function decode(&results)) is deprecated and may not work as expected! Just use decode() – without any parameter.
checked wiring, OK.
used decode(): monitor completely blank.
Please help.
Alan
Hi Sara,
I followed your instructions to download the ‘Ir Remote’ library.
When I got the result shown above I did some research. Went onto Arduino forum & found a solution.
Then I modified your code as shown below. The decoded values for numbers 1 – 6 are 0 -5.
This I used in the switch statement.
The code now works perfectly.
But why:
(1) Did the original code not work on my system.
(2) Why do I now get single digit codes?
Keep up your great work.
Stay safe
Alan
/*
* Modified by Rui Santos, http://randomnerdtutorialscom
* based on IRremote Library – Ken Shirriff
*/
#include <IRremote.h>
const byte IR_RECEIVE_PIN = 11;
int IrReceiverValue;
int bluePin = 10;
int greenPin = 9;
int yellowPin = 8;
void setup(){
Serial.begin(9600); //starts serial communication
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
pinMode(bluePin, OUTPUT); // sets the digital pin as output
pinMode(greenPin, OUTPUT); // sets the digital pin as output
pinMode(yellowPin, OUTPUT); // sets the digital pin as output
}
void loop(){
//decodes the infrared input
if (IrReceiver.decode()){
IrReceiverValue = IrReceiver.decodedIRData.command, HEX;
//switch case to use the selected remote control button
switch (IrReceiverValue){
case 0: //when you press the 1 button
digitalWrite(bluePin, HIGH);
break;
case 1: //when you press the 4 button
digitalWrite(bluePin, LOW);
break;
case 2: //when you press the 2 button
digitalWrite(greenPin, HIGH);
break;
case 3: //when you press the 5 button
digitalWrite(greenPin, LOW);
break;
case 4: //when you press the 3 button
digitalWrite(yellowPin, HIGH);
break;
case 5: //when you press the 6 button
digitalWrite(yellowPin, LOW);
break;
}
IrReceiver.resume(); // Receives the next value from the button you press
}
delay(10);
}
Hello can you give me the c programming code for this IR remote controlled LED system
Hi.
All the code is posted in the tutorial.
Regards,
Sara
My IR reciever blew off when i gave 5v from the board.Plz change the value to 3.3v if not someone less will also face the trouble too.