In the previous article, we successfully flashed the Raspberry Pi 5 into an Android TV box, and the basic functions are already complete. This article will introduce how to use a remote control to operate the Android TV.
-
• “I Want to Watch TV – Projector and TV Box Selection”
-
• “I Want to Watch TV – Transforming Raspberry Pi 5 into an Android TV Box: Part 1”
The Raspberry Pi is designed to be used as a small computer, but as a TV box, it must have the functionality to be controlled by a remote control. There are various ways to control the Raspberry Pi with a remote control, and I will list some of the methods I have tried.
Using a Mobile Phone to Control Android TV
This is the simplest and lowest-cost pure software solution. You just need to install software on your phone to control the Android TV, as long as the phone and Android TV are on the same local area network. I used the app Remote TV
, which is free but has ads.

The functionality is complete, including the ability to turn the Android TV on and off. However, the operation of Android TV does not actually turn it off; it runs in low power mode and remains connected to the network. This means you can actually turn it on through the app. The inconvenience lies in the fact that each operation requires you to pick up your phone and open the app first, which is not as convenient as having a hardware remote control.
Using the Projector’s Remote Control
I used an Epson TZ2800 projector as the playback device, and the projector’s HDMI supports HDMI CEC functionality. Here, I want to complain about the traditional company Epson, as it is very difficult to find information on whether this projector supports CEC on the official product page[1]; it might exist somewhere, but I couldn’t find it.
HDMI CEC (Consumer Electronics Control) functionality allows multiple devices to control each other through HDMI connections, enabling the same remote control to operate both the projector and the Android TV:
-
1. When the projector is turned off, the Android TV can also be turned off.
-
2. When the projector is turned on, the Android TV can be turned on.
To use HDMI CEC functionality, you need to enable the relevant features in the Android TV system.

The following interface is used to select the HDMI CEC support interface, which can only support one HDMI interface.

Since I share a remote control with the projector, there are still some functional limitations. For example, the volume control can only operate the projector, not the Android TV’s volume. However, most functions are already available.
Using a Bluetooth Remote Control
Coincidentally, I have a TV box remote control that was given away with a mobile broadband plan, and this remote control is a Bluetooth remote. The pairing method is conveniently located on the back of the remote control.

Open the Android TV system and go to Settings
-> System
-> Remote and Gamepads
. Press and hold the menu and back buttons to pair via Bluetooth.

After successful Bluetooth pairing, the functionality works normally during use. However, I found a fatal flaw: the Bluetooth connection drops automatically and cannot reconnect automatically, requiring re-pairing each time. I’m not sure if this is a remote control issue, but this alone has ruled out my Bluetooth remote control solution.
Enabling Remote Control for Raspberry Pi Devices
The Raspberry Pi provides powerful expandability through its 24 GPIO pins, allowing external hardware devices to receive signals from the remote control. Let’s understand the common principles of remote control:
-
1. Infrared Remote Control: The most common type of remote control, which emits signals using infrared light. The receiving end requires a corresponding infrared receiver module and must be aimed at the receiver when emitting signals.
-
2. Wireless Remote Control: Usually uses the 2.4 GHz wireless band as the transmission medium. The receiving end needs to have a compatible device to receive signals, such as many wireless mice that provide a small USB receiver.
-
3. Bluetooth Remote Control: Communicates using Bluetooth technology, which also uses the 2.4 GHz wireless band. The advantage is that many devices support Bluetooth protocol, eliminating the need for a dedicated hardware receiver.
Receiving Infrared Signals
I happen to have a few discarded infrared remote controls at home, so they can be used as remote controls for the Raspberry Pi. The first step is to have the Raspberry Pi receive infrared signals through the GPIO pins. I bought an infrared receiver and Dupont wires (to connect the infrared receiver and GPIO pins) for a few bucks on the versatile Taobao. Make sure the Dupont wires are of the female-to-female type.


Connecting the Infrared Receiver to the Raspberry Pi
By default, the GPIO pins on the Raspberry Pi are not enabled. Go to the Android TV system and navigate to Raspberry Pi settings
-> IR
-> Infrared remote
switch. You can see that the receiving signal is on GPIO pin 18.

The infrared receiver has three pins: OUT (output signal), GND (ground signal), and VCC (operating voltage), where the OUT pin of the infrared receiver corresponds to GPIO pin 18.

The Raspberry Pi provides two operating voltages: 3.3V and 5V. The working voltage of the infrared signal receiver is between 2.7V and 5.5V, so I directly used the 5V pin of the GPIO.

Check the pinout diagram for the Raspberry Pi:

We can get the corresponding relationship between the infrared signal receiver and the GPIO pins:
Infrared Signal Receiver Pin | GPIO Pin |
OUT | 18 |
GND | 9 (nearest principle) |
VCC | 2 (4 and 6 are occupied by the fan power) |
After connecting the hardware, you can start the Raspberry Pi.
Remote Control Code Pairing
There may be multiple infrared remote controls at home, so why don’t they conflict with each other? Why can’t I turn on the TV and accidentally turn on the air conditioner? The reason is that each button on the infrared remote control corresponds to a code, and the codes for different devices’ remote controls are different. Even if the TV remote sends a power-on signal, the air conditioner will receive it but will not process the code for that button, so it won’t turn on. I randomly found an infrared remote control at home, but it cannot be used to control the Android TV directly, so I need to make the Android TV recognize the key codes corresponding to my infrared remote control. To recognize the infrared remote control codes, we need to use the command line tool ir-keytable
in the Android TV system, and we need to connect to the Android TV via SSH. The connection method for the Android TV can refer to the SSH section in my previous article “I Want to Watch TV – Transforming Raspberry Pi 5 into an Android TV Box: Part 1”.
Execute ir-keytable -p all -t
in the command line and press the button on the remote control. The output will look similar to the following:
991.988018: lirc protocol(necx): scancode = 0x835590
991.988023: event type EV_MSC(0x04): scancode = 0x835590
991.988023: event type EV_SYN(0x00).
992.104019: lirc protocol(necx): scancode = 0x835590
992.104025: event type EV_MSC(0x04): scancode = 0x835590
992.104025: event type EV_SYN(0x00).
The timestamp 916.968014 indicates when the event occurred. The “necx” indicates that the NEC extended protocol is used, which is a common infrared coding protocol. The “scancode” field is what we need to obtain the key code. “EV_SYN” indicates the end of a group of events. In the above command, pressing a button on the remote control sends out two identical signals, resulting in two identical log blocks being printed.
Open the GitHub project: https://github.com/lineage-rpi/android_external_ir-keytable/tree/lineage-18.1/rc_keymaps, where you can see many mappings between codes and corresponding keys. Since my infrared remote control does not have numeric keys, I selected a file that resembles the remote control keys, modified the corresponding codes, and saved it to a local file named rc_keymap.txt. My file looks like this, where I did not modify the KEY_PREVIOUSSONG and KEY_PLAYPAUSE buttons as they are not on my remote:
# table allwinner_ba10_tv_box, type: NEC
0x646dca KEY_UP
0x646d81 KEY_VOLUMEDOWN
0x217 KEY_NEXTSONG
0x646ddc KEY_POWER
0x646dc5 KEY_BACK
0x646dce KEY_OK
0x646dd2 KEY_DOWN
0x646d80 KEY_VOLUMEUP
0x254 KEY_PREVIOUSSONG
0x255 KEY_PLAYPAUSE
0x646d82 KEY_MENU
0x646d88 KEY_HOMEPAGE
0x646dc1 KEY_RIGHT
0x646d99 KEY_LEFT
It should be noted that the first line looks like a comment, but it is not; do not delete it, and keep the original file format unchanged.
Loading Configuration When Android TV Boots
After obtaining the mapping relationship between the remote control buttons and codes, we need to place it in the /boot/rc_keymap.txt
file of the Android TV system to enable it to automatically load this configuration at boot. This file does not exist by default and needs to be created.
The /boot partition is read-only by default and does not allow adding files:
127|:/boot # echo "123" > aa
sh: can't create aa: Read-only file system
Remount the /boot directory as read-write:
$ mount | grep '/boot '
/dev/block/mmcblk0p1 on /boot type vfat (ro,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
$ mount -o remount,rw /boot
$ mount | grep '/boot '
/dev/block/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
Create and write the configuration to the /boot/rc_keymap.txt file:
cat << EOF > /boot/rc_keymap.txt
# table allwinner_ba10_tv_box, type: NEC
0x646dca KEY_UP
0x646d81 KEY_VOLUMEDOWN
0x217 KEY_NEXTSONG
0x646ddc KEY_POWER
0x646dc5 KEY_BACK
0x646dce KEY_OK
0x646dd2 KEY_DOWN
0x646d80 KEY_VOLUMEUP
0x254 KEY_PREVIOUSSONG
0x255 KEY_PLAYPAUSE
0x646d82 KEY_MENU
0x646d88 KEY_HOMEPAGE
0x646dc1 KEY_RIGHT
0x646d99 KEY_LEFT
EOF
Remount the /boot partition as read-only:
mount -o remount,ro /boot
After completing these steps, restart the system. If successful, you will be able to directly control the Android TV system using the infrared remote control.
Conclusion
So far, I primarily use the infrared remote control mode, as a TV box should have its own remote control. Good Luck!
Reference Links
[1]
Official product page: https://www.epson.com.cn/Apps/tech_support/SupportProduct.aspx?p=32158