Hi all, I just found a solution to a question which has been asked before and has been bothering me for quite some time. When using the IRremote library on an Arduino, you can not send and receive in the same program it seems at first. The trick is to put a delay of 400 ms between receiving a signal and sending a new one. Also see this topic: IR Remote Send/Receive from the same Arduino - Troubleshooting - Arduino Forum
Here's an example:
#include <IRremote.h>
#include <IRremoteInt.h>
#define SEND_DELAY 100
#define RECEIVE_SEND_DELAY 400
enum ziggoRemote
{
ziggoPower = 2060,
ziggoPower2 = 12,
} ZiggoRemote;
enum wingLedStrip
{
wingLedStripType = NEC,
wingLedStripLength = 32,
wingLedStripOn = 16203967,
} WingLedStrip;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
IRsend irsend;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (receiveSignal())
{
sendSignal();
}
}
bool receiveSignal()
{
if (irrecv.decode(&results))
{
switch (results.decode_type)
{
case SONY:
Serial.println("SONY");
break;
case NEC:
Serial.println("NEC");
break;
case RC5:
Serial.println("RC5");
break;
case RC6:
Serial.println("RC6");
break;
default:
break;
}
Serial.println(results.value);
Serial.println(results.bits);
irrecv.resume(); // Receive the next value
return true;
}
return false;
}
void sendSignal()
{
switch (results.value)
{
case ziggoPower: case ziggoPower2:
delay(RECEIVE_SEND_DELAY);
irsend.sendNEC(wingLedStripOn, wingLedStripLength);
break;
default:
break;
}
delay(SEND_DELAY);
Serial.println("Signal send");
irrecv.enableIRIn();
}
Thought I'd quickly share it with you for the guys out there struggling with this like I was.