Episode #4: Turn your iPhone(Android, Mac, PC, Player, etc) into a Universal Remote

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.

RTFMs Episode #4: iPhone Remote
RTFMs Episode #4: iPhone 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.

Remote Competition #1Remote Competition #2
Remote Competition #1

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.

iPhone Remote Bill of Materials
iPhone Remote Bill of Materials

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.

iPhone Remote LED Pinout
iPhone Remote LED Pinout

Your remote is ready! It can look as ugly as this one above or a bit nicer like this.

iPhone a Nicer Remote
iPhone a Nicer Remote

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.

iPhone Remote Max VolumeiPhone Remote not Max Volume
iPhone Remote Max Volume

Open this web page in the web browser: https://remote.rtfms.com.

iPhone Remote Device Selection
iPhone Remote Device Selection

Select the device you want to control, then click on the appropriate file, like Power.wav to turn the power on.

iPhone Remote Command
iPhone Remote Command

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: https://www.remotecentral.com/features/irdisp1.htm.

Problems

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:

iPhone Remote Carrier Generation Method 1
iPhone Remote Carrier Generation Method 1

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:

iPhone Remote Carrier Generation Method 2
iPhone Remote Carrier Generation Method 2

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.

More problems

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.

Performance

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:

iPhone Remote LEDs Alignment
iPhone Remote LEDs Alignment

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:

iPhone Remote LEDs Glued Together
iPhone Remote LEDs Glued Together

Then I cut the legs and soldered this construction to the 3.5mm plug:

iPhone Remote LEDs Soldered to the Plug
iPhone Remote LEDs Soldered to the Plug

This made the construction robust and compact. Finally I covered everything with heat shrink.

FAQ

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.

57 thoughts on “Episode #4: Turn your iPhone(Android, Mac, PC, Player, etc) into a Universal Remote

  1. couldn’t you just take a universal remote, reroute the LED into the microphone jack, and record your own WAV files that way? or will there be too much noise

    1. Edit1754,

      Yeap, that’s a possibility. In fact you don’t even need to reroute the remote LEDs, you can use the ones used in this remote. I.e. those LEDs work not only as emitters, but as receivers as well. I’m working on the soft to leverage this fact. And this is how I was debugging the hardware aprt, BTW.

      Also old remotes are a good source of great IR LEDs. They have appropriate wavelength and they are also frequently wideangle – really useful feature.

      Andrey

  2. “I promise to improve if there will be more than 20 people using it.”

    here’s one. even tough i don’t care about the interface :P Thank you for sharing a great idea.

    1. Isama,

      Thank you, so 18 more to go (I count myself too) :)

      In fact with already a few thousand project visits it looks like there are plenty of people who want their universal remote, so I decided to go ahead with the better design without waiting for the rest of confirmations.

      Andrey

    1. NotSpamming,

      Great idea, unfortunately I can’t.

      But you can :) When you buy those LEDs on ebay in bulk they cost around 10 cents per count. 3.5mm plugs are less then $1. Even if you sell those for $5 that’s a good profit. And it can be assembled without soldering, just with heat shrink.

      But wait for a week till a better interface is ready. I also came up with the new wiring schema, it looks very promising.

      Regards,
      Andrey

    1. Greymatr,

      Great idea! I was thinking about this, unfortunately I don’t have much time this week, so if you have a few hours to spare maybe you can make one?
      I’m currently working on the web interface and solving the existing problems like
      – huge delay between the button press and the file being played
      – ugly hardly usable interface
      – not-so-great range and barely ok angles
      – polishing the code so I can publish it

      I have a good progress with those, so hopefully will have those problems resolved sooner than later and release v2

      Andrey

    1. Vcazan,

      Will certainly do. Simultaneously I’m trying a different approach to getting more codes. Hopefully the database of the available codes soon will be sufficient enough and this remote will become truly universal.

      Regards,
      Andrey

    1. Flood_of_SYNs,

      Thank you for double-checking!

      I know that diagram looks strange, but it’s correct. In fact there are two other wiring approaches and they all look strange too. I’m going to describe them a bit later with different pros and cons

      Andrey

  3. I have made 44.1 kHz files as requested. There are also 8 and 16 bit versions of both 44.1 and 48 kHz. I am surprised that some devices will not play 48 kHz. Do they also not do 48 kHz MP3?

    The code has been updated to remove MFC dependency so it can be compiled with the free Visual Studio Express. It has also been cleaned up a bit. Take a look at the IrAudio::Sine() function to see how DDS (Direct Digital Synthesis) is used to generate a precise carrier frequency. Having a proper carrier frequency and IR wavelength (950 nm) is beneficial in this application because the power is very low compared to an ordinary remote. The maximum carrier frequency that can be achieved with real hardware is about 45% of the sample rate. It is not possible to do 50% (half of sample rate) for a variety of technical reasons. (Study Shannon and Nyquist for all the details)

    New code and wavs: http://www.compendiumarcana.com/iraudio/tvgb2wav.zip

    I first became aware of this technique from a posting at the Sparkfun forums: http://forum.sparkfun.com/viewtopic.php?f=14&t=9394

    That lead to the development of a way to capture IR directly to audio: http://compendiumarcana.com/iraudio/

    I also added audio generation to my IR Widget software: http://compendiumarcana.com/irwidget/

    The IR Widget has become popular with the JP1 community, and they have created updated software that can import Pronto hex and other formats and convert them to audio: http://www.hifi-remote.com/forums/viewtopic.php?t=12241

    One of the JP1 members also sells an assembled IR Widget for those who canā€™t build one: http://www.hifi-remote.com/forums/viewtopic.php?t=9405

    1. Hello oPossim,

      Thanks a lot for the files and the new sources. I didn’t try them yet as last week was crazy.

      I tried to play the files on Max with sox – it played some and choked on others. Then I concatenated the files (again, via sox) and tried to play them on iPhone and it didn’t like 48kHz at all. After quick research I found a lot of complains from different people that 48kHz format has very limited support on many platforms.

      Thanks for the other links too, will study them a bit later.

      Regards,
      Andrey

  4. Correction to above: should say maximum AUDIO frequency, not CARRIER frequency. The IR carrier is double the audio, so it can be about 90% of sample rate.

    1. Hello curious,

      Hmmm …
      Just plugging your phone to an antenna won’t work because iPhone can’t output much power + the frequency is totally off.
      But you can sure use it as a modulating input for any transmitter, like ham radio. Just make sure you’re not transmitting music on ham frequencies – that’s in general prohibited with a few exceptions.
      Also there are products on the market that will transmit sound from your iPhone to an FM radio – that will work for 10ft or so.

      Regards,
      Andrey

  5. Hello

    How would I get the Wav files for the Remote used with my Home sound system. The system is a JBL ESC350. There are two Buttons that I would like to get the files for, “Tone” and “Calibrate”.

    Thank You

    Ted

    1. exodus,

      Sorry, that’s probably not enough. Besides these two codes I need at least the carrier frequency (I hope it’s 38K). Also my code only can covert pronto codes into IR signals. I think it is possible to convert the two codes you sent into pronto code, but maybe it is easier to find the pronto code by model number? There are websites in the internet that collect such codes (even though most of them are totally not working based on personal experience)

      Andrey

  6. Hi Andrew, i have been trying to get this to work for quite a while, but no luck, i have an infra red socket “http://www.sourcingmap.com/220v-infrared-remote-control-socket-outlet-p-104026.html?currency=GBP&utm_source=google&utm_medium=froogle&utm_campaign=ukfroogle” which i am trying to switch on, it picks up the signal i am sending (the light flashes on the socket) but i doesnt actually power on, i have tried with a samsung remote and the socket works fine, any ideas?

    1. Nixdorf,

      I’m not sure about this particular device, but my TV also flashes light when I’m sending wrong IR signal to it. I think those flashes may mean that it just sees the signal, the carrier is correct, but not necessarily the signal itself is right. If you have an oscilloscope you can hook up an IR receiver to it and compare signals from your remote and from samsung remote. Maybe it will reveal the difference in signal.

      Sorry about being not very helpful, I’ve just never seen anything like this device. My home power control works via X10 which is an RF protocol. I know X10 devices are also available in Europe, maybe you can consider using one of those? RF is more versatile than IR, it works even through walls.

      Andrey

    1. palaniraja, it worked for my samsung TV as well when I tried codes from remotecentral. Unfortunately I found their database very old and frequently wrong. I dodn’t find codes for most of my home and office electronics and the codes I found frequently didn’t work. Maybe you know another good source of codes?

      I’m currently busy with the new episodes of RTFMs, but I’ll return to this topic and I’ll try luck with AppleTV codes later.

  7. Thank you Andrey for reply.

    I have few friends who own apple remote, I could ask them for help, but how do they capture the code?

    Is it possible to use macbook pro IR receiver to capture (IR codes) with any application (preferably freeware)

    1. Lee,

      Just open this page in a web browser and save the files to local disk just like you save all other files (right-click on the link, select “Save Link As…” or something like this, depending on the type of your web browser). Then upload files from your computer to the MP3 player.

      Regards,
      Andrey

  8. I tryed to create the wav file from this code:
    0000 006D 0022 0002 0157 00AC 0015 0016 0015 0016 0015 0041 0015 0016 0015 0016 0015 0016 0015 0016 0015 0016 0015 0041 0015 0041 0015 0016 0015 0041 0015 0041 0015 0041 0015 0041 0015 0041 0015 0041 0015 0016 0015 0041 0015 0016 0015 0016 0015 0016 0015 0041 0015 0041 0015 0016 0015 0041 0015 0016 0015 0041 0015 0041 0015 0041 0015 0016 0015 0016 0015 0689 0157 0056 0015 0E94

    but I get this error: Traceback (most recent call last):
    File “C:\prwav.py”, line 76, in
    file.write_ir_code( samsung_power_code )
    File “C:\prwav.py”, line 55, in write_ir_code
    ( self.frequency, sequence_1_len, sequence_2_len ) = ( frequencies[codes[1]], int( codes[2], 16 ), int( codes[3], 16 ) )
    KeyError: ‘006D’

    what could be wrong?

  9. I’ve tryed other codes too, but I still get Key Error. this time 0070

    0000 0070 0000 0064 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0030 0010 0aac 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0030 0010 09cf

    what should be wrong?

  10. http://dl.dropbox.com/u/14932480/IR%20Remote/IrRemote.html
    Made this quick example with JQTouch

    Now need to create more wavs for the rest of my appliances… having trouble running the python code in Python 2.7, getting this error:

    Traceback (most recent call last):
    File “pronto.py”, line 75, in
    file = IrSoundFile( ‘samsung’, ‘tv’, ‘power’ )
    File “pronto.py”, line 14, in __init__
    self.file = wave.open( dir + ‘/’ + signal + ‘.wav’, ‘wb’ )
    File “C:\Python27\lib\wave.py”, line 500, in open
    return Wave_write(f)
    File “C:\Python27\lib\wave.py”, line 303, in __init__
    f = __builtin__.open(f, ‘wb’)
    IOError: [Errno 2] No such file or directory: ‘samsung/tv/power.wav’
    Exception AttributeError: “Wave_write instance has no attribute ‘_file'” in <bou
    nd method Wave_write.__del__ of > ignored

  11. #Very dumb question!

    IR is not standard on phones or tablets. Has anyone developed a bluetooth/ir convertor which is not a ripoff like the logitech harmony or the griffin beacon??

    It seems logical to me to simply use a good app transmitting thru bluetooth to control ur HE system. Any leads?

    1. saptrix,

      A BT/IR converter is not a difficult thing to do on android, maybe more difficult on iPhone because of its closed and limited API. On android you can use BT as a link to send serial commands over. On the IR side you put a simple microcontroller that will trigger the IR LEDs. I haven’t seen an opensource implementation of such though.

      Regards,
      Andrey

Leave a Reply