Turn Led ON/OFF with any remote control

Julien Louage
JLouage
Published in
4 min readSep 20, 2018

--

I made this Arduino project that allows to turn ON and OFF LEDs using an IR remote control. The project is pretty simple, you don’t need a lot of components. In my case I have used an Arduino Uno R3, Breadboard, any remote control, 4 x 200Ω resistors, 4 leds, AX-1838HS IR receiver module and some jumper wires. You must check the datasheet before use the IR module to see which pins connect to the power supply and which one delivers the output voltage. In my case the infrared receiver has 3 pins:

  • First pin: Vout, outputs HIGH when no signal is present and LOW when a mark is received.
  • Second pin: GND.
  • Third pin: Vcc.

I used an available IR Arduino library so it was pretty easy to decode the signals transmitted by the infrared remote. Download the latest version. To install the library, simply open your Arduino IDE, go to Sketch -> Include Library -> Add .ZIP Library. Choose your downloaded zip file and import it.

Schematics

You need to wire your circuit like the schematic above. Upload the below sketch to your Arduino, open the serial monitor and start using your remote control and see which values the Arduino is receiving. Write down which values appear in the serial monitor when you press the numbers keys (From 0 to 9) or any other key you want to use. In my case they were:

  • 16705559 = 1
  • 16672919 = 2
  • 16689239 = 3
  • 16656599 = 4
  • 16697399 = 5
  • 16664759 = 6
  • 16681079 = 7
  • 16648439 = 8
  • 16707599 = 9
  • 16674959 = 0

Sketch

#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
#include <IRremoteInt.h>
IRrecv irrecv(11);
decode_results results;
long lastPressTime = 0;
int state = LOW;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
}

Now you need to update the below sketch to use those codes. You need to change the #define ONE by your code of the first button, then for the #define Two and the same for the rest buttons. Upload your code to your Arduino and Enjoy!!!

/*
source: www.jlouage.com
You'll need to change the led pins and the codes
accordingly to your configuration and IR remote
*/
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#define RED_LED_PIN 4 //Define the pin of the red led
#define BLU_LED_PIN 5 //Define the pin of the blue led
#define YEL_LED_PIN 6 //Define the pin of the yellow led
#define GRE_LED_PIN 7 //Define the pin of the green led
#define ONE 16705559 //Define the key 1
#define TWO 16672919 //Define the key 2
#define THREE 16689239 //Define the key 3
#define FOUR 16656599 //Define the key 4
#define FIVE 16697399 //Define the key 5
#define SIX 16664759 //Define the key 6
#define SEVEN 16681079 //Define the key 7
#define EIGHT 16648439 //Define the key 8
#define NINE 16707599 //Define the key 9
#define ZERO 16674959 //Define the key 0
IRrecv irrecv(11); //The pin where you connect the output pin of AX-1838HS
decode_results results;
void setup()
{
pinMode(RED_LED_PIN, OUTPUT); //Change the mode of the red led pin to output
pinMode(YEL_LED_PIN, OUTPUT); //Change the mode of the yellow led pin to output
pinMode(BLU_LED_PIN, OUTPUT); //Change the mode of the blue led pin to output
pinMode(GRE_LED_PIN, OUTPUT); //Change the mode of the green led pin to output
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {

if (results.value == ONE) { //Check if the key 1 is pressed
digitalWrite(RED_LED_PIN, HIGH); //Turn on the red led
}else if(results.value == TWO) { //Check if the key 2 is pressed
digitalWrite(BLU_LED_PIN, HIGH); //Turn on the blue led
}else if(results.value == THREE) { //Check if the key 3 is pressed
digitalWrite(YEL_LED_PIN, HIGH); //Turn on the yellow led
}else if(results.value == FOUR) { //Check if the key 4 is pressed
digitalWrite(GRE_LED_PIN, HIGH); //Turn on the green led
}else if(results.value == FIVE) { //Check if the key 5 is pressed
digitalWrite(RED_LED_PIN, LOW); //Turn off the red led
}else if(results.value == SIX) { //Check if the key 6 is pressed
digitalWrite(BLU_LED_PIN, LOW); //Turn off the blue led
}else if(results.value == SEVEN) { //Check if the key 7 is pressed
digitalWrite(YEL_LED_PIN, LOW); //Turn off the yellow led
}else if(results.value == EIGHT) { //Check if the key 8 is pressed
digitalWrite(GRE_LED_PIN, LOW); //Turn off the green led
}else if(results.value == NINE) { //Check if the key 9 is pressed
digitalWrite(RED_LED_PIN, HIGH); //Turn on the red led
digitalWrite(BLU_LED_PIN, HIGH); //Turn on the blue led
digitalWrite(YEL_LED_PIN, HIGH); //Turn on the yellow led
digitalWrite(GRE_LED_PIN, HIGH); //Turn on the green led
}else if(results.value == ZERO) { //Check if the key 0 is pressed
digitalWrite(RED_LED_PIN, LOW); //Turn off the red led
digitalWrite(BLU_LED_PIN, LOW); //Turn off the blue led
digitalWrite(YEL_LED_PIN, LOW); //Turn off the yellow led
digitalWrite(GRE_LED_PIN, LOW); //Turn off the green led
}
irrecv.resume(); // Receive the next value
}
}

--

--