IR receiver module on pin 11, on an Arduino Uno
An IR receiver module on pin 11: press a button on the remote and the IRremote library prints its command, and pin 13 lights while a code is arriving. The whole build, an Arduino Uno and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 15 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $32. On Mokxi they're free.
What you'll learn
- How infrared remotes send data
- Using the
IRremotelibrary - Decoding a button into a command code
- Hexadecimal numbers
- Difficulty: Beginner
- Time: About 15 minutes
- Board: Arduino Uno R3
- Parts: 4
How it works
The remote flashes infrared light in a pattern. The receiver module turns those flashes back into electrical pulses on its OUT pin, which goes to pin 11. The IRremote library decodes the pulses, using the NEC format, into an address and a command. Each button has its own command.
The sketch prints the command number in hex. Repeat signals, sent when you hold a button, are skipped. The library also blinks the LED on pin 13 while a signal arrives.
Parts list
4 parts, plus the jumper wires. They retail for about $32; on Mokxi they're free.
- 1 × Arduino Uno R3In Starter Kit, Claw Machine Kit, Vending Machine Kit.
- 1 × Half breadboard
- 1 × Infrared receiver, VS1838B
- 1 × Infrared remote, 21 buttons
Kits that can build it
These 8 starter kits have every part in the circuit. Each kit's page lists what else it can build.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Infrared receiver, VS1838B pin GND | Arduino Uno R3 pin GND |
| Infrared receiver, VS1838B pin OUT | Arduino Uno R3 pin 11 |
| Infrared receiver, VS1838B pin VCC | Arduino Uno R3 pin 5V |
| Infrared remote, 21 buttons pin IR | Infrared receiver, VS1838B pin IR |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// An IR receiver on pin 11: which button was pressed?
//
// module S -> pin 11 + -> 5V - -> GND
//
// The receiver turns the remote's flashes back into pulses and IRremote
// decodes them into an address and a command, one command per button. The
// library blinks pin 13 while a signal comes in.
//
// Click a button on the remote on the canvas.
#define DECODE_NEC
#include <IRremote.hpp>
void setup() {
Serial.begin(9600);
IrReceiver.begin(11, ENABLE_LED_FEEDBACK);
Serial.println("Mokxi Uno: IR receiver on pin 11");
}
void loop() {
if (!IrReceiver.decode()) return;
if (!(IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) {
Serial.print("command 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume();
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Opens serial at 9600 baud and starts the receiver with IrReceiver.begin(11, ENABLE_LED_FEEDBACK). That tells the library to listen on pin 11 and to blink pin 13 while a code arrives.
void setup() {
Serial.begin(9600);
IrReceiver.begin(11, ENABLE_LED_FEEDBACK);
Serial.println("Mokxi Uno: IR receiver on pin 11");
}loop sketch.ino
If IrReceiver.decode() finds nothing, the loop returns at once. When a signal is decoded, it skips repeats, then prints the command in hex. IrReceiver.resume() at the end gets the receiver ready for the next button.
void loop() {
if (!IrReceiver.decode()) return;
if (!(IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT)) {
Serial.print("command 0x");
Serial.println(IrReceiver.decodedIRData.command, HEX);
}
IrReceiver.resume();
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Nothing prints when you press a button This project
Check OUT goes to pin 11, with 5V and GND on the receiver. In the simulator, click a button on the remote. - Holding a button prints only once This project
That is by design. The sketch ignores repeat signals. - No signal is seen, or the module gets hot, because the three legs are in the wrong order. Infrared receiver
On the VS1838B, with the dome facing you, the legs are usually OUT, GND, VCC from left to right. Check your module's marking before powering it. Supply is 2.7 to 5.5 V. - A plain LED blinking at the receiver is never detected. Infrared receiver
The receiver only responds to light modulated at about 38 kHz. Send with a library such as IRremote, which makes the carrier. OUT idles high and goes low during a burst, so decode that inverted signal. - Button codes come out wrong or do not match another sketch. Infrared remote
Remotes differ. Print the raw codes for your buttons first, then compare against those values. A repeat while you hold a button is a special repeat code, not a new press. - Nothing is received at all. Infrared remote
Check the receiver pin order of OUT, GND and VCC, which varies by module. Use the pin your IR library expects. Keep the receiver away from bright light and aim the remote at it. - Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.