Using the Infrared Infrared IR Demodulator Breakout with Arduino involves wiring up the demodulator to your Arduino-compatible microcontroller, installing the IRremote library, and running the provided example code.
You'll need an IR LED or IR remote controller to use this example with the demodulator:
This board is specifically for proximity sensing or break-beam projects. It can receive 38KHz IR remote control signals but there isn't a filter system so you'll get a lot of spurious signals.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the demodulator using a JST PH cable.
-
Board 5V to demodulator JST PH V+ (red wire)
-
Board GND to demodulator JST PH GND (black wire)
- Board pin 5 to demodulator JST PH Sig (white wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to demodulator VIN (red wire)
-
Board GND to demodulator GND (black wire)
- Board pin 5 to demodulator SIG (white wire)
Library Installation
You can install the IRremote library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for IRremote, and select the IRremote library:
There are no additional dependencies needed for this library.
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries // // SPDX-License-Identifier: MIT /* * Based on the ReceiverDump.cpp from the * Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. * by Armin Joachimsmeyer ************************************************************************************ * MIT License * * Copyright (c) 2020-2023 Armin Joachimsmeyer * */ #include <Arduino.h> #include <IRremote.hpp> #define IR_RECEIVE_PIN 5 #define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules. int ir_count = 0; bool ir_state = false; void setup() { pinMode(LED_BUILTIN, OUTPUT); Serial.begin(115200); // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); Serial.print(F("Ready to receive IR signals ")); Serial.print("at pin "); Serial.println(IR_RECEIVE_PIN); } void loop() { // put your main code here, to run repeatedly: if (IrReceiver.decode()) { // Grab an IR code // At 115200 baud, printing takes 200 ms for NEC protocol and 70 ms for NEC repeat ir_state = true; Serial.println(); // blank line between entries Serial.println(); // 2 blank lines between entries IrReceiver.printIRResultShort(&Serial); if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) { Serial.print("Try to increase the \"RAW_BUFFER_LENGTH\" value of "); Serial.println(RAW_BUFFER_LENGTH); // see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library } else { Serial.println(); Serial.println("IR signal received!"); IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format ir_count += 1; Serial.print("Signal count: "); Serial.println(ir_count); Serial.println(); } IrReceiver.resume(); } else { ir_state = false; } }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. As you send IR signals to the demodulator, you'll see the raw data packets print to the Serial Monitor. You'll also see the signal_count
, which increases in value by 1
every time a new signal is detected. A boolean state called ir_state
is true
when a signal is detected and false
when a signal is not detected. You can use this code as a template for using the demodulator as a proximity sensor or break-beam.
Here is the output using an IR remote with the demodulator:
Here is the output using an IR LED emitter with the demodulator:
Text editor powered by tinymce.