Arduino Project : IR Remote Decoding

In many Arduino projects, Infra Red (IR) is one of the sensors that is used quite often. This may be due to the relatively low cost of the components. In addition, the general public is familiar with the use of IR for existing home devices, such as TVs, air conditioners, DVD players, etc. Likewise in the Arduino project, the use of IR sensors and IR remote controls is not new anymore.

In this article, we will learn how to decode data from a remote control using an IR Sensor and Arduino. Remote IR decoding is a way to “translate” the data sent by the remote control to the IR sensor, which can then be further processed for certain purposes, such as on/off switches or other purposes. The remote control that will be used this time is the TV remote control.

Components:
• Arduino Uno Board
• IR Sensor (CHQ1838)
• TV remote control

Sketch :

First download the IR Remote Library here , then extract it and place it in the Arduino/libraries folder. Then to decode the IR Remote, we will use the default IRrecvDemo sketch from the IR Remote Library as follows:
/*
* IRremote: IRrecvDemo – demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
// In case the interrupt driver crashes on setup, give a clue
// to the user what’s going on.
Serial.println(“Enable IRin”);
irrecv.enableIRIn(); // Start the receiver
Serial.println(“Enabled IRin”);
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
delay(100);
}

Run the Sketch above, then see the results on the serial terminal for each remote control button pressed.

Here are the HEX values ​​decoding from the 0 to 9 buttons and the power button.

Record the results above, then use them in the following Sketch to display the buttons pressed on the serial monitor.
/*
* IRremote: IRrecvDemo – demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
if(results.value==0x20DF10EF)
{
Serial.print(results.value, HEX);
Serial.println(” : Power Button”);
}
else if(results.value==0x20DF8877)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 1″);
}
else if(results.value==0x20DF48B7)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 2″);
}
else if(results.value==0x20DFC837)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 3″);
}
else if(results.value==0x20DF28D7)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 4″);
}
else if(results.value==0x20DFA857)
{
Serial.print(results.value, HEX);
Serial.println(” : 5″ key);
}
else if(results.value==0x20DF6897)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 6″);
}
else if(results.value==0x20DFE817)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 7″);
}
else if(results.value==0x20DF18E7)
​​{
Serial.print(results.value, HEX);
Serial.println(” : Key 8″);
}
else if(results.value==0x20DF9867)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 9″);
}
else if(results.value==0x20DF08F7)
{
Serial.print(results.value, HEX);
Serial.println(” : Key 0″);
}
else
{
Serial.print(results.value, HEX);
}

irrecv.resume(); // Receive the next value
}
delay(100);
}

From the project above we learned how to decode signals from an IR remote using Arduino. By knowing how to decoding the IR remote, we can use it for other Arduino projects.

Thus our project this time, may be useful and thank you for visiting.

 

Leave a Reply

Your email address will not be published.