Reusing my old phone as a universal remote

By chimo on (updated on )

Over the years, I’ve ended up with a bunch of small infrared remotes for various things. I also had an old1 Samsung Galaxy S5, which has an infrared transmitter, sitting in a storage bin in the basement. I decided to look into consolidating the various IR remotes into virtual remotes via the Android phone.

Capturing the IR signals

Hardware

Some years ago, I bought a TSOP38238 IR receiver to use with my raspberrypi. I don’t remember why I got this back then, but that’s what I used to capture the IR signals from the remotes this time around.

I hooked up the IR receiver pins (left) to the raspberrypy’s pins (right) as follows:

  • Pin 1 -> Pin 18 (Out/GPIO)
  • Pin 2 -> Pin 6 (Ground/Ground)
  • Pin 3 -> Pin 1 (VS/3V3 Power)

See: “GPIO and the 40-pin header”.

Software

Install lirc and dtoverlay:

# apk add lirc raspberrypi-utils-dtmerge

Load overlay:

# dtoverlay gpio-ir,gpio_pin=18

At this point, you should see a device named lirc0 in /dev/

Run mode2:

$ mode2 --driver default --device /dev/lirc0

Press a button on an infrared remote. You should see some output like:

pulse <number>
space <number>

timeout

For my purposes, I wanted to save the output to a file, so I piped the output to tee:

$ mode2 --driver default -d /dev/lirc0 | tee out.txt

Then pressed all the buttons on my remote one by one. Once done, hit Ctrl+C to exit.

Now, we want to only keep the numbers as space-separated list for each button. The following one-liner does the trick, but I’m sure there are better options out there:

sed -E 's/timeout [0-9]+//g' ./out.txt |     # Replace "timeout" lines with blank lines
    cut -d ' ' -f2 |                         # Only keep numbers
    sed -r ':a; N ;s/(.+)\n(.+)/\1 \2/; ta'  # Remove all newlines except on blank lines

Android

  1. Install IR-Blaster.
  2. Create a remote.
  3. Create buttons using the decimal values captured.
  4. Use your phone as a remote!

[1] My SGS5 runs LineageOS 18.1, the latest version available for this model. That version isn’t supported anymore. As such, I don’t connect this device to the internet. In fact, since it’s only used as a IR remote, both Wifi and Bluetooth are turned-off. ^