All,
I found some code online for taking codes from a Sony remote control using a Radio Shack IR module:
however, I did not see anything on the NEC protocols like Samsung. Essentially the difference is that the bit is encoded by the time delay between pulses rather than by the pulse length itself. I'm offering up the code that I developed for this purpose. In my case I'm grabbing codes from a Samsung DVD player remote. Altering the code for other NEC type protocols should not be difficult.
The protocol I hacked is not published and I really have no clue if the 16 bits I'm grabbing at the end are reversed or not. I have a feeling they are not. Either way I'm getting a unique code for every button on my control so that's good enough for me.
/*
- Samsung Decoder
- This code shows how to grab serial information from a Samsung
- remote control which uses a variation of the NEC ir protocol
- Currently the code is grabbed from the last two bytes recieved.
- The first two bytes are addressing information that does not vary.
- There is a ridiculously slim chance that this code could fail every
- seventy minutes when the microseconds reset. The odds of this
- happening do not justify the overhead of validation.
*/
#define IR_PIN 2
long start;
unsigned int code = 0;
void setup()
{
pinMode(IR_PIN, INPUT);
delay(1000);
Serial.begin(9600);
}
void loop()
{
code = 0;
while (pulseIn(IR_PIN, LOW) < 9000) {} //wait for start pulse
while(digitalRead(IR_PIN) == HIGH) {}
start = micros();
for (int x = 0; x < 32; x++)
{
while(digitalRead(IR_PIN) != HIGH) {}
while(digitalRead(IR_PIN) != LOW) {}
if (x > 15)
{
code |= ((micros() - start) > 1900) << (x - 16);
}
start = micros();
}
//Do Something with the code
Serial.println(code);
}