Taking advantage of the previous post, we are going to add an IR receiver to the circuit so that we can vary the color and brightness of the led with a remote control of Dealextreme, which is perfect for the project. The controller in question is the SKU: 47019, a very cheap remote control that comes with battery included:

RGB IR Remote control

To get the Arduino detected it, will use a TSOP 1738 or similar type infrared receiver (in my case I have a 1736 and works equally although command uses a 38KHz carrier).

This is the scheme:
RGB led controlled by IR Remote with Arduino

And this the assembly :
RGB led controlled by IR Remote with Arduino

Now we need the IRRemote library, that allows to read multitude of remote control codes. In particular it works perfectly with our remote control (which uses the NEC Protocol).
We must download the library and install it in our Arduino environment.

The code for example would be as follows (to copy the code, double click on it):

*  Control remoto de LED RGB 
*  Ejemplo de como hacer variar el color y el brillo con un led RGB  
*  con un mando a distancia.
*  Se utiliza un receptor de infrarrojos del tipo TSOP1738 
*  Autor: Jose Daniel Herrera
*  Fecha: 28/08/2012
*  http://arduino-guay.blogspot.com.es


int RECV_PIN = 8;
int R_PIN = 9;
int G_PIN = 6;
int B_PIN = 10;

#define ON                0XFFE01F
#define OFF               0xFF609F
#define BRIGHTNESS_UP     0xFFA05F
#define FLASH             0xFFF00F
#define STROBE            0xFFE817
#define FADE              0xFFD827
#define SMOOTH            0xFFC837

#define RED               0xFF906F
#define GREEN             0XFF10EF
#define BLUE              0xFF50AF
#define WHITE             0xFFD02F

#define ORANGE            0xFFB04F
#define YELLOW_DARK       0xFFA857
#define YELLOW_MEDIUM     0xFF9867
#define YELLOW_LIGHT      0xFF8877

#define GREEN_LIGHT       0XFF30CF
#define GREEN_BLUE1       0XFF28D7
#define GREEN_BLUE2       0XFF18E7
#define GREEN_BLUE3       0XFF08F7

#define BLUE_RED          0XFF708F
#define PURPLE_DARK       0XFF6897
#define PURPLE_LIGHT      0XFF58A7
#define PINK              0XFF48B7

#define INCREMENTO 10

unsigned long rgb = 0;
byte r,g,b;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
  irrecv.enableIRIn(); // Inicializamos el receptor
  pinMode(R_PIN, OUTPUT);   
  pinMode(G_PIN, OUTPUT);   
  pinMode(B_PIN, OUTPUT);   

void variar (byte* color, char valor) {
    if (valor > 0) {
        if ( *color + valor <= 255) {
            *color += valor;
        } else {
            *color = 255;
    } else { 
        if (*color + valor >= 0) {
            *color += valor;
        } else {
            *color = 0;

void RGB(unsigned long valor) {
   r = valor >> 16; 
   g = (valor >> 8) & 0xFF; 
   b = valor & 0xFF; 

void loop() {
  if (irrecv.decode(&results)) {
    if ( results.value != 0xFFFFFFFF) {
      switch (results.value) {
           case BRIGHTNESS_UP : 
               variar (&r, INCREMENTO);
               variar (&g, INCREMENTO);
               variar (&b, INCREMENTO);
           case BRIGHTNESS_DOWN : 
               variar (&r, -INCREMENTO);
               variar (&g, -INCREMENTO);
               variar (&b, -INCREMENTO);
           case OFF :
               r = g = b = 0;
           case RED           : RGB(0x00FF0000); break;
           case GREEN         : RGB(0x0000FF00); break;
           case BLUE          : RGB(0x000000FF); break;
           case WHITE         : RGB(0x00FFFFFF); break;
           case ORANGE        : RGB(0x00FF7F00); break;
           case YELLOW_DARK   : RGB(0x00FFAA00); break;
           case YELLOW_MEDIUM : RGB(0x00FFD400); break;
           case YELLOW_LIGHT  : RGB(0x00FFFF00); break;
           case GREEN_LIGHT   : RGB(0x0000FFAA); break;
           case GREEN_BLUE1   : RGB(0x0000FFFF); break;
           case GREEN_BLUE2   : RGB(0x0000AAFF); break;
           case GREEN_BLUE3   : RGB(0x000055FF); break;
           case BLUE_RED      : RGB(0x00000080); break;
           case PURPLE_DARK   : RGB(0x003F0080); break;
           case PURPLE_LIGHT  : RGB(0x007A00BF); break;
           case PINK          : RGB(0x00FF00FF); break;
      Serial.println(results.value, HEX);
      Serial.println(g, DEC);
      Serial.println(b, DEC);
    irrecv.resume(); // Receive the next value
Caution!: The IRremote library internally use the TIMER2 of Arduino. This causes outputs 11 and 3 do not work as PWM ( therefore I changed the Green led to output 6). On the other hand there is a newer version of the library IRremote, which recognizes many protocols of IR codes, but apparently after several pulses, the obtained codes seem random...??.Can serve you to support other remote controls or for other projects.
For obtain the constants I used the example that comes with the 'IRrecvDemo' library, which allows display on the console the codes sent by every button on the remote. Same is true if you want to use another different remote control.

A video demo:

If you liked it, remember to share it on your favorite social network. Thanks


November 19, 2012 at 7:10 AM

Both the receiver and the library seem to have vanished. The library's last known location on that service doesn't exist. Note: Not the one that you reference, the supposed later one. The receiver is considered obsolete by Mouser. Others exist from that vendor but their website is currently off-line.

November 19, 2012 at 9:48 AM

I've changed the link to the new library.
The receiver may be any one that works with 38 Khz (I actually use one of 36 kHz), such as TSOP 31238
Thank you.

December 7, 2012 at 4:37 PM

What purpose does the ULN2002A IC? What if I wanted to use a universal remote and the Sony protocol? Would this sketch still be valid? What arduino library are you currently using for this project? Thanks!

December 7, 2012 at 5:12 PM

The ULN2003A is a driver for manage the power RGB led, in the example is a 5W led.
The irremote library support this prortocols :NEC, SONY, RC5, RC6, DISH, SHARP, PANASONIC, JVC, SANYO and MITSUBISHI.
The IR receiver normally are 36 to 38KHz, depend of remote control, but are not critical.

December 27, 2012 at 4:57 PM

Hi! I was looking exactly for a sketch like
yours but when I try to compile on 1.0.3 or 0022
I obtain several error messages. The IRremote
librairy is instaled correctly, I can run
exemples of the librairy flawlessly.
Is something I missed? I will be very happy
if you can help me, my hardware is ready,
I have the same remote then yours.

December 27, 2012 at 10:47 PM

I have downloaded the most recent ir library from github and i also am having problems. See below:

sketch_dec27a:12: error: expected constructor, destructor, or type conversion before '<' token
sketch_dec27a:56: error: 'IRrecv' does not name a type
sketch_dec27a:58: error: 'decode_results' does not name a type
sketch_dec27a.cpp: In function 'void setup()':
sketch_dec27a:63: error: 'irrecv' was not declared in this scope
sketch_dec27a.cpp: In function 'void loop()':
sketch_dec27a:94: error: 'irrecv' was not declared in this scope
sketch_dec27a:94: error: 'results' was not declared in this scope
sketch_dec27a.cpp: At global scope:
sketch_dec27a:140: error: expected unqualified-id before '<' token

December 28, 2012 at 8:03 AM


If you copied the sketch directly, there is an error due to formatted javascript code on the website:
The line "# include <irremote .h=".h">" should be "# include <IRremote.h>"
The last line "</ irremote>" spare, delete it.

January 4, 2013 at 12:34 AM

Thank you for taking the time to respond.

January 13, 2013 at 4:33 PM

I've got some errors:

sketch_jan13a:52: error: 'IRrecv' does not name a type
sketch_jan13a:54: error: 'decode_results' does not name a type
sketch_jan13a.ino: In function 'void setup()':
sketch_jan13a:59: error: 'irrecv' was not declared in this scope
sketch_jan13a.ino: In function 'void loop()':
sketch_jan13a:90: error: 'irrecv' was not declared in this scope
sketch_jan13a:90: error: 'results' was not declared in this scope

can someone help me?

January 16, 2013 at 9:10 PM

Can you add a CASE for the fade button to fade between RGB values (swirl effect)?


January 18, 2013 at 1:44 AM

I've tried adding a case for a FADE function; what a nightmare. I'm going to get a new China controller and call it a day.

February 3, 2013 at 7:09 PM

Answering to last anonymous: The FADE function doesnt work because of the delay function can't be interrupted.
You'll have to count the time by another way, such as this one for exemple:

void attendre(int interval) {
currentMillis = millis();

while (millis() - currentMillis < interval) {
if (irrecv.decode(&results)) {
if (results.value != 0xFFFFFFFF) {
irrecv.resume(); // Receive the next value

}//fin du while

and here's the fade fonction:

void Fade() {

// variation de rouge: montée
for (int i=0; i<=255; i++) { // défile valeur 0 à 255
ledRVBpwm(i,0,0); // génère impulsion largeur voulue pour la couleur
if (irrecv.decode(&results)) {
if (results.value != 0xFFFFFFFF) {
irrecv.resume(); // Receive the next value

}//fin du for


If you have any problem, you can contact me at jgrisolia@free.fr

March 3, 2013 at 5:58 PM

Here's an interesting one. The code presented to the Fritzing project showcase compiles without any problem. And this is using the IR remote based libraries created by a probably different fellow then the one for your blog directly.

The one here complains about the missing library which I did manage to download but haven't installed yet.

Also since my RGB LED isn't like yours I won't need the driver transistor block I will only need three resistors.

March 3, 2013 at 6:29 PM

The code (and library) that is presented in that zip file is a fork from the original IR remote code that's presented here http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html from there he presents a master GIT repository and says it has been updated. I suspect that what you have there is older.

May 8, 2013 at 8:42 PM

Thanks for posting ^^

December 13, 2013 at 7:15 PM

Hi can this be made a vise versa , i have a ir controlled RGB led strip and a similar remote for it, and i want to use arduina and a IR led to controll that light strip By ir led

December 16, 2013 at 9:41 AM

@Arttu Mahlakaarto
Yes , the IRremote library can 'send' de same codes.
You must use the object 'IRsend', and de method 'sendNEC'

April 2, 2014 at 12:26 PM

even with the corrections:
The line "# include " should be "# include "
The last line "" spare, delete it.
The code still doesnt compile: IRRecv does not name a type etcetera

April 2, 2014 at 12:37 PM

Found it. it should say "IRremote.h" not "irremote.h"

Post a Comment


Arduino (8) Christmas (1) FFT (2) Lights (4) Microphone (1) MOC3041 (1) MP3 (2) MP3 Player (2) Optocouplers (1) Power (1) Remote controller (1) RGB Led (3) SD (2) Triac (1) TSOP1738 (1) ULN2003 (1) vs1002 (2) vs1003 (2) vs1053 (2) WS2811 (1) WS2812 (1) WS2812b (1) Xmas (1)

Versión española

Versión española
Arduino es Guay!!

Search in this blog


Follow in Facebook

Powered by Blogger.