How to wire an IR receiver to a Raspberry Pi Pico
To wire an IR receiver to a Raspberry Pi Pico, connect VCC to 3V3(OUT), GND to GND and OUT to GP15 (physical pin 20). 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 Raspberry Pi Pico 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 | Raspberry Pi Pico pin | Wire color | Why |
|---|---|---|---|
| VCC | 3V3(OUT) | red | The VS1838B-style receiver runs from 2.7 to 5.5 V. |
| GND | GND | blue | Ground. |
| OUT | GP15 (physical pin 20) | 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 Raspberry Pi Pico
Logic level
The Raspberry Pi Pico’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(OUT). That pin is the Raspberry Pi Pico’s own regulated 3.3 V output.
This pair
Power the receiver from 3V3 on the Raspberry Pi Pico: 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
The numbers in the code are GP numbers, not the physical pin numbers printed beside the header: GP15 is pin 20. GP23 to GP25 are used on the board itself, and GP25 is the LED.
The working code for the Raspberry Pi Pico
Library: IRremote (IRremote.hpp). This is the sketch the circuit above runs.
#include <IRremote.hpp>
const int IR_PIN = 15; // OUT, GP15 (physical pin 20)
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 a Raspberry Pi Pico
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.
Counting physical pins instead of GP numbers
The sketch says 15, which means GP15, and that is physical pin 20 on the header. Counting 15 pins down the side lands on a different GPIO, and the part never answers.
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.