IR send RAW

Hello,

First of all: Please bear with me, I'm a beginner :slight_smile:

I created a sketch to receive a code from an IR remote.

The code is:

  • 551502015
  • (HEX):20DF40BF

Code to RECEIVE:
#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

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

void loop()
{
if(irrecv.decode(&results))
{
Serial.print("Received: ");
Serial.println(results.value);
Serial.print("Received (HEX):");
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}

Now I'd like to send this code back to my TV. It is important to you to know that I would like to be able to "mirror" any kind of code. Predefined libraries like "irsend.sendSony" is not an Option.

Based on some Posts on the web I created the below sketch. I think I do not entirely understand that unsigned int bit. In all examples I looked into people using Arrays containing multiple codes. But I do only have one. It doesn't work, the LED does not even illuminate or it's too short to see via my digital camera. The irsend.sendSony code I can see btw.

Your help is much appreciated!! ;D

Code to SEND:
#include <IRremote.h>
IRsend irsend;

unsigned int rawCodes[1] = {551502015};

void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.read() != -1) // Send anything via serial to send signal
{
for (int i = 0; i < 3; i++)
{
irsend.sendRaw(rawCodes, 1, 38); // 38 = kHz
//irsend.sendSony(0xa90, 12); // Sony TV power code
delay(100);
}
}
}

unsigned int rawCodes[1] = {551502015};

551502015 will not fit into an int, signed or otherwise.

unsigned int rawCodes[] = {5,5,1,5,0,2,0,1,5};
for (int i = 0; i < 9; i++)
    {
      irsend.sendRaw(rawCodes[i], 1, 38); // 38 = kHz
      //irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(100);
    }

would make more sense, but still might not be right.

ChrisVH1982:
1502015

  • (HEX):20DF40BF

Now I'd like to send this code back to my TV. It is important to you to know that I would like to be able to "mirror" any kind of code. Predefined libraries like "irsend.sendSony" is not an Option.

You have to note which of the supported data formats the receiver recognized. You can find that value in "results->decode_type". You would then use that value to determine which irsend.sendXxxx() function to call to send it out:
NEC, SONY, RC5, RC6, PANASONIC, LG, JVC, or UNKNOWN

For "UNKNOWN" you have to store a large array of RAW data and play that back.
For PANASONIC you need to store results->panasonic_address in addition to results->value.

Thank you both for replying! The for Loop does not work out unfortunately.

About decode_type: I get "1" or "-1" out and I tested using an LG, Panasonic and Dreambox remote.

if(irrecv.decode(&results))
{
Serial.println("Results:");
Serial.println("------------------");
Serial.print("Received: ");
Serial.println(results.value);
Serial.print("Received (HEX):");
Serial.println(results.value, HEX);
Serial.print("Decode type:");
Serial.println(results.decode_type);
Serial.print("Number of items:");
Serial.println(results.rawlen);
Serial.println("");
irrecv.resume();
}

Results:

Received: 551502015
Received (HEX):20DF40BF
Decode type:1
Number of items:68

Update:

When I add the following condition Returns "NEC" for my LG TV and "UNKNOWN for my PANASONIC remote. However, I prefer RAW because I would like to also mirror other, non TV, signals.

if(results.decode_type == NEC)
{
Serial.println("NEC");
}
(...)

Results:

Received: 551502015
Received (HEX): 20DF40BF
Decode type: 1
Decode type: NEC
Number of items: 68

If you must go with RAW signals, look at this article:

That will let you uniquely recognize each RAW input.

To send outputs you also need to store the RAW data which can take up 152 bytes. You can only store about 10 of those codes in RAM so you may find you need to use some form of external memory like an SD card (if you want to add codes dynamically) or FLASH if you don't mind re-uploading the sketch to add new codes.

hey guys, i'm stuck on the same problem.
i need to transfert data over IR from one arduino to other, and i think i need to use sendRaw but i really didn't understand this function exactly, well the code that UKheliBOB posted looks logic but still need some explanation
why i<9 and if using sendRaw why using sendSony ?

for (int i = 0; i < 9; i++)
{
irsend.sendRaw(rawCodes*, 1, 38); // 38 = kHz*

  • //irsend.sendSony(0xa90, 12); // Sony TV power code*
  • delay(100);*
  • }*
    i wanna thank mr John for the link it's really useful
    but my problem still in how to use sendRaw if there is any help pls..
for (int i = 0; i < 9; i++)  //there are 9 elements in the array numbered from 0 to 8, hence keep going whilst < 9
    {
      irsend.sendRaw(rawCodes[i], 1, 38); // 38 = kHz
      //irsend.sendSony(0xa90, 12); // Sony TV power code //this line is commented out so is effectively not there.
      delay(100);
    }

oh thanks bro i was searching for this function explanation for days

Hi guys, I have problems with the IR Library, too. I can receive data but have no idea how to send data and that´s what I mainly want to do...

when I use this code:

  Serial.println("Results:");
  Serial.println("------------------");  
  Serial.print("Received: ");
  Serial.println(results.value);
  Serial.print("Received (HEX):");
  Serial.println(results.value, HEX);
  Serial.print("Decode type:");
  Serial.println(results.decode_type);   
  Serial.print("Number of items:");
  Serial.println(results.rawlen); 
  Serial.println("");

I get this output:

Results:
------------------
Received: 16712445
Received (HEX):FF02FD
Decode type:3
Number of items:68

So I have no idea what decode type 3 is and therefore no ide how to send the received data "FF02FD". Any help is very appreciated

Run the IRrecvDumpV2 example to get the full information.

You can find the decode type enumeration in IRremote.h:

typedef
	enum {
		UNKNOWN      = -1,
		UNUSED       =  0,
		RC5,//1
		RC6,//2
		NEC,//3
		SONY,//4
		PANASONIC,//5
		JVC,//6
		SAMSUNG,//7
		WHYNTER,//8
		AIWA_RC_T501,//9
		LG,//10
		SANYO,//11
		MITSUBISHI,//12
		DISH,//13
		SHARP,//14
		DENON,//15
		PRONTO,//16
	}
decode_type_t;

(Comments added to make the numbers more readable.)