Two Way Arduino IR Communication Problem

Hello,

I have two Mega's. The first with an IR Transmitter Module with DAT plugged into PIN 9.

First Mega Code:

#include <IRremote.h>

IRsend irsend;

void setup()
{
}

void loop() {

irsend.sendRC5(0x0, 8); //send 0x0 code (8 bits)
delay(2000);

irsend.sendRC5(0x1, 8);
delay(2000);
}

Second Mega has an IR Receiver Module with DAT plugged into PIN 11 and another IR Transmitter Module with DAT plugged into PIN 9.

Second Mega Code:

#include <IRremote.h>

int IRSend_pin = 9;
int IRRecv_pin = 11; // pin for the IR sensor
int LED = 13; // LED pin
IRrecv irrecv(IRRecv_pin);
decode_results results;
IRsend irsend;

void setup()
{
Serial.begin(9600);
pinMode(IRSend_pin, OUTPUT);
irrecv.enableIRIn(); // Start the receiver
pinMode(LED, OUTPUT);
}

void loop()
{
if (irrecv.decode(&results))
{
digitalWrite(LED,HIGH);
irsend.sendRC5(0x0, 8); //send 0x0 code (8 bits)
delay(2000);
irsend.sendRC5(0x1, 8);
delay(100);
digitalWrite(LED,LOW);

irrecv.resume(); // Receive the next value

}

}

FYI these are sample codes that I have found on the internet that I tweaked a bit.

The Problem:

I want the first Mega Transmitter to send a signal to the Receiver on the Second Mega. And when that Receiver gets the signal I wan the second Transmitter on the second Mega to send off a signal. It works for two loops and then stops.

If anyone knows what is going on your help would be greatly appreciated.

Thanks you

8 ) ; in place of the sunglasses emoji

Allow me to explain better. The first Mega code is working great. The issue is with the second. The code loops once and works, but after that is stops receiving the IR signal from the first Mega. Why does it only work once?

Figured it out. Case closed

I may have a similar issue. What was the culprit to your problem?

Thanks.