Which remote is better – this universal remote or this iPhone? Of course iPhone is better!! It is naturally the best remote you can imagine. It is connected to the internet, so you can check the TV program. It has huge high-resolution touchscreen. And it is always with you. One problem with it: it’s not a remote at all. So let’s turn your smartphone into a remote.
First let’s check the competition. What? $50 for the remote?! That’s crazy!! We will build ours for a tiny fraction of this price. Mine cost me less than $2.
All we need is 2x 940nm IR LEDs ($2.50 for 10 or $5 for 50) and an audio plug that fits your smartphone. You can salvage it from broken headphones or buy for $1.
Attach the two LEDs to the plug like it is shown on the picture. Long leg of one LED and short leg of another LED go to the large tab on the plug. The rest of the LED legs go to the rest of the plug connectors. Mono plug has just two connectors and works just as fine: just attach the remaining LED legs to that one remaining connector.
Your remote is ready! It can look as ugly as this one above or a bit nicer like this.
Now plug this remote into the headphone socket on your smartphone, and make sure the volume is cranked up to maximum. This needs a quick explanation. Not sure about Android (never used it), but iPhone has multiple sound volumes: for ringer, for player, for headphones, maybe more. We need to set the player headphones volume to the maximum. You should plug headphones, start iPod program and increase the volume to maximum. Make sure the headphones are not in your ears or you can damage hearing. The other, trickier, method is inserting the remote into the jack and playing the command file. In that short moment when the file is being played you can adjust the volume. You need to be very quick to do that.
Open this web page in the web browser: http://remote.rtfms.com.
Select the device you want to control, then click on the appropriate file, like Power.wav to turn the power on.
You don’t actually need an iPhone and the Internet for this hack to work. You can download those file to any device that can play .wav sound files, such as
- Any smartphone like Android or Blackberry
- Most mp3 players
- Many dumbphones
- Even your PC – this remote you will never lose!
The best feature of my new universal remote is that if I can use MobileMe to quickly find it :) Or just call it.
So, how on Earth Does This work?
The general principle of this device operation is quite simple: you just play a sound file. You play it not via the headphones or speakers, but via IR LEDs. The same LEDs are used inside most remotes you have at home. When plugged to the iPhone those LEDs blink when electrical signal gets to them and this blinking makes your TV or DVD player to run one command or another.
So how do we create a sound file that will make the LEDs blink just like they do in the remotes? There are a few technical difficulties with that. If not those difficulties you probably would never see those $50-$80 remotes in the stores because $2 remotes would be doing the same job. To understand the problems with the sound files let’s first understand how the IR remote signal works in general. You can find more information in the Internet, here I’ll provide just a very basic explanation.
So in the foundation of the IR signal there is a CARRIER. Carrier is a certain frequency specific to a given device and in 80% of the cases close to 38kHz (i.e. 38000 cycles per second). For simplicity let’s say that the remote LEDs always blink with this frequency, but with different intensity. In fact there are only two intensities: maximum and 0.
Now every command to your IR-enabled home appliance can be specified as a bunch of numbers like the device code and the command code. How do those numbers get transformed into those intensities? Well, you can find the details on wikipedia, but in brief every set of numbers can be encoded as a sequence of pairs (on_duration, off_duration) like it is described here: http://www.remotecentral.com/features/irdisp1.htm.
So all we need is to generate the carrier frequency and just turn it on and off at certain moments. And here comes the first challenge: the carries frequency is 38kHz and most audio cards can only output maximum of about 20kHz. Also many devices (like iPhone) only support only audio files with certain characteristics and the best we can get from it is 44.1kHz sampling rate for stereo output which leaves us with just 22.05kHz per channel. There is no straightforward method to generate 38kHz when your device can only output 20kHz.
Fortunately there are at least two ways how to do it, both require two LEDs.
Method #1. Leveraging the power of stereo signal
So we have 20kHz on each channel. Fortunately the total sampling rate is 44.1kHz meaning that 44.1 / 2 = 22.05 kilotimes per second we can specify what should be the state on EACH channel. This method shifts the phase of signal on each channel so that while each channel outputs 22 kHz signal the combination of the signals is actually producing 44.1 kHz. Let me throw in a picture to illustrate this:
As you can see the sum of the two signals actually oscillates at double frequency, in our case it’s 44.1kHz. So if we connect one LED to one channel and the other one to the other channel each LED will blink with frequency 22.05 kHz, but together they will blink at 44.1kHz. Cool!!? Well, actually not so cool. LEDs have polarity and they will only blink when it’s right. That means that the entire bottom part of the signal is wasted. Let’s try another method
Method #2. LEDs are still just a diodes, just light-emitting
Diode is an electronic component that lets current flow in just one direction. In the case of LED when the current flows it also make it lit. Let’s use this and connect both LEDs to just one channel. We will also connect them in the way so that they are reversed. Now when the polarity is right for one LED it is wrong for the other one ans vice versa. Here is the picture:
What that gives us the same 44.1kHz but we got them from just one channel and no energy wasted. BTW, if you connect the both channels no LEDs will be blinking at all because they still have two signals in antiphase and cancel each other. So we need to send the same signal on both channels. This is what the hack presented on this page does.
So we got our 44.1kHz. Wait, don’t we need actually 38kHz? Yeap. And we also need 36kHz, 50kHz and other frequencies because different appliances use different IR protocols with different carriers. So how do we turn 44.1kHz into 38kHz (the most common frequency)? Well, the dumb method is divide one frequency by another like X=44.1/38 =1.16 and skip 16% of the 44.1 oscillations. Smarter method uses something like Bresenham’s algorithm, offers better approximation and better performance. It’s important to understand that it’s impossible to generate perfect 38kHz on a 44.1 oscillator, but we can get a good approximation. Good enough for most IR receivers to treat the signal like it’s coming from their original remote.
How about those 50kHz devices like Bang&Olufsen boxes? Well, sorry, no solutions for those yet, though I have one idea worth trying.
How well does this remote work? It depends on what kind of LEDs you use and how well you built the remote.
First of all all LEDs are different and some of them are very different. I’m using generic noname 950nm LEDs and when assembled properly they have approximately 9ft range. I’ve ordered high-performance 940nm LEDs and will keep you posted on their performance. Hopefully they will work better.
The other aspect of the problem is LEDs alignment. Because unlike in the generic remote neither of those LEDs oscillate at the carrier frequency it is very important that the appliance IR receiver sees them both simultaneously. To make things even more complicated generic LEDs have quite narrow beam approximately 20-30 degrees. This picture illustrates what happens when you do not keep those LEDs properly aligned:
As you can see combined beam becomes even narrower when the LEDs are misaligned, meaning you will need to target the IR receiver on your TV like a sniper. So do your best and keep those LEDs aligned as much as possible. Also do not forget that the beam is actually 3-dimensional so you need to watch both horizontal and vertical alignments.
How do I make a better IR Remote
In my “better” remote I used a fine file to make one side of both LEDs flat and glued them with superglue like it is shown on this picture:
Then I cut the legs and soldered this construction to the 3.5mm plug:
This made the construction robust and compact. Finally I covered everything with heat shrink.
Q: Ok, I got the theory, but how did you cook those files that make the LEDs blink right way?
I wrote a program that takes codes I found in the internet forums and generates the .wav files from them.
Q: Can I see that program?
Yes. No. Not yet. My overall goal for this project was actually learning Python, not hacking remotes. So I wrote this program in python that generates the files. This is my first program in python and I’m ashamed with its source code quality. So let me polish it then I’ll publish the sources.
Q: How do I get those magic .wav files for my XXX ZZZ appliance?
Let’s work on this together. Please submit your request here as a comment and I’ll do my best to generate the necessary files. Then you will try them and let me know if they work fine. If they do – everyone is happy. If not – I’ll keep digging.
Some devices will never get the .wav files. Like PS3 or Wii that use bluetooth for communications with remote. Some device will get the codes but not soon, like those 50kHz Bang and Olufsen devices. But these are in minority, absolutely most devices can be controlled using this method.
Q: I have those codes for my appliance in Pronto Hex format, can I send them to you?
Absolutely! Send in any format and let me know what the format is, I’ll try got turn it into .wav files.
Q: Did you invent all this LED interlacing thing?
Nope, bunch of smart guys did, I was just learning python :) Although I’ve never seen anyone else who made a functional TV remote for iPhone using this idea and made it work via browser, that is kind of cool.
Q: Why the user interface is so ugly and unusable?
Because it’s minimum viable product. I promise to improve if there will be more than 20 people using it. If not – would it worth it to put so much time into a UI almost nobody will use?
Update – the source code
Here is the python source code of the program I used to generate the original few .wav files shown in the video. The pronto codes are defined in the end of the script.