Introduction: Raspberry Pi Zero Universal Remote
Build a universal remote control with web interface using a Raspberry Pi, LIRC, and just a few components. I needed one because the remote in my house tends to go missing a lot. My mother-in-law's remote for her cable box broke and I don't know why she doesn't just go get the free replacement so she grabs the one in our living room and sometimes doesn't return it. Also, my kids would misplace the controller from time to time. So if I want the controller, I have to hunt down 3 people and hope one of them remembers that they took the remote.
Another bonus to building the remote to control the TV, cable box, and dvd player, I realized that I can control our living room tower fan since it too has an IR remote control. If the device has an IR receiver, you can control it with this universal remote.
This Instructable entails a bit of hardware and software but is well worth it in the end not having to hunt down a controller and just control everything from your computer or phone's browser.
Change Log:
3/02/2018: Corrected GPIO references as pointed out by Paul Hickey.
1/27/2018: Added macro capability. Corrected default Raspbian password as pointed out by MattH324.
1/13/2018: Added power supply and USB cable to BOM as suggested by jrullo.
1/12/2018: Changed R3 power rating from 1/2W to 1/4W as suggested by B MW.
1/07/2018: Initial publish
Step 1: BOM
Bill of Materials
- Raspberry Pi Zero W
- 5V Power Supply (1.2A minimum)
- Micro USB Cable
- Micro SD Card
- IR LED 5mm (940nm) - TSAL6200
- IR Receiver Module (3.3V type) - TSOP38238
- 2N2222 NPN transistor
- 36 Ohm 1/4W Resistor
- 680 Ohm 1/4W Resistor
- 10K Ohm 1/4W Resistor
- Perfboard
- 4-40 3/8" countersunk screws (if using the case I modeled)
- Wire (stranded 24AWG works well)
Tools
- Computer
- SD card reader
- Soldering Iron and solder
- Hot glue gun and hot glue (or super glue)
- Wire cutter
- Wire stripper
- Screw driver
- 4-40 bottom tap
- Helping hands or some sort of hobby vise
- 3D printer (not necessary but you can print up a case)
Notes
You will need a minimum size of 4GB micro SD according to the Raspberry Pi foundation documentation. I would just get a 16GB or 32GB because seems like 4GB and 8GB are hard to come by now and tend to cost more. Also the larger capacity allows you to multipurpose the Pi as a small file share, but that is beyond the scope of the Instructable, but something to consider after you complete the remote.
Make sure the IR LED is specified for wavelength of 940nm and get them from a reputable seller. I bought some cheapy ones off eBay and they only work when close to the television, like about 5-6 feet away. I ended up using a TSAL6200 IR LED from DigiKey which can control the television from the very back of my living room (15+ feet).
Make sure to us an IR Receiver Module that operates at 3.3V like a TSOP38238. This simplifies connecting the module to the Pi so you do not have to level shift the module's output down to 3.3V. I initially had a TSOP4838 that the datasheet says it operates from 2.5V to 5.5V, but I could only get it to work with 5V. That could also be the problem of going cheap off eBay. So yeah, save yourself some trouble of not having to add extra parts to convert the 5V output from the receiver down to 3.3V and just get a TSOP38238.
Buy components from a seller like DigiKey. As noted twice, I got bad components going cheap off eBay. I'm not saying all eBay sellers are bad, I'm just saying don't be surprised if you don't get exactly what you ordered. Save time and headache and buy from Adafruit, DigiKey, Mouser, etc. The bay is still good in my opinion if you keep track of good seller. Also ordering passive components such as resistors and capacitors through eBay are pretty safe.
Almost any jelly bean NPN transistor can be used as long as the transistor can handle a minimum of 150 or so milliamps. I happen to have a lot of 2N2222 transistors laying around so I just used that.
Step 2: Raspbian Install & Setup YMMV
Download Raspbian Lite from https://www.raspberrypi.org/downloads/raspbian/. Do not grab the desktop as you do not need the desktop. We will not be using the GUI. As of writing this, the latest Raspbian Lite image is 2017-11-29.
Follow their instructions on how to install Raspbian to your SD Card.
The Raspberry Pi Organization suggests using Etcher but it doesn't always works for me. I get validation errors. I think it has something to do with Windows 10 because when I use Linux (same machine, just swapped out the hard drives), Etcher works all the time.
Your mileage may vary on setting up Wi-Fi for the Pi Zero W. My router is a bit funky in that it will not allow computers to connect to other computers unless they have an assigned IP. So if you find that you cannot connect to your Pi, assign it a static IP.
After you flash the Raspian image to your SD card. Eject and reinsert your SD card into your computer. Create a text file named "wpa_supplicant.conf" and place in the /boot folder of the SD card. The following are contents of the wpa_supplicant.conf file (change country, ssid, psk, key_mgmt to your values):
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 country=US network={ ssid="Your Wi-Fi SSID" psk="Your Wi-Fi password" key_mgmt=WPA-PSK }
Add a blank file named SSH to the /boot folder of the SD card. This will enable SSH as SSH is disabled by default now.
Hook up the Pi's power source to boot up the Pi. The wpa_supplicant.conf is automatically moved to /etc/wpa_supplicant/ if you ever need to edit the settings.
Test that you can connect to your Pi via SSH. The default user is "pi" with password "raspberry".
In my case, I had to hook up the Pi to a monitor and run ifconfig to get the MAC address of the Pi's Wi-Fi adapter so that I can assign a static IP to that MAC address.
If you can connect, great! First thing to do is change password. Then get the latest updates by the running the following two commands (don't copy the '$' sign, it denotes the terminal prompt):
$ sudo apt-get update $ sudo apt-get upgrade
Leave the SD card in the Pi and set aside the Pi for now while you work on the case and IR LED driver circuit.
Step 3: Enclosure
I modeled a case to hold the Pi Zero W, the IR LED driver circuit, IR LED and IR receiver module. You can download the model at https://www.thingiverse.com/thing:2742325. Having the case up front is handy so you can have the remote nicely boxed up while you configure LIRC.
If you do not have a 3d printer, try to find an enclosure that can fit the length of the Pi and width of the Pi plus the IR LED driver circuit (4 x 6 perfboard). An Altoid mint tin might do. Just make sure you insulate the inside so you don't short anything.
If you print up my enclosure, use a 4-40 bottom tap to cut screw threads in the corner screw holes. Make sure to use a bottom tap so you can get threads cut almost all the way to the bottom of the screw hole.
If you only have a regular tap, then you will need to drill out the holes all the way (or modify the model).
Step 4: IR LED Driver
The TSAL6200 IR LED can continuously handle 100mA of current. The max current you should pull from a Raspberry Pi GPIO pin is 16mA and no more than 51mA total from all pins (Raspberry Pi GPIO pin max current). We should not directly power the IR LED from a GPIO as 16mA may be to weak for the IR LED to be useful. We instead need to use a simple transistor amplifying circuit.
Follow the schematic to create the circuit to connect the IR LED to the Raspberry Pi. Not shown in the schematic is hooking up the IR LED to the 5V power pin. This will be shown in the upcoming steps and mentioned below as part of the calculations. The following steps detail putting the components on a perfboard.
If you are wondering about how I chose the resistor values, read on. If you just trust me and want to get on with the project, go to the next step.
R1 is a pull-down resistor to ensure the IR LED is off when the Raspberry Pi is in an unknown state. The value is a rule of thumb where 10K is good enough. This resistor is probably not needed since TV/DVD/etc. receivers receive encoded IR signals and the chances that your IR sends a valid signal when the Pi is off or booting to one of the devices are pretty slim. I personally leave the pull-down resistor because best practice is to always start/end in a known state.
R2 is the base current limiting resistor. You need to calculate the value of this resistor according to the transistor you use. The 2N2222 datasheet has a DC current gain from 35 to 100 depending on how much current and voltage you are using. I just went with worst case and used a gain of 35 for my calculation. I want the transistor base current to allow more than 100mA to flow from the collector to the emitter of the transistor. To calculate the base current we need to divide the desired current by the DC current gain, 100mA / 35 = 2.9mA. I rounded up to 4mA for some leeway which will allow up to 140mA to flow.
The GPIO pins output 3.3V. We also have to take into consideration the voltage drop from the base to emitter of the transistor. The voltage base emitter drop is 0.6V according to the datasheet. So to calculate the resistor required to limit the GPIO current to 4mA, use Ohm's law V / I = R, (3.3V - 0.6V) / 4mA = 675 Ohms. The nearest E24 resistor value is 680 Ohm (using this value rounds to 4mA).
We need to check what power rating to use for R2. Power formula is P = V * I. The power that R2 needs to dissipate is (3.3V - 0.6V) * 4mA = 0.011 Watts. I went with 1/4 Watt because that's the smallest wattage resistors my local electronics store carry.
R3 limits the current passing through the IR LED. The LED will be powered from the 5V GPIO pin which is directly connected to the USB 5V power. This means the max current you can draw from the 5V pin is the max the power supply supports minus the current the Pi draws.
The forward voltage of the TSAL6200 is 1.35V and there is a tiny 0.3V voltage drop across the transistor from collector to emitter (according to their respective datasheets). The value for R3 is then (5V - 1.35V - 0.3V) / 100mA = 33.5 Ohms. The nearest E24 value is 36 Ohms, which calculate to 93mA, which is still good enough for our purposes.
Finally we need to check how much power R3 needs to dissipate. Power formula, P = VI, calculates to (5V - 1.35V - 0.3V) * 93mA = 0.312 Watts. That means we need a 1/2 W resistor for R3. Well not quite. Thanks to B MW for pointing out that 0.312W is the instantaneous power usage and really only a concern if you are continuously powering the LED. IR codes are really short (usually in the milliseconds) sets of ~38KHz pulses. So you are not continuously powering the led. You can use a 1/4 Watt resistor for R3 instead of a 1/2 Watt resistor.
Step 5: Building the LED Circuit - R1
You will need to cut a perfboard to 4 x 6. I arrange the perfboard with 4 holes vertically and 6 holes horizontally (4 rows by 6 columns).
Start with R1, 10K Ohm resistor, and place it into the lower leftmost corner (bottom row, first column) of the perfboard with the leads spaced apart so there is two empty holes between them.
Bend the lead in the leftmost corner vertically and the opposite leg horizontally. We will use the legs as a trace to connect to the other components.
Step 6: Building the LED Circuit - R2
Insert R2, 680 Ohm resistor into the row above the R1 resistor.
Bend leftmost leg horizontally outward from the board and the other leg horizontally like how you did for R1.
Step 7: Building the LED Circuit - Q1
Insert the transistor Q1 to the right of R1 and R2 (bottom 3 rows of the 5th column)
Make sure Q1's emitter lead is through the bottom hole that is in line with R1.
Q1's base lead needs to go through the row that connects to R2.
Bend the emitter leg downward away from the board and the collector upward to hold Q1 in place.
Step 8: Building the LED Circuit - Solder First Set of Components
Now is a good time to solder some of the leads to hold the parts in place.
Solder Q1's base to the board which connects it to R2.
Solder Q1's emitter to the board which connects it to R1.
Solder R2's leftmost leg to the board connecting it to R1.
Trim the Q1 leads and R2 lead that were soldered.
Trim R1's lead one row up from the connection to R2. This will connect to a wire to the GPIO 22 pin of the Pi.
Trim R1's lead one column to the right from the connection to the Q1's emitter. This will connect to a wire to a ground pin on the Pi.
Trim Q1's collector lead one row up. This will connect to R3.
Step 9: Soldering IR LED Circuit - R3
Place R3, 36 Ohm resistor, in the topmost row all with the first lead in the first column and the other lead in the last column. The resistor should span the whole board.
Bend the leftmost leg horizontally inward toward the board. Trim the lead when it intersects Q1's collector lead at the 5th column. Solder the connection of R3 and Q1 together.
Bend the rightmost leg down and trim one row down. This will connect to the cathode of the IR LED.
Step 10: Building the LED Circuit - Wire Leads
Use colored wire to differentiate which wire connects to what. I used yellow for signal from the Pi, white for the IR LED cathode, and black as ground. Use lengths of about 3 to 4 inches so that you have some wiggle room when wiring up the board to the Pi in the case.
Strip and tin one end of the wires.
Insert the tinned end into the perfboard at their respective hole and solder in place.
Yellow wire in the 2nd row left most column.
White wire to 2nd row rightmost column.
Black wire bottom row rightmost column.
Make sure you trim any excess.
Step 11: Component Test Fit
Layout your components to somewhat match the case layout. The holes of the case are self-explanatory.
The top of the Pi should be facing the top of the case. The HDMI and usb ports will line up with the case cutouts.
Place the IR LED and IR receiver module in their respective holes.
Step 12: Trim LED Driver Wires to Length
Now you know how far the circuit board will be from the Pi you can cut the wires to length.
I removed the components from the case to easier work with the two. Space the Pi and LED driver circuit to how they would be in the case.
Leave a bit of length of the wire so that you can move the circuit board around if needed, but not leave too much wire where it takes up too much space. I made the wires do like a 'U' turn to the GPIO they are connected to instead of straight shot from the board to the Pi. This way you have some wiggle room.
Step 13: Solder Ground Wire
Trim the end of the wires and tin the ends.
Start with the black ground wire and poke the end through pin 6 (ground). Make sure you go from the top of the Pi board so that you are soldering the end of the wire on the back of the board.
Solder into place.
Note: I say pin but its really a hole since there are no preinstalled headers on a regular Pi Zero.
Step 14: Solder IR Signal Wire
Take the yellow signal wire and place through pin 15 (GPIO 22). Make sure to go from the top of the Pi like how you did for the ground wire.
Solder into place.
Place the board in the case to test fit to make sure your wires are not too long that they interfere with the other components. If they are, trim off some excess.
Step 15: Cut More Wires to Length
Cut 4 more wires for connecting the components together. Cut the wires to about the same length as you did for the ground and signal.
Use different colors of wire to easily differentiate what they connect to it.
Colors I used are:
- Orange - 3.3V
- Red - 5V
- Black - Ground
- Green - IR receiver signal
Trim the ends and tin.
Step 16: Solder Wires Into Place
Solder the orange wire to pin 1 (3.3V) of the GPIO header. Go from the top down so that you are soldering the wire from the back.
Solder the red wire to pin 2 (5V).
Solder the black wire to pin 14 (ground).
Solder the green wire to pin 16 (GPIO 23).
Step 17: Trim IR Component Leads
Place the IR components into their respective openings.
Bend the IR LED legs toward where the driver board will go.
Bend the legs of the IR receiver module up and then bend again toward the IR LED.
Trim the leads short like show in the picture.
Step 18: Glue IR Components
Glue the IR LED and IR receiver module to hold them in place. Use a good amount glue so the components do not move when you place the Pi and driver circuit wires in.
You can either use hot glue or super glue. I just went with hot glue because my little tube of super glue dried up.
Step 19: Tin IR Component Leads
Tin the ends of the leads of the IR LED and IR receiver module. This will make connecting wires easier in the upcoming steps.
Trim the cathode of the IR LED a tad bit shorter so that you can easily identify the cathode lead. There is a cutaway on the LED to tell you which is the anode or cathode but that cutaway may be covered by the hot glue so easier to just shorten up a lead.
Step 20: Test Fit
Test fit the Pi and LED driver board.
Make sure your wires are the right length, not too long and not too short, but just right.
Step 21: Solder IR Wires
Remove the Pi and driver circuit from the case.
Strip the end of the wires and tin them.
Solder the wires to the correct leads.
- Red wire - IR LED anode
- White wire - IR LED Cathode
- Orange wire - IR receiver module lead 3
- Black Wire - IR receiver module lead 2
- Green Wire - IR receiver module lead 1
Use the picture of the pinout for the TSOP38238 to help solder the correct wires to the correct leads.
Eyeball your solder joints on the Pi to make sure they are not shorting to other pins.
Step 22: Screw Enclosure Cover
Make sure the SD card is still in the Pi before you screw on the back of the enclosure.
Place the back cover on the case.
Use four 4-40 countersunk screws on the corners of the case. Make sure you tapped the screw holes to prevent the plastic from splitting. Also, do not overtighten where you strip out the threads.
Slap some decals and labels on to pretty up the enclose and help you tell which micro USB port is the power port.
Step 23: LIRC Install
Power up the Pi and SSH into it.
Enter the following in the terminal to download and install LIRC. Answer 'Yes' to any questions when prompted. Note: Do not copy the '$' sign as that denotes the terminal prompt. This is to help differentiate what is a command and what are contents of a file.
$ sudo apt-get install lirc
Next we need to add two lines to '/etc/modules', but first make a backup of the modules file.
$ cd /etc/ $ sudo cp modules modules.bak
Then using your favorite Linux editor of choice (nano, vim, or even emacs), add the follow two lines to the bottom of the /etc/modules file.
lirc_dev lirc_rpi gpio_in_pin=23 gpio_out_pin=22
We also need to update boot configuration file 'boot/config.txt'. As we did for modules, we should make a back up first.
$ cd /boot $ sudo cp config.txt config.txt.bak
Then change line 51 of config.txt from
#dtoverlay=lirc-rpi
to
dtoverlay=lirc-rpi,gpio_in_pin=23,gpio_out_pin=22
A fresh install of LIRC does not contain a hardware configuration file so you have to create it. User your editor of choice and create the file '/etc/lirc/hardware.conf' with the following contents:
######################################################## # /etc/lirc/hardware.conf # # Arguments which will be used when launching lircd LIRCD_ARGS="--uinput" # Don't start lircmd even if there seems to be a good config file # START_LIRCMD=false # Don't start irexec, even if a good config file seems to exist. # START_IREXEC=false # Try to load appropriate kernel modules LOAD_MODULES=true # Run "lircd --driver=help" for a list of supported drivers. DRIVER="default" # usually /dev/lirc0 is the correct setting for systems using udev DEVICE="/dev/lirc0" MODULES="lirc_rpi" # Default configuration files for your hardware if any LIRCD_CONF="" LIRCMD_CONF="" ########################################################
Next we need to update the '/etc/lirc/lirc_options.conf' file, but as always, make a backup first just incase.
$ cd /etc/lirc $ sudo cp lirc_options.conf lirc_options.conf.bak
Update line 11 of lirc_options.conf from
driver = devinput
to
driver=default
Reboot the Pi by entering the following. You will lose connection so SSH back in when the Pi is done booting up.
$ sudo shutdown -r now
Step 24: LIRC Install Quick Test
After the Pi has rebooted and you have SSH'ed back in from the previous step, we can quickly test if LIRC was installed correctly and if you connected your LED driver circuit correctly.
You will need to download a valid remote configuration file to correctly test installation and hookup. Run the following to download a remote configuration file into the LIRC configuration directory, '/etc/lirc/lircd.conf.d/'. Note, the sudo wget line is one long continuously line.
$ cd /etc/lirc/lircd.conf.d/ $ sudo wget -O test.conf https://sourceforge.net/p/lirc-remotes/code/ci/master/tree/remotes/samsung/00056A.lircd.conf?format=raw
LIRC will load any configuration file with extension '.conf' that is in the '/etc/lirc/lircd.conf.d' directory. The command above downloaded a Samsung remote configuration file and named it test.conf. We need to first restart LIRC to load the newly added configuration file. Ignore the warning about lircd.service can still be activated.
$ sudo systemctl stop lircd $ sudo systemctl start lircd
We will manually send an IR code with the irrsend command. The following tells LIRC to send the power button IR code from the Samsung_00056A remote configuration file.
$ irsend SEND_ONCE Samsung_00056A KEY_POWER
You may be wondering where did the Samsung_00056A come from since we named the configuration file test.conf when we downloaded it. The name comes from the name setting in the test.conf at line 14. Keep this in mind since the name of the file is not necessarily the name of the device.
When you run the command there will be no output. You should just see the next command prompt. If there is an error of some sort, double check to make sure you followed the instructions in the previous step.
Test that your IR LED is correctly connected by using a digital camera. We cannot directly see the IR LED flash unless you are some sort of super human. Use a digital camera such as a smart phone camera and focus on the IR LED. Run the irsend command again and you should see the LED flash.
If the LED did not flash, double check your wiring and driver circuit. If everything is in working order, you may remove the test.conf file since we don't really need it anymore.
Step 25: LIRC Remote Configuration
You should still be SSH'ed into the Pi from the last step. If not, SSH back in.
Use the LIRC irrecord command to start the program that records your remote controller's IR codes. Follow my button naming convention so that the web interface structure I made will seamlessly integrate with LIRC. We need to pass the '--disable-namespace' parameter else we will not be able to name the buttons the way we want to.
$ irrecord --disable-namespace
When you run the command you should get a description of the program.
A proper config file for lircd is maybe the most vital part of this package, so you should invest some time to create a working config file. Although I put a good deal of effort in this program it is often not possible to automatically recognize all features of a remote control. Often short-comings of the receiver hardware make it nearly impossible. If you have problems to create a config file READ THE DOCUMENTATION at https://sf.net/p/lirc-remotes/wiki If there already is a remote control of the same brand available at http://sf.net/p/lirc-remotes you might want to try using such a remote as a template. The config files already contains all parameters of the protocol used by remotes of a certain brand and knowing these parameters makes the job of this program much easier. There are also template files for the most common protocols available. Templates can be downloaded using irdb-get(1). You use a template file by providing the path of the file as a command line parameter. Please take the time to finish the file as described in https://sourceforge.net/p/lirc-remotes/wiki/Checklist/ an send it to <lirc@bartelmus.de> so it can be made available to others. Press RETURN to continue.
Press the return (enter) key. The program tests the ambient light for noise which will take a few seconds. As long as there is not too much noise, the program will then ask for the name of the remote.
Checking for ambient light creating too much disturbances. Please don't press any buttons, just wait a few seconds... No significant noise (received 0 bytes) Enter name of remote (only ascii, no spaces) :
Enter the name of the remote you will record. Keep the name simple because you will be using it later to setup the web interface. For this example, I entered 'LivingRoomTv' and then pressed return.
Using LivingRoomTv.lircd.conf as output filename Now start pressing buttons on your remote control. It is very important that you press many different buttons randomly and hold them down for approximately one second. Each button should generate at least one dot but never more than ten dots of output. Don't stop pressing buttons until two lines of dots (2x80) have been generated. Press RETURN now to start recording.
The program will tell you that your configuration file is named 'name_used.lircd.conf', in this example the file is 'LivingRoomTv.lircd.conf'. The program says to press many differnent buttons randomly and hold down the button for about a second. I think the randomness is not really important but the amount of different buttons you press is.
Point your remote toward the IR receiver module. Press the return key on your keyboard. Start pressing and holding buttons on your remote for about a second. You will see dots appear on screen when you press and hold a button on your remote. If you do not see any dots, check your wiring on the IR receiver module and start the recording process over.
Keep pressing buttons till you get two rows of dots. The program will tell you when to stop. One of my remotes I ended up going three rows for whatever reason. If you run out of buttons to press, just repeat previously pressed buttons.
................................................................................ Got gap (109933 us)} Please keep on pressing buttons like described above. ............................................................................... Please enter the name for the next button (press <ENTER> to finish recording)
Eventually the program will have enough information it needs to decode your remotes IR codes. You will then enter the name of the button you want to record. Prefix all your buttons with 'Key_' as the web interface relies on this prefix. For example, name your buttons KEY_POWER, KEY_SOURCE, KEY_1, KEY_2, etc.
After you enter the button name, press enter. The program will ask you to press and hold your remote button down. If the program was successful, it will ask for another key. Example as follows:
Please enter the name for the next button (press <ENTER> to finish recording) KEY_POWER Now hold down button "KEY_POWER". Please enter the name for the next button (press <ENTER> to finish recording)
Repeat for all your buttons. When you have no more buttons to record, leave the button name blank and press enter.
The program will now check if there are special bits to set. You will need to press just one button, any button, just make sure you use the same button, as fast as you can. Make sure that you are actually pressing the button fast and not holding it down. So when you are ready, press enter and press your button as fast as you can.
Checking for toggle bit mask. Please press an arbitrary button repeatedly as fast as possible. Make sure you keep pressing the SAME button and that you DON'T HOLD the button down!. If you can't see any dots appear, wait a bit between button presses. Press RETURN to continue.
After the program is done checking for special bits, it will tell you that it wrote out the file. In this example the file is 'LivingRoomTv.lircd.conf'.
You will need to copy the newly created configuration file to '/etc/lirc/lircd.conf.d/'.
$ sudo cp LivingRoomTv.lircd.conf /etc/lirc/lircd.conf.d/
Repeat the process above for all other remotes you want to record.
Restart LIRC to load all your new remote configuration files. Ignore the warning when you stop lircd.
$ sudo systemctl stop lircd $ sudo systemctl start lircd
Run the following to make sure your new remotes are loaded into LIRC.
$ irsend LIST '' ''
You should see a list of the remote names you made configuration files for.
Your univeral remote is ready to use by using irsend command. Test by pointing the IR LED towards the device you recorded the remote for. Enter an irsend command and the device should respond as if you pressed the button on the original remote. For example entering the following command will turn on my TV.
$ irsend SEND_ONCE LivingRooomTv POWER_KEY
If your device responds, great! The Pi is a working universal remote. However, using LIRC through the terminal is not really user friendly. In the upcoming steps, we will setup a website to interface with LIRC. This way you can press buttons on a website just as naturally as you would with the original remote.
Step 26: LIRC Web Interface - LircNodeJsWeb
I created a web interface to LIRC using Node.js. The project is found at https://github.com/bbtinkerer/LircNodeJsWeb. The README.md contains instructions for setting up the website on your Raspberry Pi Zero W.
I am not including the instruction here but will give an overview of the project. I will update the README.md as I work on the project fixing bugs/adding features. I do not want to have discrepancies in instructions between the README.md and this instructable. I want the instructions centralized on the GitHub project. As of January 7, 2018, the project is in a good working state to use as a simple remote controller interface.
The project uses Node.js as the backend, Pug as the template engine, and Bootstrap for styling pages.
You do not need to learn Node.js. You just need to follow the directions in the README.md to setup the configuration file. A little knowledge of how JSON works is helpful as the configurations are in JSON format.
You should at least get a little familiar with Pug syntax. Just learn enough to know how to declare objects and block content. You do not need in depth knowledge. Just enough to layout a page with the Pug syntax.
The pages use Bootstrap as the styling engine. You don't have to use Bootstrap, but Bootstrap makes styling for different viewports (computer, tablet, smart phone screens) easy. Just as with Pug, you do not need vast knowledge of Bootstrap, just enough to know how to organize and style objects.
The web interface calls irsend with the ID of any button or clickable object that starts with 'KEY_' for the device the layout is for. That is why we had to prefix our buttons during the LIRC recording. An exception is when the ID of a clickable object begins with 'ALT_' as that is a way to call another device's button from the current device layout. An example is that a cable box doesn't have volume controls but you would like to add the TV volume controls to the cable box layout.
Update January 27, 2018
I added macro capability. Now you can turn on all/some devices at once with one button. Turn on something and spam the mute key just incase you want the device to start quiet. Make a dumb TV act smart by sequencing button presses to get to a certain input source. Hate having to press 4 buttons to get to your channel, just write a macro to press the 4 buttons for you. The possibilities are almost endless.
Step 27: LircNodeJsWeb Automatic Startup on Boot
The instructions on the project README.md lack instructions on how to start the web server when the computer boots. My reason for that is that I do not know which OS is used. Since I know this Instructable is for Raspbian on the Pi Zero W, I can give instruction on how to start the server when the Pi boots in this instructable.
You will need to create a systemd service file in '/etc/systemd/system/'. Change directory to the system directory.
$ cd /etc/systemd/system
Then create a file named lircNodeJsWeb.service with the following contents (don't forget to use sudo when starting your editor):
[Service] WorkingDirectory=/home/pi/nodejs/LircNodeJsWeb ExecStart=/opt/nodejs/bin/npm start Restart=always StandardOutput=syslog StandardError=syslog SyslogIdentifier=lircNodeJsWeb User=root Group=root Environment=NODE_ENV=production PORT=80 [Install] WantedBy=multi-user.target
Test that you have correctly made the service file by issuing the following command and then checking that the website comes up in a browser. Don't forget to stop the Node.js server first if it is currently running.
$ sudo systemctl start lircNodeJsWeb
After the the website comes up successfully, we need to enable the lircNodeJsWeb service so that it automatically starts after the Pi boots. Run the following command:
$ sudo systemctl enable lircNodeJsWeb
You should see the following output:
Created symlink /etc/systemd/system/multi-user.target.wants/lircNodeJsWeb.service → /etc/systemd/system/lircNodeJsWeb.service.
Reboot and test that the web server automatically started. Give the Pi a minute or so to startup before browsing to the website.
$ sudo shutdown -r now
If the website displays, Congratulations! You now have an awesome universal remote control that you can access with any browser in your local network.
Thank you for reading and I hope you enjoyed this Instructable.