Help with Infrared

Hi, I’ve been trying to make a laser tag system with my 2 aArduinos for some time now but I haven’t been having a lot of success. So I’ve tried to go back to basics, with 1 Arduino waiting 3 seconds and then sending an infrared signal and another receiving the signal and turning on an LED in pin 12. At the moment the sender doesn’t send the signal (we used a camera that could see IR to find out) and the receiver waits a random amount of time. If you could please help me to fix this so I could try and implement it that would be really helpful.

The library I used

Recieve Code

#include <IRremote.h>
#include <IRremoteInt.h>

IRsend irsend;
const int LED = 12;
const int BUTTON = 10;
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() 
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(RECV_PIN, OUTPUT);
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT); 
}

void loop() 
{
//sending IR

//recieiving IR
  if(recieveIR)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
}

//  ()=================|| INFRARED RECIEVE ||=================() \\
// this is the infrared recieve, again I don't understand it very well and my friend
bool recieveIR()
{
  //if (irrecv.decode(&results))
  if (irrecv.decode(&results) != 0) 
  {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    return true;
  }
  return false; 
}

Send code

#include <IRremote.h>
#include <IRremoteInt.h>

IRsend irsend;
const int LED = 12;
const int BUTTON = 10;

void setup() 
{
Serial.begin(9600);
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT); 
sendIR();
}

void loop() 
{

}

//  ()=================|| INFRARED SEND ||=================() \\  
//this is the code for infrared sending, I don't completely understand this and my friend helped me with it
void sendIR()
{
   if (Serial.read() != -1)
   {
      for (int i = 0; i < 3; i++)
      {
        irsend.sendSony(0xa90, 12); // Sony TV power code
        
      }
   }
}

I assume your using an I2C interface to your sender, and the irsend.sendSony(0Xa90, 12) is supposed to be a hex address, followed by a command. The address in that case would not look like 0Xa90, but maybe more like 0X90. Better go check that step.

Your receive code has (at least) two major errors

  pinMode(RECV_PIN, OUTPUT);  // for the receiver?
  if (recieveIR)  // check address of function, this will always be true

...better...

  if (receiveIR())   // call the function

Your receive logic will flash the led for a very short time, could be hard to see.

Your send does sends something only when serial input is available. So early in startup this will probably never be the case and you only try it once from setup.

Whandall: Your receive code has (at least) two major errors

  pinMode(RECV_PIN, OUTPUT);  // for the receiver?
  if (recieveIR)  // check address of function, this will always be true

...better...

  if (receiveIR())  // call the function



Your receive logic will flash the led for a very short time, could be hard to see.

Your send does sends something only when serial input is available.
So early in startup this will probably never be the case and you only try it once from setup.

Thanks, I'll fix and test those as soon as I can