There are numerous practical uses for infrared (IR) communication, which is a commonly utilised and simple wireless technology. The most common applications that use infrared communication in daily life are TV/video remote controls, motion sensors, infrared thermometers, air conditioning remote controls, and all other applications.

Many Arduino projects make use of IR communication. We can create remote-controlled robots, heart rate monitors, TV remote controls, and other devices using just a basic IR transmitter and receiver to turn ON or OFF easily.

So in this tutorial I'll demonstrate how to configure an IR receiver and remote on an Arduino. I'll also demonstrate how to operate devices linked to the Arduino using practically any IR remote (such as the one for your TV) or to operate any Load connected to relay module.


What is infrared light?

A type of light that resembles the light we see all around us is infrared radiation. The frequency and wavelength are the only distinctions between IR radiation and visible light. Since infrared radiation is invisible to humans since it is outside the range of visible light.


What is IR Receiver?

IR Receiver

The IR receiver transforms the IR light into an electrical signal using a photodiode and pre-amplifier. Most IR receiver diodes have the following appearance. We are using TSOP38238 IR Receiver.

IR Receiver Pinout 


Relay module

Relay Module

The most popular switching devices in electronics are relays. Unlike transistors, which have a maximum current limit and are unable to switch AC loads, it can be used to switch large current loads with ease. Both AC and DC loads can be switched using this 5V 10A relay module.

It is an electromagnetic switch that can turn on or off a high current circuit when a tiny current is applied to the coil inside. It contains screw terminals on the PCB for direct connection. They can be used in home automation to turn appliances ON or OFF, in electronic circuits to carry out switching operations, in safety circuits to disconnect or connect heavy loads.

Relay Module Pinout


Components Required

Software Required

  • Arduino IDE


Circuit Diagram

  1. To find the remote control hexadecimal code

 Circuit Diagram


Arduino Code

To find the remote control hexadecimal code

Each time you press a button on the remote control, a unique hexadecimal code is generated. This data is then modulated and transmitted over IR to the receiver. The receiving microcontroller needs to be aware of the code each key on the remote corresponds to in order to determine which key was pressed.

You can determine the code generated for each key on your specific remote because different remotes transmit different codes in response to key presses. The IR key codes need to be mentioned in the datasheet, if you can locate it. If not, there is a simple Arduino sketch that, when you press a key, it will send the hexadecimal codes to the serial monitor and from there we can get the desired  hexadecimal  code which we will be using in another code. 

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results; 

void setup() {


  irrecv.enableIRIn(); // Start the receiver

void loop() {

  if (irrecv.decode(&results))


     Serial.println(results.value, HEX);

     irrecv.resume(); // Receive the next value




Circuit Diagram

  1. For relay module operation

Circuit Diagram 


Arduino Code

For relay module operation

//IR Remote Control Relay

#include <IRremote.h>

int RECV_PIN = 2; // IR Receiver PIN

int led1 = 3;   // relay module input at pin 3

int led2 = 4;   // for additional relay module input

int state[] = {0,0,0};

#define code1 0x1FE50AF  // Button 1 Code, replace last 7 digits with                          new code generate

#define code2 0x1111111  // Button 2 Code, in case you are using two relay module

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup() {

//Serial.begin(9600); // you can ommit this line


pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);


void loop() {

if (irrecv.decode(&results)) {

unsigned int value = results.value;

switch(value) {

case code1:

if(state[1] == 1) {       // if first led is on then

digitalWrite(led1, LOW);  // turn it off when button is pressed

state[1] = 0;             // and set its state as off

} else {                  // else if first led is off

digitalWrite(led1, HIGH); // turn it on when the button is pressed

state[1] = 1;             // and set its state as on



case code2:

if(state[2] == 1) {

digitalWrite(led2, LOW);

state[2] = 0;

} else {

digitalWrite(led2, HIGH);

state[2] = 1;




//Serial.println(value); // you can ommit this line



After uploading this code, you are ready to test the circuit. Just power the Arduino and press the remote button whose hexadecimal code you have entered in the Arduino code. On pressing you will see that the relay will operate and whatever the load is connected to it, will turn ON. Now you can control all your appliances with the help of a remote.



Codes are not generated when key is pressed?

This may happen due to improper connection of the IR receiver. You must check the polarity of this IR receiver.

Remote not working?

Try to replace the remote batteries.

Circuit is not responding?

Ensure that all the connections you have is made is according to circuit diagram.

Relay module is not working?

If so, then you must check the Vcc of the relay, it must be supplied with the proper 5V DC supply. You can also use a separate 5V DC power supply to power the module.

Leave a comment

Please note, comments must be approved before they are published

Your cart