Infrared Keyboard

By Erez Shabat (Erezsh) and Hen Amar (Hen1610) both



The purpose of our Infrared-Keyboard project is to implement a remote control keyboard. An LPC2148 microcontroller will connect to the host computer via USB cable and identify itself as a keyboard. an infra-red sensor is connected to the LPC2148 Microcontroller via three pins:

-          First pin is connected to a power source on the board (3.3V).

-          Second pin is connected to ground.

-          Third pin is connected to pin P0.2 of the LPC2148 (We will later explain in more detail why this pin was chosen).



System Usage

The Sony remote control is used to simulate a keyboard connected to a PC.

Each key press on the remote control will translate to a key press in the virtual keyboard connected to the PC.

The project maps the number pad of the remote control to the keyboard numpad (It is possible to change/add other keys easily).




LPC2148 Education Board – The board is connected to the host computer via a USB interface and acts as a keyboard.

IR sensor - Connected  to the board on pin P0.2.

Remote control – We’re using a Sony remote control that corresponds to the Sony 12-bit SIRC Infra-Red Protocol (more info ahead).





Sony SIRC protocol

The info below is based on info from SB-Projects (with some changes).

SIRC Features:

·         12-bit, 15-bit and 20-bit versions of the protocol exist, most common is the 12-bit (this is the version we’ve implemented).

·         First 5-bits are for address and last 7-bits are for the command (total of 12-bits)

·         Pulse width modulation

·         Carrier frequency of 40kHz

·         Bit length varies between 1.8 (representing bit 1) and 1.2 (representing bit 0)


The SIRC protocol uses a pulse width encoding of the bits. The pulse representing a logical "1" is a 1.2ms long burst of the 40kHz carrier, while the burst width for a logical "0" is 0.6ms long. All bursts are separated by a 0.6ms long space interval.




The picture below shows a typical pulse train of the SIRC protocol. With this protocol the LSB is transmitted first. The start burst is always 2.4ms wide, followed by a standard space of 0.6ms. Apart from signaling the start of a SIRC message this start burst is also used to adjust the gain of the IR receiver. Then the 7-bit Command is transmitted, followed by the 5-bit Device address. In this case Address 1 and Command 19 is transmitted. Commands are repeated every 45ms(measured from start to start) for as long as the key on the remote control is held down.




Software (main parts of source code described)

We will describe the software from two aspects the Infra-Red (this is implemented by IR.c) and USB (which is implemented by usbhandler.c)

The sensor works inverted. It runs with a high idle. When it receives a signal the output pulses low. The program measures the pulse-widths and builds a 12-bit "word" in a buffer that contains the 7-bit command and a 5-bit address (which is 128 in our case when the Sony remote is set to “TV”).

Remote controls send every command several times (depends on the duration of the press). The program detects a change in voltage on pin P0.2 for a falling edge. The interrupt saves the timer counter value as “start” and sets an interrupt on rising edge. When an interrupt rises again, calculates the width of the pulse, processes it accordingly and sets to watch for a falling edge again. When IR.c detects 12 bits, it sets a flag (“done”) to let the main program know a packet is ready for its use.


·         USB – The usbhandler.c is responsible to implement USB functionality in our program. We’ve used the LPCUSB stack available here in order to implement the use of the USB. The usbhandler contains the USB descriptors (that identifies the connection as an HID - Interface Descriptor), which includes inside it the 5 standard USB descriptors (more info on

In addition, we defined a new descriptor named hid_report_descriptor that describes a keyboard device, and another descriptor named keyboard_in_report that describes the keyboard message send to the computer for every key(s) pressed.

The USB keyboard descriptors (also mouse and joystick) can be obtained here.

Information about the keyboard report structure and correct values in the HID protocol can be found here.



Download project (includes a solution file for Microsoft Visual Studio 2008 and a corresponding makefile).

Note: This was compiled and tested with WinARM Version 20060606.