IR remove project will only loops once.

Project: When IR receiver gets “pause” signal from TV remote it sends “mute” signal along with it to the TV thus muting the TV every time I pause it. That’s it.

All components work individually:

The IR led works. I can send the mute signal to the tv and it will loop over and over again.
The IR receiver works. I can record and display codes of every input from my TV remote.

What I cannot do is read the TV remote and execute the mute signal more than 1 time.

The trouble code has to be the “ir.sendRaw” in the following:

void sendMute()
{
  int khz = 38;
  unsigned int  muteSignal[] = {4550,4400, 600,1600, 600,1650, 550,1650, 600,500, 600,500, 600,500, 600,550, 600,500, 600,1600, 
                              600,1650, 550,1650, 600,500, 600,500, 600,500, 600,550, 600,500, 600,1600, 600,1650, 550,1650, 
                              600,1600, 600,550, 550,550, 600,500, 600,500, 600,500, 600,500, 600,550, 600,500, 600,1600,
                              600,1600, 600,1650, 600,1600, 600};
  ir.sendRaw(muteSignal, sizeof(muteSignal) / sizeof(muteSignal[0]), khz); 
}

My guess is the function is not exiting after it’s executed. I looked at the library and online and all over and I didn’t see anything other than just sendRaw with those parameters and that’s it.

Here is the complete code:

#include <IRremote.h>

#define PAUSE 0xD922D768  // Hex IR code for Pause (32 bites)

int recvPin = 11;  // IR reciever
int statusLed = 8;

IRrecv irrecv(recvPin); // Create the IR receiver object
IRsend ir;     // Create the IRsend object
decode_results  results;      // object to store the incoming ir signals

void setup()
{
  Serial.begin(9600);   // initiate the serial monitor
  irrecv.enableIRIn();  // initiate the receiver
  pinMode(3, OUTPUT);   // initiate the IR led
  pinMode(8, OUTPUT);   // initiate the status led
}

//+======================== MUTE FUNCTION =====================================
void sendMute()
{
  int khz = 38;
  unsigned int  muteSignal[] = {4550,4400, 600,1600, 600,1650, 550,1650, 600,500, 600,500, 600,500, 600,550, 600,500, 600,1600, 
                              600,1650, 550,1650, 600,500, 600,500, 600,500, 600,550, 600,500, 600,1600, 600,1650, 550,1650, 
                              600,1600, 600,550, 550,550, 600,500, 600,500, 600,500, 600,500, 600,550, 600,500, 600,1600,
                              600,1600, 600,1650, 600,1600, 600};
  ir.sendRaw(muteSignal, sizeof(muteSignal) / sizeof(muteSignal[0]), khz);
}

//+======================== LED Status light ===================================
void LED() 
{   
  for (int i = 0; i < 2; i++) 
  {
  digitalWrite(statusLed, HIGH);
  delay(150);
  digitalWrite(statusLed, LOW);
  delay(50);
  }
}



void loop() 
{ 
  if (irrecv.decode(&results))
  {
    unsigned long code = results.value;
    switch(results.value)
    {
      case PAUSE:
        digitalWrite(statusLed, HIGH);
        delay(500);
        digitalWrite(statusLed, LOW);
        sendMute();                                               //commenting this out and the loop loops.
      break;
      
      default :
        Serial.print("Remote Code: ");
        Serial.println(results.value);
        delay(200);                               // debounce
      break;
    }
    irrecv.resume();
  }
}

It has to be some basic logic I’m missing or messed up. This is really driving me crazy. guys. I’ve spent way to long on this.

SOLVED:

Unfortunately the examples don't mention this but you have to reset the IR pin after using it.

So I just had to enableIRIn() after send raw

ir.sendRaw(muteSignal, 67, 38);
irrecv.enableIRIn();

The source code is the ultimate documentation

:grin: