How to correctly receive and send raw IR data from Arduino

Lemuel Adane picture Lemuel Adane · Mar 31, 2014 · Viewed 31k times · Source

Following is my code to read the raw IR data from Arduino:

#define sprint Serial.print 
#define sprintln Serial.println
#include <IRremote.h>

#define IR_RCVR_PIN 11
IRrecv ir_receiver(IR_RCVR_PIN);
decode_results results;

void setup() {
    Serial.begin(9600);
    ir_receiver.enableIRIn(); // Start the receiver
}

void loop() {
   if (ir_receiver.decode(&results)) {
    dump(&results);
    ir_receiver.resume(); // Receive the next value
   }
}

int c = 1;

void dump(decode_results *results) {
   int count = results->rawlen;
   sprintln(c);
   c++;
   sprintln("For IR Scope: ");
   for (int i = 1; i < count; i++) {
       sprint("0x");
       sprint((unsigned int)results->rawbuf[i], HEX);
    sprint(" ");
   }

   sprintln("");
   sprintln("For Arduino sketch: ");
   sprint("unsigned int raw[");
   sprint(count, DEC);
   sprint("] = {");
   for (int i = 1; i < count; i++) {
       sprint("0x");
       sprint((unsigned int)results->rawbuf[i], HEX);
       sprint(",");
    }
    sprint("};");
    sprintln("");
    sprint("irsend.sendRaw(raw,");
    sprint(count, DEC);
    sprint(",38);");
    sprintln("");
    sprintln("");
}

Using that I can get this from a remote controller:

1
For IR Scope: 
0x47 0x1F 0xB 0x17 0xA 0x17 0xB 0x6 0xA 0x6 0xB 0x6 0xA 0x17 0xB 0x6 0xA 0x6 0xB 0x17     
0xA 0x17 0xA 0x7 0xA 0x17 0xA 0x7 0xA 0x6 0xB 0x17 0xA 0x17 0xA 0x6 0xB 0x17 0xA 0x17    
0xB 0x6 0xA 0x6 0xB 0x17 0xA 0x6 0xB 0x6 0xA 0x17 0xB 0x6 0xA 0x6 0xB 0x6 0xA 0x7 0xA     
0x6 0xB 0x6 0xA 0x6 0xB 0x6 0xA 0x7 0xA 0x6 0xB 0x6 0xA 0x7 0xA 0x6 0xB 0x6 0xA 0x6 0xB    
0x6 0xA 0x7 0xA 0x6 0xB 0x6 0xA 0x6 0xB 0x17 0xA 0x6 0xB 0x6 0xA 

For Arduino sketch: 

unsigned int raw[100] =       
{0x47,0x1F,0xB,0x17,0xA,0x17,0xB,0x6,0xA,0x6,0xB,0x6,0xA,0x17,
 0xB,0x6,0xA,0x6,0xB,0x17,0xA,0x17,0xA,0x7,0xA,0x17,0xA,0x7,0xA,0x6,
 0xB,0x17,0xA,0x17,0xA,0x6,0xB,0x17,0xA,0x17,0xB,0x6,0xA,0x6,0xB,0x17,0xA,
 0x6,0xB,0x6,0xA,0x17,0xB,0x6,0xA,0x6,0xB,0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,
 0x6,0xB,0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,0x6,0xB,
 0x6,0xA,0x7,0xA,0x6,0xB,0x6,0xA,0x6,0xB,0x17,0xA,0x6,0xB,0x6,0xA,};

So on sending this data I can use this instruction:

irsend.sendRaw(raw,100,38);

The problem is I cannot get any respond from the device I need to control. I already check my IR transmitter my reading is the same above.

Im I missing something?

Answer

Lesto picture Lesto · Mar 31, 2014

You should take multiple reading of the signal, then average their values to remove little bias error. Be sure your emitter and receiver use the same light wavelength and to work at 38KHz (you are transmitting modulating at 38KHz. If your emitter does modulation for you, then you should not use IRremote).

Also, what do you expect as "response"? Normally, IR communication is one-way.