How-to: USB remote control receiver

Now that we listen to MP3s, and watch XVIDs or x264s, a computer is the entertainment center in at least one room of most homes. Unless you have a special HTPC, though, you’re probably stuck using the keyboard to pause, change the volume, and fast-forward through annoying Mythbusters recaps. PC remote control receivers range from ancient serial port designs (who has one?) to USB devices not supported by popular software. In this how-to we design a USB infrared receiver that imitates a common protocol supported by software for Windows, Linux, and Mac. We’ve got a full guide to the protocol plus schematics and a parts list.

Design overview


Remote controls transmit data on an modulated infrared beam. An infrared receiver IC separates the modulated beam into a clean stream of 0s and 1s. The data stream is decoded by a microcontroller and sent to a computer over a USB connection. Software processes the codes and triggers actions on the computer.

Background

Computer infrared receivers

The oldest PC infrared receiver design uses a receiver IC to toggle a serial port pin, usually DCD. This design probably originated on Usenet, and it’s still the most popular on the web: Engadget, Instructables, etc. These aren’t true serial devices because they don’t send data to the PC. Instead, a computer program times pulses on the serial port and demodulates the signal. This is a super simple design, but it depends on direct interrupt access and timing precision that’s no longer available in Windows. Linux or Mac users can try this receiver, if you still have a serial port. We couldn’t get this type of receiver to work with the serial port on a modern Windows XP PC, and don’t expect the precise timing to transfer through a USB->serial converter.

Some more advanced infrared receivers are true serial port devices that measure or decoding infrared signals before sending data to the computer. The UIR/IRMan and UIR2 incorporate a classic PIC 16F84, but don’t provide firmware and/or source code. These devices should work on a modern computer, through a USB->serial converter if necessary. The USBTINY and USBIRBOY are native USB devices, but lack wide support.

Receiver software

Regardless of receiver type, the computer needs a program to listen for incoming remote commands and convert them to actions on the computer. Linux and Mac users have LIRC, which supports a bunch of different receiver types. Windows users are a bit less fortunate. WinLIRC is an abandoned Windows port of LIRC for simple interrupt-based serial port receivers; WinLIRC was last developed in 2003. Girder was originally a freeware PC automation utility, but has become expensive bloatware with a 30 day trial. Fortunately, the last freeware version of Girder (3.2.9b) is still available for download.

Working with IR remote protocols

Decoding IR signals

Remote controls encode commands in the spacing or timing of a 38KHz carrier pulse, [San Bergmans] has an explanation of the principals involved. An infrared receiver IC separates the data stream from the carrier. Our job is to decode the data stream with a microcontroller. There are dozens of remote control protocols, but Phillips’ RC5 is widespread and commonly used by hobbyists.

RC5 is stream of 14 equal length bits of exactly 1.778ms per bit time. A pulse during the first half of the bit time represents 0, a pulse in the second half represents 1. This scheme is called Manchester coding.

We used a logic analyzer to examine the output of a Happauge WinTV remote control, a known RC5 remote. The diagram shows two presses of the 1 button, and two presses of the 2 button; note that the output is inversed and the Manchester coding is backwards from the above description.

The first two bit times are start bits, followed by a toggle bit. The toggle bit inverses each time a button is pressed so the receiver can tell the difference between a hold and a repeated press. The next 5 bits are the address (0b11110=0x1E), followed by the command (0b000001=0x01, 0b000010=0x02). A backwards compatible extension to RC5 uses the second start bit as command bit 7.

Representing remote codes to the computer

Looking at previous designs, we saw three general methods of communicating remote commands to a computer:

  • Protocol specific receivers decode one protocol, and send actual decoded commands to the PC
  • A more general type of receiver measures the timing and spacing of each pulse and sends the full waveform to the PC for analysis.
  • Some receivers create a unique hash for a signal, but don’t actually include enough data to fully recreate the waveform.

While our preference is towards the general hash method, our only remote uses RC5 and it was more interesting to build an RC5 specific decoder. We describe modifications for a more general version in the firmware section.

Computer interface protocol

We didn’t want to write our own receiver software or driver, so we looked for an existing, well established communication protocol to imitate. The UIR/IRMAN/IRA/CTInfra/Hollywood+ type receiver is supported by Girder and LIRC, and uses a simple serial protocol with handshake:

  • The device is initialized by the DTS and DTR pins of the serial port. We don’t have these and don’t care.
  • The computer sends “IR”, with an optional delay. The device replies “OK”. We’ll just send “OK” on every “R”
  • Remote control codes are sent as a unique six byte hash. We’ll decode an RC5 signal and send the actual values, but a generic hash could be used instead.

This protocol is for a serial port device, but our USB receiver will appear as a virtual serial port and the program won’t know the difference.

Hardware

Click here for a full size schematic (png). Our receiver is based on a USB enabled PIC 18F2455 microcontroller, the smaller, cheaper version of the 18F2550. The 18F family is programmable with the hobbyist favorite JDM-style programmers if a diode is used to drop VPP to a safe level. The PIC gets one decoupling capacitor (C1), and a diode (D1) and resistor(R1) on the ICSP programming header. We exposed the serial port on a pin header for debugging or a mixed USB/serial port version using a MAX RS232 transceiver IC.

The USB peripheral requires a 20MHz external clock (Q1, C5,6), and a .220uF capacitor. We faked the capacitor using 2 x .1uF decoupling capacitors (C2,3). A 3mm LED (LED1) and a 330ohm current limiting resistor (R2) show USB connection status.

We used a TSOP-1738 infrared receiver IC which calls for a 4.7uF decoupling capacitor (C4). If you can’t find this particular IC, any receiver listed here should work. The TSOP-1738 output is the inverse of the received signal, it pulls to ground when a pulse is detected, so a pull-up resistor (R3) holds the pin high when no signal is present. Check if you use a different receiver, you may need to use a pull-down resistor and reverse the Manchester decoding routine in the firmware.

The circuit draws power from the USB bus, so we don’t need an additional power supply.

Parts list

Click here for a full size placement diagram (png). The PCB design is 100% through-hole and single sided. The schematic and PCB were made with Cadsoft Eagle, freeware versions are available for most platforms. All the files are included in the project archive (zip).

Part
Description
IC1
C1,2,3
C4
C5,6
27pF capacitor (15pF might be better)
D1
Q1
R1,3
R2
TSOP
TSOP1738 (obsolete, try TSOP1138)
USB
SER
ICSP

Firmware

The firmware is written in C using Microchip’s free demonstration C18 compiler. Firmware and source are included in the project archive (zip).

We used version 2.3 of Microchip’s USB stack to create a USB serial port using the default drivers already available on most systems. The USB stack has simple functions to enumerate the USB device and transfer data between device and host. It only took a few pin changes to get the CDC demonstration working on our custom hardware.

Our implementation of the UIR/IRMAN/IRA/CTInfra/Hollywood+ protocol simply responds to the letter ‘R’ with ‘OK’. This should satisfy the handshake requirements of any implementation of this protocol.

We chose to specifically decode RC5 (and RC5x) because it’s a widely used protocol, and the only type of remote we have to work with. Most of the decoding is done in the interrupt handler:

  • The first signal change triggers an interrupt that starts a 889us (one-half bit period) timer.
  • On each timer interrupt, one-half of a Manchester coded bit is sampled.
  • Every other interrupt the measurements are compared, and the bit value is calculated to be 0, 1, or an error. Errors reset the decoding routing.
  • At the end of each transmission the address and command bytes are decoded, and sent to the host with 4 buffer bytes(0). We discard the toggle bit because it would confuse the PC software into thinking every other press was a unique code. We append the second start bit to the command bit for RC5x compliance; this just adds 0x40 to non RC5x remote codes.

A more general version can be made by removing the Manchester coding step (3), and sending 48 sample bits (all 6 bytes) to the computer.

Installing the USB infrared receiver

Most operating systems already have drivers that support a virtual serial port device like the receiver. Windows XP has the required drivers, but needs help from an .inf file to properly associate them with our device.

Windows will show the new hardware dialog the first time you plug in the receiver. Choose to use a custom driver and point it to the .inf file included in the project archive (zip). This links the device to a driver already included in Windows, and adds the receiver as a COM port. You can check the COM port number in the control panel.

Mac and Linux users can use the receiver with LIRC, but Windows users will be faced with the choice of the old, freeware Girder, or the new, 30-day trial shareware version. We used the freeware version of Girder, but hope you guys can suggest a great, open source alternative that we overlooked.

Regardless of the computer-side control software you use, configure it for a UIR/IRMAN/IRA/CTInfra/Hollywood+ style receiver, and enter the COM port or serial address assigned to it. Our receiver is also compatible with any protocol options like ‘Fast UIR Init’ and ‘Skip UIR Init Check’, which shorten or eliminate the “IR”->”OK” handshake. Now test the receiver and add a remote according to the documentation for your software.

Manual terminal interface and debugging

If you have a problem with the receiver, or you’re just curious, try to interface it from a serial terminal. We really like the serial terminal on Hercules. Set the correct COM port, but the speed and configuration settings are ignored by the USB serial port driver.

A capital ‘R’ will prompt the receiver to reply ‘OK’. RC5 codes are returned as raw bytes, so be sure to set your terminal to show HEX values rather than interpret it as ASCII text. The first byte is the RC5 address byte (0x1E), followed by the command byte (0x41), and then four buffer 0s to comply with the UIR/IRman protocol. The image shows the handshake, and the output of a short press on the 1,2, and 3 buttons.

A free utility called Portmon logs COM port activity for review. This is helpful for spying on existing receiver protocols, and debugging the interaction of our custom hardware and closed/proprietary software. The image shows Girder sending the initialization string ‘IR’ (0x49,0x52), and the receiver reply ‘OK’ (0x4F,0x4B).

Taking it further

Our RC5x compliant receiver follows a widely used interface protocol. There’s a ton of possibilities for additional features in an open source infrared receiver:

  • Support all remotes through a generic hash generator, like the original UIR/IRman hardware.
  • Add additional remote protocol decoders, like RC6.
  • Support multiple, configurable interface protocols.
  • Implement the serial port I/O.
  • Store configuration options in EEPROM, including protocol, interface mode, timing options, serial port, etc.

Comments

  1. slater says:

    not a very related question but i am realy curious
    will an old serial port reciver work with a serial to USB adapter with winlirc?

  2. Chris says:

    Has anyone got this to work with Ubuntu and LIRC?
    when I plug in the unit it get a “/dev/ttyACM0″ but not sure what driver I need LIRC to use

    Works in XP just fine with grinder.

  3. Chris says:

    This is how to get this working under Ubuntu 8.04

    1: Compile LIRC with IRMan support

    2: Next stop the cdc_acm driver and stop it from loading

    sudo modprobe -r cdc_acm

    echo “blacklist cdc_acm” | sudo tee /etc/modprobe.d/cdc_acm

    3: Unplug the device
    4: Run this command to load the correct driver

    sudo modprobe usbserial vendor=0x04d8 product=0x000a

    5: Now you should have a /dev/ttyUSB0 device that you can configure LIRC to use next we need to configure the /etc/lirc/hardware.conf file to use this new device

    6: sudo nano /etc/lirc/hardware.conf

    and make the needed changes to match the below lines.

    REMOTE=”Custom”
    REMOTE_MODULES=””
    REMOTE_DRIVER=”irman”
    REMOTE_DEVICE=””
    REMOTE_LIRCD_CONF=”/etc/lirc/lircd.conf”
    REMOTE_LIRCD_ARGS=”–device=/dev/ttyUSB0″

    START_LIRCD=”true”

    LOAD_MODULES=”true”

    7: I am using a the Verizon Fios remote model RC14453022/00B programmed for code 0881 on the DVD button, this code gave me the needed rc5 output. Just as a note this remote will not allow you to use the digit keys for the TV,AUX,and DVD buttons and it will not control my Blue Ray Player, have to find me a new remote…

    8: Next we need to make a Lircd.conf file. Run
    the next code and follow the prompts.

    sudo irrecord –disable-namespace –driver irman -d /dev/ttyUSB0 RemoteXXX.conf

    9: Next we need to copy the new file to the correct location.

    sudo cp RemoteXXX /etc/lirc/lircd.conf

    10: Now we start LIRC using the correct driver so we can check if the setup is working.

    sudo lircd -n –driver irman -d /dev/ttyUSB0

    11: We now need to start irw to see the output of the remote keys, if you do not see any output when a key is pressed then your setup is not working

    irw

    12: Next you can run mythbuntu-lircrc-generator to make the ~/.lirc/mythtv configuration file for mapping the remote keys, or you can do it manually.

    Good Luck
    Chris

  4. Ivaneduardo747 says:

    @ Slater: in short: no because the WinLirc’s serial receiver does not decode the signal, wich is decoded by software. It does’nt do handshacke with the pc and WinLirc access to the Serial port directly. You can still buy one PCI -> Serial card (dont know if those things beeing sold).

    @ THE PEOPLE THAT TRIED LOTS OF REMOTES: if your PIC seems to work, but you cant get any data from any remote, try this:
    Check your receiver with an osciloscope (if you own one) or with a simple led (remember the resistor!).
    Check if your remote IS RC5 (just one of the 6 in my home was RC5, the rest where RC6)
    Try in raw mode (or however is called)
    If you are shure that everything is working ok (exept that all your remotes are not RC5) just buy a generic control and program it for Philips TV.

    @Chris looks ok, i will give it a try

  5. akis k triandafillou says:

    my creative rm-1800 stop work,after windows updates,please if you have something for my.

  6. x says:

    has anybody added any modifications to the firmware or has the author released new firmware?

  7. Ian says:

    My WinTV remote (pictured) broke, so I had to replace it with a universal remote control. Low number Phillips TV codes seemed to be RC5 on the models I tried.

  8. rendy says:

    i’ve made it, but so simple, not like it,
    i know it from a book. only 5 component.
    easy to install,
    anyway, your guide is cool

  9. Franciosi says:

    The device its recognized and a serial port is assigned.
    Hercules give OK response to “R” but dont return any IR signal from remote controls.

    The IR device is SFH 5110 active-low ir demodulator.

    The PIC is the 18F2550.

    Where is the problem??

  10. Ian says:

    @Franciosi – did you use the HEX or compile your own?

  11. hanuru says:

    i noticed i already have infrared on my pc so does that mean i just have to set up the remote to make it work?

  12. Ah Bee says:

    I want to know is it support remote wake up? I want to wake the host PC by pressing the power button of the remote control.

  13. president.nulagi says:

    er, guys:

    http://www.eventghost.org/

    Less geeky, but much easier!

  14. drink says:

    Could anyone help me, how to implement power-off/power-on function by this remote, either by (powerswitch/wakeonlan) or usb-wake-up. Thx in advance.

  15. ronnie says:

    I built this circuit as a portion for a school project of mine (tube amplifier). Win XP recognizes, allows me to update driver, Hercules send R receive OK. Using a multitude of remotes including a programmable universal remote. Girder and EventGhost will not recognize. I can see signals on my oscope from the IR Receiver, but nothing seems to be output on USB. I programmed the 18F2455 with a Kitsrus.com 149E programmer using Microburn software. There seemed to be issues with the Fuses. The fuses outlined in config.h do not match the available options in Microburn. Might this be my problem? Also, in main.c, which lines of code should be removed to allow all IR signals to be passed to the computer? Any insight is much appreciated as this is the final aspect of my project that is now due in 2 days =(

    Thanks in advance!

  16. ronnie says:

    I got it all working, it was the Fuse info. However, I still need to know which lines of code to comment out in main.c

    thanks in advance

  17. DjMcMaster says:

    Dear “All” !

    At first: thank you for publishing this topic.

    The question: we opened the .brd file with Eagle (5.7.0 WIN lite and with 5.3 PRO version too) and the GND layer cannot be seen. Please advise what to do to make the GND layer visible. Or advise an Eagle version what can handle this project.

    Bye!

  18. Ian says:

    @djmcmaster – press the fill button in eagle (X with green dots on the end).

  19. ljudsko says:

    Hello,
    I made this receiver on protoboard and pluged it into USB. Windows 7 reconized new hardware and I manualy selected driver, included in project archive. I got error, that driver isn’t made for x64-based system? How can that be possible?

  20. Rusu says:

    Hello i have made this very nice receiver an i have problems to configure it. My operating sistem is Windows XP(sp2). i programmed the microcontroller PIC18F2550 with the hex code given above, when i plug in the usb cable into computer, the status message shows :” new hardware found” , i installed the driver (INF) and the led on the circuit blinks few times and then stops.
    the problem is i can’t configurate the circuit with the girder, UICE,… (maybe i don’t know i how). I tried to use 3 types of remotes but girder, and uice does not recognize nothing.
    What cand i do ? if you have any ideas please help me… thanx in advance!
    best regards, Rusu

  21. Rusu says:

    Hello! It works!!!:D
    My problem was the remote control. I tried many but only few from Philips worked. I also tried universal remotes but no succes.
    Thank you for this project!
    I have a question … With Windows vista this circuit should work?
    regards, Rusu

  22. Sanjib Adhikary says:

    i have try it but don’t work properly. what can i should now.

  23. Rusu says:

    Hello Sanjib,
    I have tried the receiver on Windows Vista, and works OK!. I used Girder 5. I also tried to use girder 3 but it don’t works properly. My advise is to try girder 5.
    all good, Rusu

  24. Jared says:

    You could try implementing a keyboard protocol, in fact I have a reciever that does exactly that. No frontend software required, and no drivers are needed either.
    It appears as a HID device.
    Most keys translate directly to keyboard keys, but the play/pause/ff etc. buttons translate to media keys, which are really useful if you want to control the media program when it doesn’t have focus.
    The only downside is you can’t (easily) customize the action of the keys

  25. ajd4096 says:

    WTF is this waffle about “true” serial?
    Software decoding does not make it any less serial.
    It sure as hell doesn’t magically send the data in parallel.

  26. dony says:

    Can I buy one from you ?. Seriously. If I got the sample it would be alot easier than to look it at the diagram.

    Thks

  27. KAZEM_TNT says:

    wherer can i find the driver for this circit?
    and this ic programer schematic ?

  28. I have spent a lot of time researching verizon internet through fios and the cable and satellite options available. Is there a single person out there believe that traditional cable is really better than Fios high speed? It seems that there is no comparison between the available options when talking about network speed and user experience for managing your channels.

  29. Fios is the best option by far

  30. IRconnector says:

    Can I Connect A Nokia Mobile Through this Curcit & Make An Internet Connection?
    I mean Can I USE it to connect a mobile as a IR Modem?
    Please Reply me Soooooooooooooon!!!!!!!!1

  31. mgrusin says:

    I know this is an old project, but has anyone gotten the source to compile with the newest libraries from Microchip? I’m getting errors (more info on request). Alternately, would anyone care to share a working .hex file?

  32. eleci says:

    mgruisin

    you mean you have tried this one ?? and not worked ?

    http://www.cg.tuwien.ac.at/~markusl/irmanClone2550.hex

  33. ljudsko says:

    It’s been a long time now, when I posted my error and still no reply! Can anyone please tell me, if this receiver is made for x64 base systems or not? Because it says that driver do not support x64 system, when I manual select driver for unknown device. Please help me.

  34. argento says:

    anyones has modified the code for use any remote control? not only rc5 (philips remotes)

  35. argento says:

    @ljudsko

    use this driver!

    http://www.obddiag.net/adapter/mchpcdc.zip the driver works for Windows 2000/XP/Vista/7 x86 and Vista/7 x64, using it with Windows 2000 is not recommending due the bugs in Windows 2000 CDC driver.

  36. miao44 says:

    Hello Ian!I have some problem getting the USB-Receiver work(I can see RC5 codes in the oscilloscope but get no more then just “OK”). So I build the project trying to find what the problem is.Then I found there maybe some missing lines in the main.c because it didn’t jump into the interrupt because GIE was not open.I doubt whether the source code is the last version.I use the original main.c to build the HEX and the two files are not in the same size.Check it when you have time and it will help me a lot.Thx in advance.

  37. ljudsko says:

    @argento, I already done that, as I said, but it doesn’t work..It says, that I must use a driver, compatible with windows x64 system..

  38. ljudsko says:

    Any idea, please?

  39. argento says:

    @ljudsko
    humm okey please check this first:
    program your pic 2550!!
    a rc5 ir remote (phillips rc5 tv or universal pre programmed).
    check your usb connection replace the cable.
    your ir remote soft support winxp/vista/7 x64?.
    (i’m using eventghost and work perfect).
    install the provided driver!.
    if noting work, i needed more info of your test!!!

  40. ljudsko says:

    @argento, I already tried this driver, but it doesn’t work. I tryed eventghost to, but doesn’t recognize device. Usb connection and cable is ok. Everything, that my circuit do, when I connect it to a PC, is that LED flashes.

  41. st2000 says:

    Anyone re-write this for the Microchip usb demo board?

  42. crizr says:

    After a lot of head-scratching, I was able to make it compile and run using Microchip’s v2.7a stack. It turns out you have to edit main.c and: paste the code from the USER_USB_CALLBACK_EVENT_HANDLER function from the demo’s main.c to make it compile; call “USBDeviceAttach();” after the “USBDeviceInit();” line; and call “USBDeviceTasks();” right after variable declarations on the “InterruptHandlerHigh” routine.

    For you guys who want to make it work with other remote codes, try using the algorithms / ideas from: http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html and http://www.arcfn.com/2010/01/using-arbitrary-remotes-with-arduino.html

  43. argento says:

    @crizr
    i’dont have any idea in programming!!!

  44. Siva says:

    I programmed the microcontroller PIC18F2550 with the hex code given above, when i plug in the usb cable into computer, the led on the circuit blinks few times and then stops.
    The problem is i can’t configurate the circuit with the girder. I tried to use 5 types of remotes but girder, does not recognize.

    I am getting output ‘OK’ in Hercules. when i send IR.

    Can anyone guide me how to check the remote is RC5

  45. Siva says:

    Can anyone tell Will the LED blink when we press the remote..

  46. argento says:

    @siva
    no the led not blink when you press the remote!!
    use a osciloscope is the only way to see the signal!!
    for remote im use a phillips tv remote an a sony universal pre-programed in a phillips tv and works fine

  47. Siva says:

    I am trying this for past 10 days , I used PIC18f2550, is it necessary to recompile the C file.

    when i plug in the usb cable into computer, the led on the circuit blinks few times and then stops.

    Will the LED be always ON if we connected to USB or it will blink for three times only when we connect. what is the purpose of LED.

    I am getting output ‘OK’ in Hercules. when i send IR. Can anyone guide me whether we receive HEX codes in HERCULES when i press button in remote.

    Is there anyone who completed this USB IR remote using 18F2550.

    Is there any difference between IR Receiver HS0038 A2 and TSOP1738.

    I am using IR Receiver HS0038 A2. and remote RC7812.

  48. crizr says:

    @Siva, the LED should stay on when the computer is connected. The precompiled HEX supplied on the project archive works with the PIC18F2550. If the circuit is ok HEX codes should appear on a serial terminal in binary/HEX mode when you press remote buttons. If you want to compile the code with the most recent Microchip USB stack you would have to make the modifications to the code I described above. There are probably differences between HS0038 and TSOP1738, check the datasheets. The TSOP4838 for instance, which I used, has an internal pull-up on the output, so you have to remove the external pull-up resistor.

  49. Siva says:

    @crizr Is it necessary to connect serial port, Can i known y serial port is used

  50. crizr says:

    No, connecting the serial port is not required.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 94,586 other followers