How to wire an IR receiver to an ESP32-S3
To wire an IR receiver to an ESP32-S3, connect VCC to 3V3, GND to G and OUT to GPIO 4. Power the receiver from 3.3 V so its output swings to 3.3 V, the board’s own level; from 5 V its output would idle at 5 V on a 3.3 V pin. The sketch below uses the IRremote (IRremote.hpp) library. It decodes the buttons of an NEC remote and prints each command code.
- 3.3 V logic
- Library: IRremote.hpp
- 3 wires, 1 helper parts
IR receiver to ESP32-S3 wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| IR receiver pin | ESP32-S3 pin | Wire color | Why |
|---|---|---|---|
| VCC | 3V3 | red | The VS1838B-style receiver runs from 2.7 to 5.5 V. |
| GND | G | blue | Ground. |
| OUT | GPIO 4 | amber | Low while a 38 kHz burst arrives, high otherwise: the demodulated code. |
| IR (light) | The remote | n/a | In the editor the infrared light path is drawn as a gray wire from the remote. |
Helper parts
The extra parts in the circuit above, and where their wires go:
| From | To | Wire color |
|---|---|---|
| RM1 pin IR | IR | gray |
Power and logic levels for IR receiver and ESP32-S3
Logic level
The ESP32-S3’s GPIO pins are 3.3 V logic and are not 5 V tolerant. Nothing wired to a pin may go above 3.3 V.
Supply
The IR receiver takes 3.3 V from 3V3. That pin is the ESP32-S3’s own regulated 3.3 V output.
This pair
Power the receiver from 3V3 on the ESP32-S3: its output then swings to 3.3 V, the board’s own level. Fed from 5 V, its output would idle at 5 V on a 3.3 V pin.
Pins to leave alone
GPIO 19 and 20 are the USB port’s data lines, GPIO 35 to 37 belong to the PSRAM on octal-PSRAM boards such as the N8R8, and GPIO 0, 3, 45 and 46 are strapping pins.
The working code for the ESP32-S3
Library: IRremote (IRremote.hpp). This is the sketch the circuit above runs.
#include <IRremote.hpp>
const int IR_PIN = 4; // OUT, GPIO 4
void setup() {
Serial.begin(115200);
IrReceiver.begin(IR_PIN);
Serial.println("Point the remote and press a button");
}
void loop() {
if (IrReceiver.decode()) {
if (!(IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) {
Serial.print("Command: 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume(); // ready for the next one
}
}
What you should see
Open the serial monitor at 115200 baud. The sketch prints Point the remote and press a button, and then a Command line in hexadecimal for each button press on the remote in the circuit.
A receiver that never prints anything is usually on the wrong pin, or the remote uses a protocol other than NEC.
The serial monitor prints this, recorded from the circuit above with one remote button pressed after 300 ms:
Point the remote and press a button
Command: 0x47Common mistakes wiring an IR receiver to an ESP32-S3
Old IRremote code
Sketches written for IRremote 2.x use IRrecv irrecv(pin), irrecv.enableIRIn() and results.value. Version 3 and later use IrReceiver and decodedIRData, as here. Mixing the two is the most common reason an IR sketch will not compile.
Forgetting resume()
After decode() returns true, the library holds the code until resume() is called. Leave it out and the first button press is the only one you ever see.
Using the USB or PSRAM pins
GPIO 19 and 20 are the USB port’s data lines and GPIO 35 to 37 belong to the PSRAM on N8R8 boards. Wire the receiver output to one of those and the USB socket or the memory stops working on a real board, even though the simulator carries on. Stay on GPIO 4 to 18.
Build your own IR receiver project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.