i'm currently experimenting with both the IRLib2 (GitHub - cyborg5/IRLib2: Library for receiving, decoding, and sending infrared signals using Arduino) and IRRemote v 4.4.1.
i've successfully managed to send IR signals using the IRLib2 library with the following sketch:
#include <IRLibRecvPCI.h>
#include <IRLibSendBase.h> //We need the base code
#include <IRLib_HashRaw.h> //Only use raw sender
IRsendRaw mySender;
IRrecvPCI myReceiver(2);//pin number for the receiver
void setup() {
Serial.begin(9600);
delay(2000); while (!Serial); //delay for Leonardo
myReceiver.enableIRIn(); // Start the receiver
Serial.println(F("Ready to receive IR signals"));
}
#define RAW_DATA_LEN 68
uint16_t rawData[RAW_DATA_LEN]={
9022, 4598, 542, 570, 534, 602, 534, 606,
534, 602, 534, 602, 534, 606, 566, 570,
530, 606, 538, 1734, 546, 1682, 566, 1682,
566, 1682, 566, 1678, 570, 1682, 566, 1706,
542, 1706, 542, 1682, 566, 570, 534, 1714,
566, 570, 510, 630, 530, 606, 534, 1718,
562, 570, 538, 602, 562, 1710, 542, 570,
566, 1682, 566, 1706, 542, 1706, 542, 570,
542, 1730, 542, 1000};
void loop() {
//Continue looping until you get a complete signal received
mySender.send(rawData,RAW_DATA_LEN,38);//Pass the buffer,length, optionally frequency
if (myReceiver.getResults()) {
Serial.println(F("Do a cut-and-paste of the following lines into the "));
Serial.println(F("designated location in rawSend.ino"));
Serial.print(F("\n#define RAW_DATA_LEN "));
Serial.println(recvGlobal.recvLength,DEC);
Serial.print(F("uint16_t rawData[RAW_DATA_LEN]={\n\t"));
for(bufIndex_t i=1;i<recvGlobal.recvLength;i++) {
Serial.print(recvGlobal.recvBuffer[i],DEC);
Serial.print(F(", "));
if( (i % 8)==0) Serial.print(F("\n\t"));
}
Serial.println(F("1000};"));//Add arbitrary trailing space
myReceiver.enableIRIn(); //Restart receiver
}
}
The solution was removing BJT base resistance.
This works well for sending signals; however, the raw data I receive is slightly different in length and pattern compared to the original transmission. For example, the received data might look like:
#define RAW_DATA_LEN 100
uint16_t rawData[RAW_DATA_LEN]={
9106, 4754, 498, 658, 522, 658, 522, 686,
522, 666, 518, 682, 522, 670, 566, 626,
526, 670, 538, 1810, 530, 1786, 522, 1786,
550, 1786, 550, 1750, 562, 1786, 522, 1814,
522, 1786, 526, 1786, 550, 630, 526, 1810,
550, 638, 490, 714, 498, 714, 490, 1814,
550, 630, 522, 686, 550, 1794, 514, 666,
542, 1766, 546, 1814, 522, 1782, 526, 634,
522, 1814, 522, 1070, 9222, 4706, 518, 630,
522, 662, 522, 690, 490, 686, 494, 686,
498, 682, 550, 634, 522, 658, 522, 1814,
522, 1762, 546, 1750, 534, 1790, 522, 1766,
542, 1754, 530, 1000};
Do you have any clue on that?
I also attempted to use the IRRemote library. However, I encountered confusion regarding which pin should control the BJT (even though I tried various PWM pins on the Arduino Mega).
Could you please help me?
For you reference, here is the sketch I'm using with the IRRemote library:
#include "IRremote.h"
int receiver = 2; // Signal Pin of IR receiver to Arduino Digital Pin 11
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver); // create instance of 'irrecv'
IRsend mySender;
//vairable uses to store the last decodedRawData
uint32_t last_decodedRawData = 0;
/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
{
// Check if it is a repeat IR code
if (irrecv.decodedIRData.flags)
{
//set the current decodedRawData to the last decodedRawData
irrecv.decodedIRData.decodedRawData = last_decodedRawData;
Serial.println("REPEAT!");
} else
{
//output the IR code on the serial monitor
Serial.print("IR code:0x");
Serial.println(irrecv.decodedIRData.decodedRawData, HEX);
}
//map the IR code to the remote key
switch (irrecv.decodedIRData.decodedRawData)
{
case 0xBA45FF00: Serial.println("POWER"); break;
default:
Serial.println(" other button ");
}// End Case
//store the last decodedRawData
last_decodedRawData = irrecv.decodedIRData.decodedRawData;
delay(500); // Do not get immediate repeat
} //END translateIR
void setup()
{
Serial.begin(9600);
Serial.println("IR Receiver Button Decode");
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
mySender.sendNEC(0xBA45FF00, 32);
if (irrecv.decode()) // have we received an IR signal?
{
translateIR();
irrecv.resume(); // receive the next value
}
}