I explain below how I used LIRC, a cheap usb IR receiver, and the Android program Rcoid to get my Samsung S4 working as a remote control. This will only work for Android phones that have a built-in IR blaster (such as the Samsung S4 and S5 and the LG G2).
Creating an LIRC Configuration File for your Remote Control:
Your remote may already have an LIRC file that you can download. Mine did not, so I needed to make own. To do this, I purchased the TSDX-IR14 usb IR receiver. (Linux identifies it as eHome Infrared Transceiver made by Topseed Technology Corp.) After plugging the IR receiver into my computer, I then installed LIRC on my desktop (sudo apt-get install lirc).
During the LIRC setup I selected:
1) Remote control Configuration: Linux input layer (/dev/input/eventX)
2) Ir transmitter, if present: Custom
3) Interface for your dev/input device: /dev/input/by-id/usb-Topseed Technology Corp. eHome Infrared Transceiver
The above steps will vary depending on your IR receiver. If you need to reconfigure LIRC to change the settings, open a terminal and run: sudo dpkg-reconfigure lirc
Then I opened a terminal window and tested the IR receiver. First I entered this command:
mode2 -d /dev/lirc0
This allowed me to see how much noise the usb receiver was accidentally picking up. Turning the lights off seemed to reduce this a bit for me.
Then I opened a terminal window and ran this command:
This provides a list of the names for various buttons that LIRC can recognize. You will be asked by LIRC to assign a name to every button on your remote; you may need to fudge things a bit to come up with matching names for some buttons.
Then I placed the first remote control I wanted to record in front of the receiver and ran this command:
irrecord -d /dev/lirc0 /home/username/Desktop/test-remote.conf
(You will need to change username to match your username.) Follow the resulting directions carefully. I needed to run through them several times because I made small mistakes. If you don’t push buttons fast enough, LIRC will produce a file in RAW mode. This was not good for my purposes, as I needed LIRC to convert the files into hex mode in order to get them working with Rcoid. If you follow the directions properly, LIRC should be able to give you a working hex configuration file. (If the configuration file is in RAW format, it will say RAW in the “flags” section. By contrast, the files LIRC created when I correctly followed its instructions read “SPACE_ENC” in the “flags” section.)
After LIRC finishes and creates a configuration file for your remote, open the file and take note of the information in the following rows:
-pre_data_bits (may be missing)
-pre_data (may be missing)
-the hex codes for the specific buttons you want to add to your Rcoid remote.
This will be the information Rcoid will need.
Next, install Rcoid to your Android phone. You can get it here. Here is a German language video that explains how to import an LIRC configuration files into Rcoid. You will be able to understand the video even if you do not understand German.
Here is how I built a custom remote in Rcoid:
1) Open Rcoid and select Menu and then create a new remote control.
2) Add and arrange the buttons (“Elements”) as you would like them to appear in the remote: just press on the grid and select “Add Element”.
3) Save the remote control: Menu: Finish edit: Save
4) Select: Menu: Edit Remote Control
5) Select a button you would like to add an IR command for: this will call up the Element menu
6) Select: Switch: On
7) Select: Generate
8) Select LIRC-Converter
9) The following are the Rcoid settings you will need to enter; the numbers you will plug into these boxes come from your LIRC configuration file. You can ignore the other settings:
-Const Length: check if the “flag” row says “CONST_LENGTH”
-Header: look at “header” row in the LIRC file: a) flip header to yes; b) enter the left in the “On” box; c) enter the right number in the “Off” box
-Logic one: look at the “one” row in the LIRC file: a) enter the first number in the “On” box and the second in the “Off” box
-Logic zero: look at the “zero” row in the LIRC file: again the first number goes in the “On” box and the second in the “Off” box
-Ptrail: select “Yes” and enter the number the number from the ptrail row in the LIRC file
-Pre-Data: Select “Yes” or “No” depending on whether your LIRC configuration file includes the rows “pre_data_bits” and “pre_data.” If it does, enter the bits number in the Bits box and in the 0x box to the right, enter the information in the LIRC pre_data row that follows the 0x. (You do not copy the “0x” from the LIRC file.)
-Data: Find the “bits” column near the top of the LIRC file and enter that number here. Then in the 0x box, enter the alpha-numeric digits following the 0x for the specific Remote Control button you wish to add. (This will be for one of the button codes that follow the “begin codes” section of the file.)
10) Select Back and then Insert and then Back again
11) Select “Finish Edit” and Save
12) Test the Rcoid button out to make sure that it works
13) Repeat for each button on your Rcoid remote
After you are finished, you should have an .rcf file for your remote saved in your Rcoid folder on your Android phone. I would recommend backing this file up to a different device in case you need to replace your phone.