Infrared send and recieve

Hello everyone,

I have a work project involving IR. I’m suppose to send and receive IR signal with the same arduino. For sending and reciving i’m using the IRremote library, an IR receiver and an IR transmitter.
The library works perfectly when i’m using one arduino to send, and another to receive.

But when I implement the code for both receiving and sendind, I blocks on sending. That’s my code

#include <IRremote.h> // Include the library

int RECV_PIN= 11; //Pin of the receiver
IRrecv irrecv(RECV_PIN); // Start the reciever

decode_results results; 
IRsend irsend;

int incomingByte=0; 

void setup(){
  irrecv.enableIRIn(); // enables the reciver

void loop (){
    Serial.println(results.value,HEX); // decodes results
  if (Serial.available() > 0){
    incomingByte=; // if i send 1, start isend

void isend(){
  for (int i = 0; i < 3; i++) {
   irsend.sendSony(0xa90, 12); // Sony TV power code

Until I don’t send 1 to the port com, it receives IR perfectly, but when I send 1 to com, it send an IR signal but does not stop sending it. I would like to send an IR signal for a given time then go back to receiving IR.

Do anyblody has an idea ? My work project is blocked until I find a solution.

Thanks in advance

IR receiver :
IR transmitter :
Arduino used :

Replace assignment:


by comparison:

      if(incomingByte == 49){

MarkT: Replace assignment:


by comparison:

      if(incomingByte == 49){

I already did and it didn't work. That's why I changed it. It just can't stop sending the IR signal.