Arduino Infrared Remote Control

This document describes how to implement an Arduino Infrared Remote Control using an Arduino single board computer as a receiver for infrared remotes control signals to control a MythTV frontend system. The example code below uses a Hauppauge Gray remote control but the Arduino code can easily be modified to utilize any remote control.
Introduction
Having used an older Hauppauge HVR-1950 as a receiver for infrared (IR) remote control and ir-keytable to interpret the meanings for key presses to control a MythTV frontends has been an ongoing concern. Over time, a number of remotes and the HVR-1950 hardware have died which forced the initial search for a replacement of the infrared remote control for a MythTV frontend system.
Compatibility issues have been encountered in getting various features of infrared remote controls to work under different versions of Ubuntu, MythTV, LIRC and ir-keytable. This led to thinking about how to control a MythTV frontend in a way that was independent of which version of MythTV that was running. For a time, a wireless keyboard was the only thing that would work to control the MythTV frontend which led to a search for how to combine infrared remote control and keyboard functions to control a MythTV frontend. The other benefit to this approach is that it is completely independent of the MythTV system and not impacted when upgrading or replacing frontend hardware or software. All that is needed is a USB port on the frontend and a relatively inexpensive Arduino.
Certain Arduino models can operate as Human Interface Devices (HID) and can emulate a plug-and-play keyboard. When an infrared receiver is connected to this Arduino, the combination allows for remote control of a MythTV frontend system that is independent of LIRC or ir-keytable. The Arduino receives and interprets the infrared signal from the remote and translates it into a keyboard special character, letter or number that is sent to the MythTV frontend just like controlling the MythTV frontend with an attached keyboard.
In the example code below, an Arduino R4 Minima with the IRremote library is used to receive the IR signals. The Arduino Keyboard library is used to send keyboard commands to a MythTV frontend. See the reference to Arduino Keyboard library in the reference section below for details of which Arduino models have HID support and can emulate a keyboard.
Since the Arduino is basically emulating a keyboard, it could be used to control any application not just MythTV. The Arduino Keyboard library also allows for multiple simultaneous key presses like Control - C or other key combinations to do complex operations.
Requirements


Here is what is needed to implement an Arduino Infrared Remote Control:
- A MythTV frontend system (any version)
- USB cable that connects frontend to Arduino
- Infrared Remote Control
- An Arduino that supports HID keyboard emulation
- The Arduino IDE or alternative software development environment
- An infrared receiver like a TSOP38238 (38KHz)
- Optional case for the Arduino
Check the IR receiver data sheet to determine the supported voltage and pinouts on the infrared receiver to determine which pins to connect to data, voltage and ground pins on the Arduino.
Most infrared remote controls utilize 38kHz signaling but in the off chance that a remote control uses a different frequence, a different infrared receiver model may be needed to match the specific frequency. The last 2 digits of the TSOP382xx designate the infrared carrier frequency.
No soldering is required but the leads from the IR received will need to connect to the 3.3 or 5 volt, signal and ground pins of the Arduino. This can be done with a 3 pin female to male jumper cable where the male ends can be separated and plugged into the ports of the Arduino.
Minimal Arduino C++ coding is required to get this project working though a couple lines in the example code below will need to be changed to match the remote control codes being used.
Installation/Configuration
The first step in building the Arduino Infrared Remote Control is to decode the infrared codes generated by the remote control to be used. Luckily the Arduino IRremote library contains example code that can be downloaded to the Arduino to decode the buttons on the remote control. Most Arduino computers can be used to receive infrared remote control signals so the initial decoding of the infrared signal does not require an Arduino model that supports the keyboard emulation. Though, the final configuration will require an Arduino that supports HID.
Download the Arduino IDE or other development environment. The Arduino IDE runs on Mac, Windows and Linux. In the Arduino IDE, download the IRremote library then select: File / Examples / IRremote / SimpleReceiver
This will open the example code to receive and decode infrared remote codes. Note the PinDefinitionsAndMore.h file contains the default pins used for infrared input specific to the model of Arduino and connect the data pin for the infrared receiver to that pin. Also note the Serial.begin(<speed>) and change to match the speed selected in the Serial Monitor or set the serial monitor speed to match. That is, the Serial Monitor Speed must match the Serial.begin speed selection in the Arduino C++ code.
Connect the Arduino to a computer running the Arduino IDE and select the Arduino model board in Tools / Board.
Next, select Tools / Port and select the port for the Arduino. If the Arduino is successfully connected to the Arduino IDE code, the board should be identified and in bold text at the top of the page.
The SimpleReceiver example code can now be downloaded to the Arduino.
If successfully downloaded, then select Tools / Serial Monitor to view infrared codes received by the Arduino. When the SimpleReceiver code runs, the port used to connect the infrared receiver will be displayed in the Serial Monitor.
Disconnect the Arduino from the USB port and connect the infrared receiver to the data, 3.3 or 5 volt and ground. Reconnect the Arduino to the USB port and repeat the steps above to get the Serial Monitor up and receiving data from the Arduino.
Now, the infrared codes sent when certain keys on the remote are pressed can be captured. At a minimum, the following key codes will need be captured:
Up/down/left/right arrow keys, pause/play button, enter/OK button, menu button, delete button and exit/escape button. Make a table or Excel spreadsheet with the MythTV Function, Keyboard Key, IR Address and IR Command codes.
Hauppauge Gray Remote Control Codes
For the Hauppauge Gray Remote Control the values were:
Function Keyboard Key IR Address IR Command --------- ------------ ---------- ---------- Move Up KEY_UP_ARROW 0x1E 0x14 Move Down KEY_DOWN_ARROW 0x1E 0x15 Move Left KEY_LEFT_ARROW 0x1E 0x16 Move Right KEY_RIGHT_ARROW 0x1E 0x17 OK KEY_ENTER 0x1E 0x25 PLAY KEY_ENTER 0x1E 0x35 Pause/Play P 0x1E 0x30 Exit KEY_ESC 0x1E 0x1F MENU M 0x1E 0x0D Green E 0x1E 0x2E Record(Red) D 0x1E 0x37 Rewind KEY_PAGE_UP 0x1E 0x32 Forward KEY_PAGE_DOWN 0x1E 0x34
Philips Universal 4 Device Remote Control
Also tested was a Philips universal remote control which generated the same codes for the codes above. The universal code for the Philips to emulate a Hauppauge controller was 1624 which was entered in the universal remote. Unfortunately the EXIT and MENU keys on the Philips remote did not match the Hauppauge Gray remote. So that the Philips universal remote would be usable, there are multiple command codes for these 2 functions in the C++ code below so the Arduino Infrared Remote Control receiver will work with either the Hauppauge or Philips remote control.
For the Philips Universal Remote Control, a couple of the values were different from the Hauppauge Gray remote:
Function Keyboard Key IR Address IR Command --------- ------------ ---------- ---------- Exit KEY_ESC 0x1E 0x24 MENU M 0x1E 0x3B
Arduino_Infrared_Remote_Control.ino Code
Here is the C++ code to implement the Arduino Infrared Remote Control:
/*
* Arduino_Infrared_Remote_Control.ino
*
* Code to receive an RC5 infrared code and then send a corresponding keyboard character via USB.
* Uses the Arduino IRremote example dump code to determine the address and command codes for your
* specific remote control. You can remove comments below to scan codes from your remote.
* Note that Keyboard emulation will not work when Serial.print is enabled.
* To receive infrared codes, connect a 38 kHz infrared receiver (Example TSOP 38038).
* Check the datasheet for your IR receiver to determine which pin connects to Pin 2 and which
* pins connect to 3.3 volts and ground.
* You must use an Arduino model with HID support in order to emulate a keyboard.
* Example: Arduino Uno R4 Minima.
*
* MIT License
*
* Copyright (c) 2025 Dennis McCloud
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Acknowledgement to Ken Shirriff, Rafi Khan and Armin Joachimsmeyer et al. who developed
* the Arduino-IRremote code and library which was the source and inspiration
* for this code and Tom Igoe who developed the Arduino Keyboard code and library.
*/
#include <Arduino.h>
#include <IRremote.hpp> // include the library
#include "Keyboard.h"
#define IR_RECEIVE_PIN 2 // IR Receive Pin on Arduino UNO R4 Minima
#define DECODE_RC5 // Decode RC5 Protocol change to match that of your remote
void setup() {
// Start the Infrared receiver
IrReceiver.begin(IR_RECEIVE_PIN);
// Initialize the built-in LED to flash when sending characters
pinMode(LED_BUILTIN, OUTPUT);
// Initialize control over the keyboard:
// Note that you must disable the serial port when using the HID keyboard simulation
Keyboard.begin();
}
void loop() {
/*
* Check if received data is available and decode it.
* Decoded result is in the IrReceiver.decodedIRData structure.
*/
if (IrReceiver.decode()) {
// Turn On Built-In LED
digitalWrite(LED_BUILTIN, HIGH);
/*
* Received an unknown protocol, skip that data - probably noise
*/
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
IrReceiver.resume(); // Enable receiving of the next IR code
return;
} else {
IrReceiver.resume(); // Enable receiving of the next IR code
}
// Ignore Duplicate Received IR Signals
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
IrReceiver.resume(); // Enable receiving of the next IR code
return;
}
/*
* If IR signal received was not RC5 then ignore
* Change to match your specific remote control
*/
if (IrReceiver.decodedIRData.address != 0x1E ) {
IrReceiver.resume(); // Enable receiving of the next IR code
return;
}
// For reference, below are the key definitions for Keyboard.h routine:
// KEY_LEFT_CTRL, KEY_LEFT_SHIFT, KEY_LEFT_ALT also RIGHT versions
// KEY_BACKSPACE, KEY_TAB, KEY_RETURN (Enter), and KEY_ESC (Escape)
// KEY_UP_ARROW, KEY_DOWN_ARROW, KEY_LEFT_ARROW, KEY_RIGHT_ARROW
// KEY_PAGE_UP, KEY_PAGE_DOWN, KEY_HOME, and KEY_END
// KEY_KEYPAD_0 to KEY_KEYPAD_9, KEY_KEYPAD_ENTER, KEY_KEYPAD_PLUS
// KEY_KEYPAD_MINUS, KEY_KEYPAD_MULTIPLY, KEY_KEYPAD_DIVIDE,
// and KEY_KEYPAD_NUMLOCK
//
// Below are the different formats for the Keyboard.write, press, and release/All routines:
// Send a keyboard key emulation, P for pause:
// Keyboard.write('P');
// Press and Hold a key
// Keyboard.press(<keyCode>);
// Release a held key
// Keyboard.release(<keyCode>);
// Release all held keys
// Keyboard.releaseAll();
// Below are the codes that are used for MythTV remote control
// These are for the Hauppauge Gray remote control which is RC5 IR protocol
// Change IR codes to match your specific remote control
// PLAY or OK Buttons on remote translate to Return
if (IrReceiver.decodedIRData.command == 0x25 || IrReceiver.decodedIRData.command == 0x35) {
Keyboard.write(KEY_RETURN);
// EXIT Key translates to Escape (0x1F Hauppauge - 0x24 Philips Universal)
} else if (IrReceiver.decodedIRData.command == 0x1F || IrReceiver.decodedIRData.command == 0x24) {
Keyboard.write(KEY_ESC);
// Up Arrow
} else if (IrReceiver.decodedIRData.command == 0x14) {
Keyboard.write(KEY_UP_ARROW);
// Down Arrow
} else if (IrReceiver.decodedIRData.command == 0x15) {
Keyboard.write(KEY_DOWN_ARROW);
// Left Arrow
} else if (IrReceiver.decodedIRData.command == 0x16) {
Keyboard.write(KEY_LEFT_ARROW);
// Right Arrow
} else if (IrReceiver.decodedIRData.command == 0x17) {
Keyboard.write(KEY_RIGHT_ARROW);
// Pause/Play toggle
} else if (IrReceiver.decodedIRData.command == 0x30) {
Keyboard.write('P');
// Menu
} else if (IrReceiver.decodedIRData.command == 0x0D || IrReceiver.decodedIRData.command == 0x3B) {
Keyboard.write('M');
// Green Button - Edit
} else if (IrReceiver.decodedIRData.command == 0x2E) {
Keyboard.write('E');
// Record button is Delete
} else if (IrReceiver.decodedIRData.command == 0x37) {
Keyboard.write('D');
// Skip Back is Page Up
} else if (IrReceiver.decodedIRData.command == 0x32) {
Keyboard.write(KEY_PAGE_UP);
// Skip Forward is Page Down
} else if (IrReceiver.decodedIRData.command == 0x34) {
Keyboard.write(KEY_PAGE_DOWN);
} else {
// Ignore any codes not expressly identified above
// Add any additional keyboard key and infrared code as needed
;
}
}
// Turn off Built-In LED
digitalWrite(LED_BUILTIN, LOW);
}
Acknowledgement
Acknowledgement to Ken Shirriff, Rafi Khan and Armin Joachimsmeyer et al. who developed the Arduino-IRremote code and library which was the source and inspiration for this project and Tom Igoe who developed the Arduino Keyboard code and library.
References
Arduino IDE: https://www.arduino.cc/en/software/
Arduino Keyboard: https://docs.arduino.cc/language-reference/en/functions/usb/Keyboard/
Arduino IRremote Library: https://docs.arduino.cc/libraries/irremote/