How to use the IR (Infrared) Remote Control Kit with Arduino

How to use the IR (Infrared) Remote Control Kit with Arduino

Infrared remote kit Arduino

 

INTRODUCTION

It is really easy to control an Arduino using an infrared (IR) remote. The remote comes with a receiver and it operates just like a TV remote and you can configure each button input to produce separate and independent outputs.

APPLICATIONS

Its applications include controlling different parts of a home automation system, smart robots and Audio and Video Systems in a vehicle.

WIRING DIAGRAM

VCC – 5V

GND - GND

Out – Digital Pin 7

Infrared remote control kit arduino connection

Connect the receiver following the connections above.

(Note: Download the required library and follow these steps.)

 

CODE

We will need two sets of code. The first set of code is used to identify the unique hexadecimal number for each key on the remote. Use second set of code is used to operate the remote.

 

First code (to identify the hexadecimal number for each key):

 

#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
}

void loop(){
  if (irrecv.decode(&results)){
        Serial.println(results.value, HEX);
        irrecv.resume();
  }
}

 

Run the code and open the serial monitor and record each key hexadecimal code for each key you want to use.

 

Second code (to operate the remote):

 

#include <IRremote.h>

const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;

void setup(){
  Serial.begin(9600);
  irrecv.enableIRIn();
  irrecv.blink13(true);
}

void loop(){
  if (irrecv.decode(&results)){
 
        if (results.value == 0XFFFFFFFF)
          results.value = key_value;

        switch(results.value){
          case 0xFFA25D:
          Serial.println("CH-");
          break;
          case 0xFF629D:
          Serial.println("CH");
          break;
          case 0xFFE21D:
          Serial.println("CH+");
          break;
          case 0xFF22DD:
          Serial.println("|<<");
          break;
          case 0xFF02FD:
          Serial.println(">>|");
          break ;  
          case 0xFFC23D:
          Serial.println(">|");
          break ;               
          case 0xFFE01F:
          Serial.println("-");
          break ;  
          case 0xFFA857:
          Serial.println("+");
          break ;  
          case 0xFF906F:
          Serial.println("EQ");
          break ;  
          case 0xFF6897:
          Serial.println("0");
          break ;  
          case 0xFF9867:
          Serial.println("100+");
          break ;
          case 0xFFB04F:
          Serial.println("200+");
          break ;
          case 0xFF30CF:
          Serial.println("1");
          break ;
          case 0xFF18E7:
          Serial.println("2");
          break ;
          case 0xFF7A85:
          Serial.println("3");
          break ;
          case 0xFF10EF:
          Serial.println("4");
          break ;
          case 0xFF38C7:
          Serial.println("5");
          break ;
          case 0xFF5AA5:
          Serial.println("6");
          break ;
          case 0xFF42BD:
          Serial.println("7");
          break ;
          case 0xFF4AB5:
          Serial.println("8");
          break ;
          case 0xFF52AD:
          Serial.println("9");
          break ;      
        }
        key_value = results.value;
        irrecv.resume(); 
  }
}

END RESULT

Open the serial monitor and verify the results of each pressed key.

ADDITIONAL RESOURCES

https://www.instructables.com/id/Arduino-Infrared-Remote-tutorial/