Introduction: AIY Universal IR Remote Control

This instrucatable describes how to make an AIY universal infrared remote control. This can be used to control any TV, soundbar, digibox, dvd or bluray player by using your voice.

I call it universal as it contains an IR receiver which can be used to record the infrared signal from any remote control.

The AIY project uses the LIRC program to record and transmit the IR signal.

Step 1: Make PCB

Parts list:

Two 940nm 5mm infrared LED emitters

One TSOP38238 infrared receiver

One 2n3904 transistor

One 10 ohm resistor

One veroboard

Four Single Connectors (Optional - I cut a six pin connector into single connectors)

Cables to connect to the AIY hat.

Ensure that the IR LED's have the long leg on the first row, and short leg on second. Second LED with long leg on second row, and short leg on third.

The transistor should have the base on the third, the collector on the fourth, and the emitter on the fifth. Ensure that the flat side of the resistor is facing the connector.

The resistor goes between row five and row eight.

Use a short piece of wire to connect row one to row seven.

Connect the IR receiver onto row seven, eight and nine.

Add the connectors to rows one, four, eight and nine.

Connectors are:

Row one - +5v power

Row four - transmitter signal

Row eight - Ground

Row nine - receiver signal

Step 2: Connect to the AIY Hat

I have soldered header pins onto my AIY to make connecting things much easier.

The pins I used are Servo 0 (GPIO 26) and Servo 5 (GPIO 24) for the signal. I also used +5v from the horizontal pin out above the Servo pins. I took the ground from the GND next to Servo 0, but you can use any ground you want.

Using the appropriate cables, I connected the AIY hat to the board like this:

+5V to row one

Servo 0 (GPIO 26) to row four

GND to row 8

Servo 5 (GPIO 24) to row nine.

Step 3: Install LIRC

Assuming that you have already set up and tested AIY: https://aiyprojects.withgoogle.com/

We need to install LIRC. Follow this valuable instructable by mirza irwan Osman:

https://www.instructables.com/id/Install-Linux-Infrared-Remote-Control-LIRC-Package

OR an alternative instruction can be found here by Alex Bane:

http://alexba.in/blog/2013/01/06/setting-up-lirc-on-the-raspberrypi/

NOTE: for my setup I needed to ensure that /boot/config.txt file had the following:

dtoverlay=lirc-rpi,gpio_in_pin=24,gpio_out_pin=26



Step 4: Get or Make LIRC Files for Your Devices

This next step creates the lircd.conf file which contains the details about the remote control for the devices you want to use.

There are two ways to make this file:

1. If you are lucky, you can find an existing file on the LIRC pages for your device

2. If you cannot find it, then you will need to record a file using the IR receiver and your remote control.

For step 1, go to the LIRC home page and look through the list of supported devices:

http://www.lirc.org/

If you can find the file for the device, then you need to transfer the information in the file into the lircd.conf file /etc/lirc

As my AIY is headerless, I use WINScP to make the changes to lirc.conf.

The information you need starts with "begin remote" and ends with "end remote"

NOTE: If you want to control more than one device, then simply add the additional remote code into the same file after the existing "end remote". Ensure that each remote has a unique name. I use "mytv" for my television, and "sky" for my sky digibox etc.

If you cannot find the code for your device, then you will need to record it.

Follow this instructable to learn how to record each remote control using LIRC:

https://www.instructables.com/id/Record-Infrared-Codes-of-Any-Remote-Control-Unit-f/

Once you have recorded the first remote control, repeat the process until you have all the remotes recorded. You can then update the lirc.conf file with all the codes you recorded. I needed to do this for my soundbar.

Step 5: Code AIY to Control Your Devices

To control the IR transmitter from AIY, make the necessary changes to the file "assistant_library_with_local_commands_demo.py"

You can run "assistant_library_with_local_commands_demo.py" from the Start Dev Terminal in order to see if your code is working.

I have my AIY start automatically on boot up by following the instruction here:

https://aiyprojects.withgoogle.com/voice/#makers-guide-3-4--run-your-app-automatically

Be aware that if you want to change your code, then you need to stop AIY running, and then start it again by using these:

sudo service my_assistant stop

sudo service my_assistant start

The attached code contains my current working program.

(Note that this code also contains additional features such as internet radio).

The code makes use of variations on sending the LIRC send_start and send_stop to transmit the required IR signal. I have found that it is necessary to introduce a pause between starting and stopping the signal, and this can vary between devices (my Panasonic TV requires a longer signal than the sky box). So for example:

subprocess.call('irsend SEND_START mytv KEY_POWER', shell=True)

time.sleep(0.5)

subprocess.call('irsend SEND_STOP mytv KEY_POWER', shell=True)

To send combinations of signals, for example the sky TV channel, I created a list which designated a phrase to a channel code. Note that sometime the AIY will not always hear the right word, so I have also included variations on the phrase (such as bbc 1 and bbc one, or the word 'guide' as well as 'dave' as AIY always returned that when I said 'dave' - it must be my accent!). I then used a routine which would pick up the three character code from the list and transmit each number (see module ##Sky channel change routine##)

It is also possible to send combinations of signals to several devices. So for example I have a "system on" routine which sends power on to the TV, power on to the soundbar, starts the sky box and switches it to BBC 1.

Once the IR transmitter is working with AIY, it is possible to think up all different combinations to use it. For example I can send a time command to adjust the volume on the sound bar.

Happy AIY IR remote controlling!