Arduino HX1838 IR Receiver Module: Wiring, Code and Simulator

To build this Arduino HX1838 IR Receiver Module project you need an Arduino Uno and an HX1838 IR receiver module and an IR remote. IRremote decodes the NEC codes an HX1838 module receives from the remote; POWER toggles the LED on pin 13. Make the 3 connections in the wiring table, upload the Arduino C++ code, and press keys on the remote. Watch the module’s LED flicker with each frame, and put the logic analyzer on pin 2 to see the 9 ms leader and the 32 bits.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1HX1838 IR receiver moduleA 38 kHz IR receiver on a little board with an LED: S to a pin, + to 5 V, − to GND. Press keys on the IR remote part while running: S pulses LOW with each NEC frame and the LED flickers. Decode it with IRremote.
1IR remotePress a key while running: every IR receiver in the circuit gets its NEC code (address 0).

Wiring

#FromTo
1Arduino Uno pin 2HX1838 IR receiver module S
2Arduino Uno 5VHX1838 IR receiver module +
3Arduino Uno GNDHX1838 IR receiver module -

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an HX1838 IR receiver module and an IR remote from the parts palette.
  3. Wire 1. Connect Arduino Uno pin 2 to HX1838 IR receiver module S.
  4. Wire 2. Connect Arduino Uno 5V to HX1838 IR receiver module +.
  5. Wire 3. Connect Arduino Uno GND to HX1838 IR receiver module -.
  6. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  7. Run it. Press Run. Press keys on the remote. Watch the module’s LED flicker with each frame, and put the logic analyzer on pin 2 to see the 9 ms leader and the 32 bits.

Arduino C++ code

// HX1838 IR receiver module: decode a remote with IRremote.
// S -> pin 2, + -> 5V, - -> GND. The module's LED flickers with every frame.
#include <IRremote.hpp>

const int IR_PIN = 2;
const int LED_PIN = 13;

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  IrReceiver.begin(IR_PIN, DISABLE_LED_FEEDBACK);
  Serial.println("IR module ready: press a key on the remote.");
}

void loop() {
  if (IrReceiver.decode()) {
    if (IrReceiver.decodedIRData.protocol == NEC || IrReceiver.decodedIRData.protocol == NEC2) {
      uint8_t cmd = IrReceiver.decodedIRData.command;
      Serial.print("Key 0x");
      Serial.print(cmd, HEX);
      // The common 21-key remote: 0x45 is POWER, 0x16 is 0.
      if (cmd == 0x45) {
        digitalWrite(LED_PIN, !digitalRead(LED_PIN));
        Serial.print("  (POWER: LED toggled)");
      }
      Serial.println();
    }
    IrReceiver.resume();
  }
}

What to try

Press keys on the remote. Watch the module’s LED flicker with each frame, and put the logic analyzer on pin 2 to see the 9 ms leader and the 32 bits.

Frequently asked questions

How do I wire the HX1838 IR Receiver Module project on an Arduino Uno?

Make 3 connections: Arduino Uno pin 2 to HX1838 IR receiver module S; Arduino Uno 5V to HX1838 IR receiver module +; Arduino Uno GND to HX1838 IR receiver module -.

What parts do I need for this Arduino project?

An Arduino Uno and an HX1838 IR receiver module and an IR remote.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

IRremote decodes the NEC codes an HX1838 module receives from the remote; POWER toggles the LED on pin 13.

What is the difference between the HX1838 module and a bare IR receiver?

Nothing on the signal: the HX1838 (VS1838B) module is the same 38 kHz receiver with an LED and its resistor on a small board. S idles HIGH and goes LOW while it sees the remote’s carrier; the LED lights at the same time.

Why does IRremote print NEC2 or repeat codes?

A key pressed again within about 110 ms is sent as a repeat frame; IRremote 4 reports it as NEC2. Release the key between presses, or treat a repeat as the same key.

More Arduino Uno projects