i'm currently in the process of hacking IR signals from a remote control. i'm reading the signal coming from the remote with a light sensitive resistor and i'm trying to store the timing of the signal. i've programmed a simple for loop, which increments a counter for every loop, and then stores the counter values when the light sensor goes from high to low or the other way around. that way mapping the signal coming from the remote.
but this gives unstable results - they differ a lot - even if i push the same button under controlled light surroundings.
it seems to me, that i need a more reliable way of keeping track of time (in microsenconds or smaller)
is there a timer function for the arduino board?
is there a manual/list of commands for the arduino board?
I have the same aim. I'm trying to compare the binary patterns from a IR Sensor (the ones with 3 pins: GND, +5V and digital out) gives me (i have a Yamaha remote).
I set up an external interrupt service routine, that's listening on pin 8 (the only pin that can do that on an arduino board). My first approach was just to count the number of pulses, but it was allways 36 - completley independet form which button I pressed.
So my second attempt was to meassure the time form edge to edge of each pulse. But i still can't distinguish which button get's pressed. I looks like the timing/period of the counting timer is set too short in my case (change of timer1's prescaler could be a solution).
I have not looked into that, I currently suspended this project. See my code only as a rough sketch...
int irPin = 8;
int somethingHappend = 0;
int count = 0;
int timeL;
int timeH;
unsigned long pattern[40]; //to store the binary pattern
int i;
void irHandler(void){
// external interrupt service routine
timeL = ICR1L; // read time since last reset
timeH = ICR1H;
pattern[count]= (timeH << 8 ) | timeL;
//pattern[count] = millis(); //another attemp, I don't which is more clever
count++;
somethingHappend = 1;
}
void printLong(unsigned long n)
// that is just the new printInteger function copied from the arduino 0004 svn source
{
unsigned long base = 10;
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
unsigned long i = 0;
if (n == 0) {
printByte('0');
return;
}
while (n > 0) {
buf[i++] = n % base;
n /= base;
}
for (; i > 0; i--)
printByte(buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10);
}
void setup() {
pinMode(irPin, INPUT);
pinMode(ledPin, OUTPUT);
beginSerial(9600); // connect to the serial port to send values back
TCNT1H = 0; // reset TCNT1
TCNT1L = 0;
TIMSK |= _BV(TICIE1); //enable external interrupt for Timer1
timerAttach(TIMER1INPUTCAPTURE_INT, irHandler); //attach service routine
}
void loop() {
if(somethingHappend){
delay(500); //make shure we wait till the whole pattern for one button press is passed completley!
TCNT1H = 0; // reset TCNT1
TCNT1L = 0;
count = 0;
somethingHappend = 0;
}
delay(500); //wait to not overload the serial connection if nothing happend
// print the last pattern
for (i=0; i < 40; i++){
printLong(pattern[i]);
printString(" ");
}
printNewline();
}
note that you can't use PWM/analogWrite() now, because timer1 would then be used for 2 things, what is not possible.
Here is a nice page that shows how to record the IR sensor binary pattern with any soundcard: http://people.inf.ethz.ch/mringwal/lirc/
I think, one should really look into how the IR Remote protocol is constructed. Any hints?