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);
}
}
}
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.
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 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*
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);
}