Using the Infrared IR Remote Receiver with Arduino involves wiring up the receiver to your Arduino-compatible microcontroller, installing the IRremote library, and running the provided example code.
You'll need an IR remote controller to use this example with the receiver:
This board is specifically for receiving 38KHz IR remote control signals - it isn't going to work for proximity/distance sensing or other frequency 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 receiver using a JST PH cable.
-
Board 5V to receiver JST PH V+ (red wire)
-
Board GND to receiver JST PH GND (black wire)
- Board pin 5 to receiver JST PH Sig (white wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to receiver V+ (red wire)
-
Board GND to receiver GND (black wire)
- Board pin 5 to receiver 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 SimpleReceiver.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> // include the library #define IR_RECEIVE_PIN 5 void setup() { Serial.begin(115200); IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); } void loop() { /* * Check if received data is available and if yes, try to decode it. * Decoded result is in the IrReceiver.decodedIRData structure. * * E.g. command is in IrReceiver.decodedIRData.command * address is in command is in IrReceiver.decodedIRData.address * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData */ if (IrReceiver.decode()) { if (IrReceiver.decodedIRData.protocol == UNKNOWN) { IrReceiver.printIRResultRawFormatted(&Serial, true); IrReceiver.resume(); } else { IrReceiver.resume(); IrReceiver.printIRResultShort(&Serial); IrReceiver.printIRSendUsage(&Serial); } Serial.println(); } }
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. As you press buttons on your IR remote, you'll see the protocol, address, command, raw data and repeat gap print to the Serial Monitor.
Text editor powered by tinymce.