Project Overview
Arduino + HX1838/VS1838 IR receiver modules: In this guide, you will compare the HX1838 vs VS1838 and wire either one to an Arduino using the IRremote library to reliably decode NEC remote button codes.
The two most common 3-pin infrared receivers in maker kits are the HX1838 and the VS1838. They look identical, they have the same pinout, they decode the same NEC remote-control protocol, and they cost less than a dollar each. So why does one of them sometimes refuse to work in a project where the other works fine? The short answer: they are from different manufacturers with slightly different carrier-frequency tolerance and AGC behavior. The long answer is below.
This guide explains what an IR receiver actually does, what the differences are between the HX1838 and VS1838, and how to wire either one up to an Arduino with the standard IRremote library. Good for retrofitting a remote control onto any project like lamps, fans, garage doors, or robot cars.
- Time: 20 to 40 minutes
- Skill level: Beginner
- What you will build: An Arduino sketch that reads IR remote hex codes, plus an optional remote-controlled relay output.
Parts List
From ShillehTek
- Arduino Nano V3.0 (ATmega328P) - the controller.
- 1-Channel 5V Relay Module - the load you will switch with the remote.
- MAX7219 8x8 LED Matrix - visual feedback when a button is pressed.
- 830-Point Breadboard + DuPont wires.
External
- An HX1838 or VS1838 3-pin IR receiver module (38 kHz carrier).
- An NEC-protocol IR remote (the cheap black 21-key remote that ships with most kits is fine).
- USB cable.
Note: Both modules are typically rated for 2.7 to 5.5 V and share the same pinout, but some clones swap pins. Double-check orientation before applying power.
Step-by-Step Guide
Step 1 - Understand what an IR receiver outputs
Goal: Know what the Arduino is actually reading from the IR receiver.
What to do: An IR receiver module is a tiny photodiode plus an amplifier, a 38 kHz bandpass filter, a demodulator, and an open-collector output. The remote control emits a modulated infrared beam at 38 kHz (other frequencies exist, but 38 kHz is the maker-world default). The receiver strips off the carrier and gives you the raw pulse train on its output pin.
The IRremote library on your Arduino decodes that pulse train into a hex code.
Expected result: You understand that the receiver outputs a digital pulse train (not a direct “hex code”), and the library performs the decoding.
Step 2 - Identify HX1838 vs VS1838 and confirm the pinout
Goal: Confirm which module you have and wire the correct pins.
What to do: Both modules usually look the same and share the same pinout. The differences are mostly manufacturer behavior such as carrier-frequency tolerance and AGC (automatic gain control).
- HX1838: a generic clone, usually a TSOP1838 die in a 3-pin TO-92-like package. 38 kHz centered, ±3 kHz bandwidth. Voltage 2.7 to 5.5 V. Lower-cost AGC.
- VS1838B: a Vishay-like part with tighter tolerance and better AGC for high ambient light. 38 kHz centered, ±2 kHz bandwidth. Voltage 2.7 to 5.5 V.
From the front (the side with the dome that points at the remote):
- Pin 1 (left): OUT - signal to Arduino.
- Pin 2 (middle): GND.
- Pin 3 (right): VCC (5 V or 3.3 V).
Some Chinese clones swap pin 1 and pin 3. If your module gets hot, you have likely wired VCC and GND incorrectly. Power down and re-check the pinout.
Expected result: You can identify OUT, GND, and VCC before connecting to the Arduino.
Step 3 - Upload a basic IRremote sketch to read button codes
Goal: Print the hex code for each remote button in the Serial Monitor.
What to do: Wire the receiver OUT to Arduino D2 (or your chosen pin), power it from 5 V (or 3.3 V), and connect GND to GND. Then upload this sketch.
Code:
#include <IRremote.h>
const int IR_PIN = 2;
IRrecv ir(IR_PIN);
decode_results res;
void setup() {
Serial.begin(9600);
ir.enableIRIn();
}
void loop() {
if (ir.decode(&res)) {
Serial.println(res.value, HEX);
ir.resume();
}
}
Expected result: Open the Serial Monitor at 9600 baud and press buttons on your remote. Each button prints a unique hex code (like 0xFFA25D). Write those down as your key map.
Step 4 - Understand when HX1838 vs VS1838 differences show up
Goal: Choose the best module for your environment and remote.
What to do: In a normal indoor environment, both modules behave similarly. Differences show up under these conditions:
- Bright sunlight on the receiver: the VS1838B’s better AGC keeps decoding; the HX1838 starts to miss codes.
- Cheap or off-frequency remote: if your remote is on 36 or 40 kHz instead of 38, the wider-bandwidth HX1838 may decode it where the tighter VS1838B does not.
- 3.3 V supply: both work, but the HX1838 sometimes has lower sensitivity at the low end of its voltage range.
- Long-range: the VS1838B usually wins by a few meters indoors.
Expected result: You know which receiver is more forgiving (HX1838) and which is more robust under strong ambient light and longer range (VS1838B).
Step 5 - Power the IR receiver cleanly to avoid phantom codes
Goal: Reduce random codes caused by power-rail noise.
What to do: If you see random hex codes printed even with no remote in the room, add a 4.7 µF to 47 µF electrolytic capacitor between VCC and GND right at the module pins, plus a 100 ohm series resistor on the VCC line. This single change solves many phantom code problems on a breadboard.
Expected result: The Serial Monitor stays quiet until you press buttons on the remote.
Step 6 - Build a remote-controlled relay output
Goal: Use a known button code to toggle a relay from the remote.
What to do: After you have hex codes for a few buttons, wire the relay input to D7 and use a simple compare or switch-style mapping in code.
Code:
const int RELAY = 7;
const uint32_t POWER = 0xFFA25D; // example
const uint32_t MUTE = 0xFFE21D;
void setup() {
pinMode(RELAY, OUTPUT); digitalWrite(RELAY, HIGH);
ir.enableIRIn();
}
void loop() {
if (ir.decode(&res)) {
if (res.value == POWER) digitalWrite(RELAY, !digitalRead(RELAY));
ir.resume();
}
}
That is a working "remote-controlled lamp" style project. Wire a 5 V relay module to the relay’s NO terminal and you are done.
Expected result: Pressing your chosen remote button toggles the relay output.
Step 7 - Decide which module to buy for your build
Goal: Pick the right receiver based on your conditions.
What to do: Use these quick guidelines:
- Indoor build, generic NEC remote - either module. They are interchangeable.
- Outdoor build, daylight - VS1838B (better AGC).
- You have a no-name remote that does not work - try the HX1838 (wider bandwidth).
- Long-range receiver mounted on a ceiling - VS1838B.
Expected result: You can choose HX1838 for tolerance and cost, or VS1838B for better sunlight handling and range.
Conclusion
HX1838 and VS1838 are largely interchangeable for Arduino IR projects. For most indoor builds, use whichever your kit includes. For outdoor use, bright sunlight, or longer-range installs, a VS1838B is usually the better choice thanks to stronger AGC and range.
Want the exact parts used in this build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our IoT consulting services.
Attribution: This guide was inspired by the side-by-side tutorial "HX1838 VS1838 NEC Infrared IR Remote Control Sensor Module for Arduino" on Instructables. Images credited to the original author of the source tutorial.


