This project is for reasonably advanced electronic nuts...but if you stick with it anyone can make it.

Through Hole Technology (THT) version

If you choose to build the Through Hole Technology (THT) version, then you will be making a Printed Circuit Board (PCB) or at least a matrix board, soldering electronic components onto it, and then programming a PIC micro-controller, so you'll need:

Surface Mount Technology (SMT) version

If you choose to build the Surface Mount Technology (SMT) version, then you'll need:


And in case it doesn't work for you first time, you may find it helpful to have:

Circuit Diagram

The circuit can be divided into a number of functional groups.

Infrared Receiver Interface
The infrared receiver consists of the TSOP4838 IR receiver module. Its job is to convert 38 kHz modulated IR signals from your remote control into digital ones and zeroes. The receiver will output a logical one (0V) when the remote is transmitting a 38 kHz signal, and will output a logical zero (+5V) during periods of silence.


Infrared Transmitter Interface
The transmitter consists of a PN2222A transistor (but any general purpose NPN transistor will work) which drives a series of three Infrared Light Emitting Diodes (IR LEDs). Driving three IR LEDs is done to boost the transmitting power. Learning remotes are designed to accept signals from remote controls in close proximity and remotes are designed to produce an intense IR signal. Consequently, IRK! must produce a fairly intense IR signal in order for the learning remote to be able to "see" it during the learning process.


LCD Interface
The Liquid Crystal Display is a 2x16 (2 lines at 16 characters per line) unit compatible with the Hitachi HD44780 4-bit defacto standard. You can use a 4x16, or a 4x20 display if you like as long as it is HD44780-compatible. These are available on eBay at very reasonable prices.


USB Interface
The USB interface is provided by the USB module built into the PIC18F2550 microcontroller. It is managed programmatically by the USB library provided with the MikroC Pro C Compiler.


Activity LED Interface
Hardly an interface as such - a simple LED and a current-limiting resistor - but if you use a high intensity (8000 mcd) green LED then I've found that you can make the resistor an insanely high value - like about 18 kΩ - and the LED is still bright! That means that the driving current is only 100 μA. If you use the original 470Ω resistor specified in the circuit diagram then you could end up being startled by the brightness.


Power Interface (experimental)
The circuit diagram shows how to power the IRK! unit using the standby voltage (Vsb) output from your PC's power supply. However, this has not been tested. You can leave the connection to Vsb out and IRK! will still work - but if you power down your system, you will not be able to power it up using your remote control. Just walk over to your PC and turn it on the old fashioned way!

Programming The Microcontroller

To program the firmware into your IRK unit:

For those interested in programming, the source code (of IRK! version 2) on SourceForge is split into two components:

How it Works

Overview

The basic idea is that there is a one-to-one mapping between pressing a button on your remote control and a key combination sent to your PC. IRK! simply teaches your learning remote a code that represents a particular key combination. Once you have programmed that code onto one of your remote buttons, pressing that button will transmit the code back to IRK! which will, of course, recognise it then send it to the PC as a USB keystroke.

Because IRK! generated the IR code, it can't possibly not recognise it - so IRK! does not need to support a zillion different IR remote control models!

USB Keystrokes

USB keystrokes are sent to the PC using codes defined in the USB Human Interface Device (HID) Usage Tables specification. That specification defines, for example, that code 0x04 means the letter "a". For a keyboard device, like IRK!, additional "modifier" codes can be sent to the PC to indicate whether the GUI (aka Windows key, Apple key, Super key), Control, Alt and Shift keys are also "pressed". For example, to send an uppercase "a", IRK! sends 0x02 (meaning Shift is pressed) and 0x04 (meaning "a" is pressed). The computer interprets that sequence as meaning uppercase "A". Immediately after sending that sequence, IRK! will send a "null" sequence of 0x00 and 0x00 to indicate that no key or key modifiers are currently being pressed. This is required by the USB protocol otherwise the PC will think you are holding down the Shift and "A" keys until it receives the next USB key code.

So, you can see that IRK! only has to be able to "teach" a learning remote control a sequence of 0x02 followed by 0x04 to represent the letter "A". When the user presses that button on the remote, IRK! will receive it using its infrared receiver and then send the 0x02 0x04 sequence to the PC which will be interpreted as the user pressing Shift+A on a USB keyboard.

Infrared Command Format

IRK! only recognises infrared signals that are addressed to a particular IRK! unit. To achieve this, an address byte is also sent/received on the infrared path. Each infrared command is a sequence of six (6) bytes as follows:

AA, AA', UX, UX', YY, YY'

Where:

AA is the address byte from 0x00 to 0xFF
AA' is the inverted address byte (all the ones converted to zeroes and vice versa)
UX is the usage page (U = 0x0 to 0xF) and, for the Keyboard usage, modifier nybble X (Control, Alt, Shift)
UX' is the inverted UX byte
YY is the command byte (for Keyboard usage, the USB key code)
YY' is the inverted command byte

The reason for transmitting an inverted copy of each byte is to reduce the chance that interference has caused an invalid command to be received. For example, you wouldn't want your request to "play this recording" to be interpreted as "delete this recording" just because a fly interrupted the infrared signal path in that instant!

To validate each command as it is received, IRK! checks that AA (inverted) equals AA', and that UX (inverted) equals UX', and that YY (inverted) equals YY', and that either AA equals this IRK!'s device address or AA equals 0xFF (the broadcast address). If all of the above is true, then IRK! can be fairly sure that it is a valid command and will act upon it.

Infrared Transmission Technique

IRK! uses Pulse Width Modulation (PWM) to encode the series of 1's and 0's that constitute each command. You could reprogram the microcontroller to use a different technique such as Manchester Encoding but PWM works just fine. For example, the USB '1' key when encoded using PWM looks like the image above.

Whenever the signal is "low", an IR burst of pulses at 38 kHz is being transmitted. Conversely, when the signal is "high" it represents a period of silence.

There is a leading burst for 1000 μs then silence for 600 μs (in versions of IRK! prior to 2.04, it was 9400 μs and 4500 μs respectively). This leading burst was required by older infrared receiver modules to "train" their Automatic Gain Control (AGC) circuits so that they could determine what a normal signal level was. Today's IR receivers don't usually have this requirement, but your learning remote may be old so IRK! still supports it.

Thereafter, a '1' is encoded as a short burst followed by a long silence, and a '0' is encoded as a short burst followed by a short silence.

Broadcast Address

An address byte of 0xFF is recognised by all IRK! devices that you may have built. So it is possible for a single remote control to send a command to ALL IRK! devices simultaneously.

System Control Commands

IRK! also supports the USB-defined "System Control" commands called "Sleep", "Wake" and "Power Off". Some USB keyboards have keys for these functions, but they are not intrinsically keyboard functions. Any suitably programmed USB device, such as IRK!, can send USB System Control commands to your PC to request it to go into "Sleep" mode, for example. The following is a summary of the results of the System Control commands on my PC (your mileage may vary):

Power Off = CPU off, Disk off, Monitor off, USB off
Sleep = CPU on, Disk off, Monitor off, USB on
Wake = Does not work!
Power Switch Pressed = CPU off, Disk off, Monitor off, USB on

Consumer Device Commands

IRK! supports the USB-defined "Consumer Device" commands such as "Mute", "Vol+", "Vol-", "Calculator", "Browser Home", You can use these commands to control your Media Player (play/pause, stop, skip back, skip forward etc) or start applications (Calculator, Browser, Media Player etc).

For a complete list of the Consumer Device commands that you can use, just download the USB Human Interface Device Usage Tables document. That sounds complicated, but the specification is not that hard to read. Specifically, look at Table 17 "Consumer Usage Page". It does not matter that IRK! does not display the names of all these commands as you scroll through them, you can still ask IRK! to send them to your USB host (e.g. Linux, Windows, MythTV etc) - and the USB host should execute the corresponding function.


Power Switch and Reset Switch Commands (experimental)

Astute readers will have noticed that there is a problem with trying to get IRK! to "Power On" your PC - because not all PCs supply power to USB devices all the time when the system power is off and IRK! depends on power being provided by the USB interface of the system it is connected to.

A way around this is to power the IRK! circuitry from the "Standby" voltage (Vsb) from the PC power supply. Vsb on older computers supplies +5V at around 10 mA even though you have powered your PC off. More recent ATX power supplies can deliver Vsb at 2A. This means that, if powered from Vsb, IRK! can stay awake listening for IR commands as long as the PC is plugged into the wall power outlet. The IRK! circuit caters for pressing the Power and Reset buttons on your PC, but you will have to somehow tap into the Vsb output from your PC's power supply to get it to work. I don't know of any motherboards that have a readily accessible header pin for Vsb. This means that if you want this function, then you may have to physically break the Vsb wire from the PC power supply. The Vsb wire should be the purple wire.

Note that powering IRK! from Vsb has not been tested at the moment, but should work in principle. The Power Switch and Reset Switch functions do work as long as IRK! is powered from USB though.

How to Use It

Using IRK! is easy...all you need to do is:

Understanding The LCD Display Format

The LCD display shows information in the following format for the Keyboard usage:

0x modifiers
yy command
Where,
0 = The usage code meaning Keyboard
x = The key modifier bits in hexadecimal (e.g. 7 )
modifiers = A textual explanation of the key modifier bits (e.g. CTL ALT SHIFT)
yy = The USB key code in hex (e.g. 2A is Backspace)
command = A textual explanation of the command (e.g. Enter)
...and in the following format for the other usages (Consumer Device, System Control):

uy usage
yy command
Where,
u = The usage code in hex (1 = System Control, 2 = Consumer Device, F = IRK local function)
usage = A textual explanation of the usage code (e.g. Consumer Dev)
yyy = The command code in hex split over two lines (ranging from 000 to FFF, so only 4096 commands are possible)
command = A textual explanation of the command (e.g. Mute)
The following usages (i.e. the "u" in the above) are currently supported:
0 = Keyboard (Enter, etc)
1 = System Control (Power on, sleep, wake etc)
2 = Consumer Device (Mute, Vol+, Vol-, etc)
F = Local IRK! function
Programming Your Learning Remote

  1. Connect IRK! to an internal USB header on PC's motherboard. If you have chosen to build IRK! with a standard USB A-B cable, then just plug it into a normal external USB port.
  2. Wait for IRK! to indicate "USB Ready" on its LCD display. The activity LED will flicker while IRK! is trying to establish USB communications with your PC.
  3. Using IRK!'s UP, DOWN, CTL, ALT and SHIFT buttons, select a key combination that you want to send to your PC - for example, Ctrl+Home. The CTL, ALT and SHIFT buttons toggle between "pressed" and "not pressed" each time you press them. The CTL button, when pressed for more than 1 second, toggles the GUI indicator. TIP: Press and hold the UP or DOWN buttons to cycle through the available keystrokes quickly.
  4. Press IRK!'s OK button to send the key combination to your PC to test that it works.
  5. Set your learning remote to "Learn" mode and select a button to be programmed on your remote.
  6. Press IRK!'s TEACH button to transmit an IR code representing that key combination to your learning remote.
  7. Set your learning remote to "Normal" mode and press the newly programmed button on your remote.
  8. Watch as IRK! sends that key combination to your PC. IRK! will flash the activity LED each time it recognises a keystroke and it will display the last keystroke received on its LCD display.
  9. Rinse, and repeat from step 3 as many times as you need!


To select a usage other than Keyboard (e.g. Consumer Device):

  1. Press and hold the SHIFT button for more than 1 second until "Select Usage" is displayed on the LCD
  2. Press the UP or DOWN buttons until the desired usage is displayed (e.g. Consumer Dev)
  3. Press OK to use functions in that usage
  4. Press the UP or DOWN buttons until the desired function is displayed (e.g. Mute)
  5. Press OK to send the function to your PC to determine if it supports that particular function.
  6. If the PC responds as expected, press TEACH to program that function onto a button on your learning remote control.



Using Your Remote

This is the same as using any remote. Press a button and IRK! will respond to commands addressed to it. The most recent command actioned will be displayed on the LCD. If the Activity LED on the front panel flashes, then IRK! has recognised the command and has passed it onto the PC. If nothing happens after that then that's the fault of the PC. If the Activity LED does NOT flash, then IRK! has not recognised the IR code programmed onto that button - your IR remote might have a flat battery, or the maybe the code wasn't programmed accurately, or maybe you're standing too far away from the IRK! device.

Setting The IRK! Device Address

By default, IRK! will power up using a device address of 0xAA. If you build more than one IRK! unit, and want to address them individually, then you will have to set a unique address on each one. An IRK! device address can be in the range 0x00 to 0xFE (0xFF is the broadcast address to which all IRK! devices will respond). To do this:

  1. Press the UP/DOWN buttons until the command "00 Set Address" appears on the LCD display.
  2. Press OK to enter "Set Address" mode.
  3. Press the UP/DOWN button until the desired address is displayed in the mm field.
  4. Press OK to save the new address and exit "Set Address" mode.


From then onwards, that IRK! device will remember the new address in its on-board non-volatile memory (EEPROM). If you have taught your learning remote control any commands using the old address, then you may need to re-program it from the IRK! with the new address.

System Control Commands

The following three commands correspond to the USB System Control commands:

  • 02 01 Power Off - This will place your PC into system power state S5 (completely powered off)
  • 02 02 Sleep - This will place your PC into system power state S3 (suspend to RAM)
  • 02 03 Wake - This will wake your PC from S3 and return it to state S0 (powered on)


Experimental Power Control Commands

For the Through Hole Technology (THT) version of IRK!, the following (non-USB, local to IRK!) commands are experimental (i.e. not fully tested) and may need the IRK! device to be powered from your PCs standby voltage (Vsb):

  • FF 01 Power Switch - This is equivalent to pressing the POWER button on your PC. The action taken depends on how you have configured your PC
  • FF 02 Reset Switch - This is equivalent to pressing the RESET button on your PC. Use this with the same amount of caution that you normally apply when using the real RESET button on your PC! You have been warned.

For the Surface Mount Technology (SMT) version of IRK!, this list of commands has been extended and control the operation of the 4066 CMOS Quad Bilateral Analog Switch:

  • F0 01 Power Switch - The two header pins marked PWR will become low impedance for about 250 ms. Note: this is not meant to switch large currents. The 4066

    quad analog switch can pass an absolute maximum of only +/- 25 mA.

  • F0 02 Reset Switch - The two header pins marked RST will become low impedance for about

    250 ms.

  • F0 03 Init USB - Causes the unit to re-register itself as a USB device. It is

    almost the equivalent of unplugging and replugging the device

    into a USB port.

  • F0 07 Debug on - Displays debug information on the LCD when an IR code is received
  • F0 08 Debug off - Returns the unit to Normal mode (displays no debug information on the LCD)
  • F0 09 Auxiliary Switch - The two header pins marked AUX will become low impedance for about

    250 ms.

  • F0 0A Power Switch On - The two header pins marked PWR will become low impedance until a

    subsequent Power Switch Off command is received.

  • F0 0B Reset Switch On - The two header pins marked RST will become low impedance until a

    subsequent Power Switch Off command is received.

  • F0 0C Auxiliary Switch On - The two header pins marked AUX will become low impedance until a

    subsequent Power Switch Off command is received.

  • F0 0D Power Switch Off - The two header pins marked PWR will become high impedance.
  • F0 0E Reset Switch Off - The two header pins marked RST will become high impedance.
  • F0 0F Auxiliary Switch Off - The two header pins marked AUX will become high impedance.

Note that although the header pins are labelled PWR, RST and AUX you can use them for any function that would normally use a low current (< 25 mA) Single Pole Single Throw (SPST) momentary action push button switch.