4/27/14

Controlling LEDs using TV Remote

This post is also published in ERF Blog
In this tutorial we explain how to control the on board LEDs of Induino. Induino is a clone of famous Arduino Uno with on board periperals. Induino contains TSOP which is used to receive IR signals. TV Remote contains IR LED and when any key is pressed it sends modulated IR signals. The signal is inturn is received by the TSOP of the Induino board. A good writeup for interfacing TV Remote with onboard TSOP is available in Induino website.(Credits: Prakash of Simple Labs)
IRremote Library by Ken Shirriff is used to make the things simpler. This library can be used to decode any TV Remote.
I had Videocon TV remote. It doesn’t use any standard protocol. So to decode it I used examples/IRrecvDemo. The code is as follows:
#include <IRremote.h>

int RECV_PIN = 15; //TSOP is connected to the 15th Pin
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
  }
}
After uploading it to the arduino board open the serial monitor and press the keys in the remote for which you want to decode and note down the result in the serial monitor.
In my case when I pressed ’1′ it showed 2FD807F and when I pressed ’2′ it showed 2FD40BF in the serial monitor. These are the hexadecimal codes. You may also get some additional values which I assume it as junk. In my case when I presses ’1′ in addition to 2FD807F the serial monitor showed FFFFFFFF. You can negelect this code as it will come for all the key press.
The key press decoded by IRrecvdemo
The key press ’1′ decoded by IRrecvdemo is displayed on the serial monitor. The second line is assumed to be junk and it can be neglected.
Now you have decoded the key press you can modify the IRrecvdemo to control you LEDs. I have shared the snippet with necessary comments:

#include <IRremote.h>
//declare necessary variables

int RECV_PIN = 15; // TSOP Pin
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  //declare necessay pins as output or input.
  //for eg. declare the LED pins as o/p and TSOP as i/p
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) 
  {
    Serial.println(results.value, HEX);
   
   if(results.value == 0x2FD807F) //2FD807F is the hex code for keypress '1'.
//0x before 2FD807F represents it as hex code.
    {      
          //Turn LED1 on or OFF 
    }
    
    else if(results.value == 0x2FD40BF) //2FD40BF is the hex code for keypress '2'.
//0x before 2FD40BF represents it as hex code.
    {      
         //Turn LED2 on or OFF
           
    }
    
    else if(results.value == 0x2FDC03F)
    {    
         //Turn LED3 on or OFF
    }
    
    else
    {
      //Do nothing.
    }
    
    irrecv.resume(); // Receive the next value
  }
}

Here’s the video of the final outcome:

No comments:

Post a Comment