IR Receiver
Interfacing IR Receiver with ESP32
Interfacing IR Receiver with ESP32 demonstrates how an infrared (IR) receiver can be connected to an ESP32 board to receive and decode signals transmitted by an IR remote control.
The ESP32 receives the infrared signal through a digital GPIO pin. The received IR data is decoded using the IRremote library and the decoded information is displayed on the Serial Monitor.
IR Remote → IR Receiver → ESP32 → Serial Monitor
Objectives
- To study the working of an IR receiver.
- To interface an IR receiver with the ESP32 board.
- To receive infrared signals from an IR remote control.
- To decode the received IR signal using the IRremote library.
- To display the received IR information on the Serial Monitor.
Software
- Arduino IDE
- IRremote library
Hardware Modules
- ESP32 Board
- IR Receiver Module
- IR Remote Control
- PC / Laptop
- Connecting wires
Theory
Introduction to Infrared Communication
Infrared (IR) communication is a method of transmitting information using infrared light.
An IR remote control contains an infrared LED that transmits modulated infrared signals when a button is pressed.
The IR receiver detects the infrared signal and converts it into an electrical signal that can be processed by the ESP32.
IR Remote → Infrared Signal → IR Receiver → Electrical Signal → ESP32
Different buttons on an IR remote transmit different coded signals. The receiver detects these signals and the IRremote library decodes the received data.
IR Receiver
An IR receiver module is used to detect infrared signals transmitted by an IR remote control.
A typical IR receiver module has three terminals:
| Pin | Connection | Function |
|---|---|---|
| VCC | ESP32 3.3V | Power supply |
| GND | ESP32 GND | Ground |
| OUT | ESP32 GPIO 4 | IR signal output |
The OUT pin provides the received IR signal to the ESP32.

IR Communication
When a button on the IR remote is pressed, the remote transmits an infrared signal.
The IR receiver detects the transmitted signal and provides the corresponding digital signal at its output.
The ESP32 monitors the receiver output using the IRremote library.
The received signal is then decoded and the information is displayed on the Serial Monitor.
Remote Button → IR Transmission → Receiver → ESP32 → Decoded Data
Connections
| Device | Pin | ESP32 | Function |
|---|---|---|---|
| IR Receiver | OUT | GPIO 4 | IR signal input |
| IR Receiver | VCC | 5V | Power supply |
| IR Receiver | GND | GND | Ground |
Steps for Assembling the Circuit
- Connect the OUT pin of the IR receiver to GPIO 4 of the ESP32.
- Connect the VCC pin of the IR receiver to the appropriate supply pin of the ESP32.
- Connect the GND pin of the IR receiver to the GND of the ESP32.
- Connect the ESP32 board to the PC/Laptop using a USB cable.
- Point an IR remote towards the IR receiver.
Safety Precautions
- First, make all the connections according to the circuit diagram.
- Check the pin configuration of the IR receiver before connecting the power supply.
- Ensure that VCC and GND connections are correct.
- Ensure that the IR receiver OUT pin is connected to GPIO 4.
- Then connect the ESP32 board to the PC/Laptop.
- Avoid short-circuiting the ESP32 power and ground connections.
Schematic Diagram
The IR receiver is connected to the ESP32 through GPIO 4.
The receiver detects infrared signals from the remote control and sends the received signal to the ESP32.
IR Remote → IR Receiver OUT → ESP32 GPIO 4 → IRremote Library → Serial Monitor
Interfacing Diagram Using Breadboard
The IR receiver can be connected to the ESP32 using a breadboard.
The OUT terminal of the IR receiver is connected to GPIO 4.
The VCC and GND terminals are connected to the corresponding power and ground connections.
Procedure
- Install the IRremote library in the Arduino IDE.
- Connect the IR receiver to the ESP32 according to the connection table.
- Write the program given below.
- Save and compile the program.
- Connect the ESP32 board to the PC/Laptop using a USB cable.
- Upload the program to the ESP32.
- Open the Serial Monitor.
- Set the Serial Monitor baud rate to 9600.
- Point the IR remote towards the IR receiver.
- Press different buttons on the IR remote.
- Observe the decoded IR information on the Serial Monitor.
Algorithm
The following algorithm is used to interface the IR receiver with the ESP32:
- Start the Arduino IDE.
- Include the IRremote library.
- Define GPIO 4 as the IR receiver input pin.
- In the void setup() function, initialize Serial communication at 9600 baud.
- Initialize the IR receiver using the IrReceiver.begin() function.
- In the void loop() function, check whether an IR signal has been received.
- If an IR signal is received, decode the signal.
- Print the decoded IR result on the Serial Monitor.
- Resume the IR receiver to wait for the next signal.
- Repeat the process continuously.
The overall operation is:
IR Remote → IR Receiver → ESP32 GPIO 4 → Decode → Serial Monitor
Working
The ESP32 initializes the IR receiver connected to GPIO 4.
The IRremote library is used to receive and decode the infrared signal.
When a button on the IR remote is pressed, the IR receiver detects the infrared transmission.
The program checks for a received signal using:
IrReceiver.decode()
If an IR signal is received, the program prints a short representation of the decoded IR result using:
IrReceiver.printIRResultShort(&Serial);
After processing the received signal, the receiver is made ready to receive the next signal using:
IrReceiver.resume();
IR Signal → Decode → Print Result → Resume Receiver
IRremote Functions Used
| Function | Purpose |
|---|---|
| IrReceiver.begin() | Initializes the IR receiver |
| IrReceiver.decode() | Checks and decodes a received IR signal |
| IrReceiver.printIRResultShort() | Prints a short decoded IR result |
| IrReceiver.resume() | Prepares the receiver to receive the next signal |
Program
#include <IRremote.hpp>
#define IR_PIN 4
void setup() {
Serial.begin(9600);
IrReceiver.begin(IR_PIN, ENABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.printIRResultShort(&Serial);
IrReceiver.resume();
}
}
Observation
Open the Serial Monitor and set the baud rate to 9600.
Point the IR remote towards the IR receiver and press different buttons.
The received IR signals and their decoded information are displayed on the Serial Monitor.
The output depends on the IR remote control and the protocol used by the remote.
Result
The ESP32 successfully interfaces with the IR receiver using GPIO 4.
The IRremote library successfully receives and decodes infrared signals transmitted by an IR remote control and displays the decoded IR information on the Serial Monitor.