IR Receiver

Updated on 31 August 2021
dev board Arduino UNO
chip TSOP4838
sensor infrared
features infrared IR receiver
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Code

Download code ir-receiver.ino
#include <IRLibAll.h>

IRrecvPCI myReceiver(2);
IRdecode myDecoder;

void setup() {
  Serial.begin(9600);
  delay(2000); while (!Serial);
  myReceiver.enableIRIn();
  Serial.println("Ready to receive IR signals...");
}

void loop() {
  if (myReceiver.getResults()) {
    myDecoder.decode();
    myDecoder.dumpResults(true);
    myReceiver.enableIRIn();
  }
}

Makefile

BOARD?=arduino:avr:uno
PORT?=/dev/cu.usbmodem14*

.PHONY: lint compile upload clean

default: lint all flash clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

all:
	arduino-cli compile --fqbn $(BOARD) ./

flash:
	arduino-cli upload -p $(PORT) --fqbn $(BOARD) ./

clean:
	rm -f .*.hex
	rm -f .*.elf

Schematic

Wire up the hardware accordingly

IR Receiver schematic

Serial console

Serial output from the firmware.

IR Receiver serial console

Description

Use IR receiver TSOP4838 and Arduino to receive remote controller IR codes. Start monitoring the serial console, and then press the remote controller button.

Only supported protocols for the remote controllers can be used. If the protocol is supported, then the serial console’s first line will show the decoded protocol and the hex code values.

Debugging

For error on lto1: internal compiler error: in lto_output_varpool_node, at lto-cgraph.c:624, install version 1.6.21 of the IR Arduino library:

arduino-cli core install arduino:[email protected]

Sample Remote control HEX

For Benq projector remote control

ON
Decoded NEC(1): Value:CF20D

OFF
Decoded NEC(1): Value:C728D

Increase volume
Decoded NEC(1): Value:C41BE

Decrease volume
Decoded NEC(1): Value:CC13E

Eco blank
Decoded NEC(1): Value:CE01F

References