IR Remote Decoder
Background
I wanted to control my little robot without electric string to a PC so put this together using the IR receiver from Cool Components http://www.coolcomponents.co.uk/catalog/product_info.php?cPath=36&products_id=169.
Tech Stuff
The output from the IR device inputs to Mbed pin 20 and was monitored by an oscilloscope. Triggering on the first transition of sequence (-ve edge), the time to the first data pulse and the pulse period was figured out. Mbed pin 19 was configured as a strobe output for the scope coincident with a read on pin 20. Mbed reads my Sky+ remote happily as well as a redundant Philips DVD remote. The time to the first data pulse (porch) is different for each remote but the pulse period is the same in both remotes so the code required is unique for each remote. This is configurable before compile time and is obvious in the code. I haven't bothered (yet) to decode the device address data as I only intend to use one remote at a time! It responds incorrectly to wrong one, naturally.
Photo
The photo shows the Mbed driving both an led display and a Nokia 6610 lcd screen with the DVD remote.
The Code
The code includes the scope output stuff commented out in case you want to decode your own remote. There is probably a really neat way of compressing the code but I like Quick and Dirty and to be able to understand it tomorrow! To find out where all the numbers came from, have a look at RemoteReader.
// SKY+ Remote IR Interface with Mbed Author: Andrew Young
//
//By connecting an IR sensor (Coolcomponents IR Breakout) to mbed, remote control
//codes can be read. I chose SKY+ because it is relatively common and has plenty
//of buttons. For my own use I include Philips DVD remote parameter.
//The program only decodes the data segment of the bit stream, not the device
//address bits, so it can be confused by other remotes. I used a scope to get the
//read strobes in the right place but it may be possible by trial and error (lots).
//Tried using an IR proximity detector (much smaller) but problems with sensitivity
//and interference, but it almost works reliably. In development.
#include "mbed.h"
#include "MobileLCD.h"
MobileLCD lcd(5, 6, 7, 8, 9);
DigitalOut led1(21); // used a Maplin 10 led display for this, much easier
DigitalOut led2(22);
DigitalOut led3(23);
DigitalOut led4(24);
DigitalOut led5(25);
DigitalOut led6(26);
DigitalOut led7(27);
DigitalOut led8(28);
DigitalOut led9(29);
DigitalOut led10(30);
DigitalOut Pulse(19); // strobe out for scope
DigitalIn IRin(20); // IR sensor input from Coolcomponents IR Breakout
int porch; // time from first pulse edge until data read
int interval; // interval between pulse strobes
int gap; // gap between pulse trains to start if() during IR Hi
int code; // value of received key, 0 key detected if = 0
int main() {
lcd.background(0x0000FF);
lcd.cls();
while(1) {
porch = 15700; //Philips DVD = 15700, Sky+ = 19000
interval = 800; //Philips DVD = 800, Sky+ = 800
if(IRin==0) {
code = 0;
led1 = 0; led2 = 0; led3 = 0; led4 = 0; led5 = 0;
led6 = 0; led7 = 0; led8 = 0; led9 = 0; led10 = 0;
// Pulse = 1; wait_us(10); Pulse = 0; //start pulse for scope use
wait_us(porch);
// Pulse = 1; wait_us(10); Pulse = 0; //128 bit strobe for scope use
if (IRin == 1) {led8 = 1; code = code + 128;}
wait_us(interval);
// Pulse = 1; wait_us(10); Pulse = 0; //64 bit strobe for scope use
if (IRin == 1) {led7 = 1; code = code + 64;}
wait_us(interval);
// Pulse = 1; wait_us(10); Pulse = 0; //32 bit strobe for scope use
if (IRin == 1) {led6 = 1; code = code + 32;}
wait_us(interval);
// Pulse = 1; wait_us(10); Pulse = 0; //16 bit strobe for scope use
if (IRin == 1) {led5 = 1; code = code + 16;}
wait_us(interval);
// Pulse = 1; wait_us(10); Pulse = 0; //8 bit strobe for scope use
if (IRin == 1) {led4 = 1; code = code + 8;}
wait_us(interval);
// Pulse = 1; wait_us(10); Pulse = 0; //4 bit strobe for scope use
if (IRin == 1) {led3 = 1; code = code + 4;}
wait_us(interval);
// Pulse = 1; wait_us(10); Pulse = 0; //2 bit strobe for scope use
if (IRin == 1) {led2 = 1; code = code + 2;}
wait_us(interval);
// Pulse = 1; wait_us(10); Pulse = 0; //1 bit strobe for scope use
if (IRin == 1) {led1 = 1; code = code + 1;}
if (code == 0) led10 = 1; //"0" code recognition
lcd.cls();
lcd.locate(2,3);
lcd.printf("%hu",code);
}
}
}
Development
This IR sensor is too big for my robot so I'm investigating using an IR proximity sensor as an IR input. This doesn't have demodulation and level clamping so is a bit sensitive to ambient lighting, distance and direction of the remote and probably other stuff I have yet to find out about.
p.s. My robot doesn't use Mbed but this is a brilliant Proof of Concept and development tool for other platforms (AVR).
Attachments
- ir decoder 2.jpg (33.4 kB) - added by ayoung@… 17 months ago.

