irsend.sendNEC doesn't seem to be working

Due to my meds I have a Swiss cheese memory. That makes learning this stuff very difficult for me but I haven't given up yet so please don't bite my head off if I've done something stupid.

I've followed all of the tutorials that I can find on receiving and sending IR codes. I only found one on sending the codes. Part of this is working but the IR TXer isn't sending anything. I verified this with the camera on my phone. I don't know if the code is wrong or if the TXer is dead. I know it's probably only a few cents for a new one but most of the Arduino stuff that I have was gifted to me. Disability pays jack squat! If someone can tell me that the code is correct, I'll have to find a new TXer.

When I view the serial monitor, it seems to start out just fine. I push the button on the remote and "RED" shows up in the monitor. The TXer doesn't do anything. Then everything stops. If I hit the button again, nothing more happens.

I really appreciate any help with this.

#include "IRremote.h"

int receiver = 11; // Signal Pin of IR receiver to Arduino Digital Pin 11

/*-----( Declare objects )-----*/
IRrecv irrecv(receiver);     // create instance of 'irrecv'
IRsend irsend;
decode_results results;      // create instance of 'decode_results'

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
  irrecv.enableIRIn(); // Start the receiver

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?
{
 if(results.value == 0xFFA05F )
    irsend.sendNEC(0xFFA05F, 32);
    Serial.println(" RED") ;
    delay(200);              //THIS IS WHERE EVERYTHING STOPS
    irrecv.resume(); // receive the next value
}

    
//Doesn't send to the IR TXer or the IR TXer is bad
//Doesn't resume read after 1st print



//  COMMENTED OUT TO TROUBLESHOOT
//  {
//    translateIR(); 
//    irrecv.resume(); // receive the next value
//  }  
}/* --(end main loop )-- */

/*-----( Function )-----*/
void translateIR() // takes action based on IR code received

// describing Remote IR codes 

{

  switch(results.value)

  {

  case 0xFFA05F: irsend.sendNEC(0xFFA05F, 32); Serial.println(" RED") ; break;   //RED LED  irsend.sendNEC(0xFFA05F, 32); 
  case 0xFF20DF: Serial.println(" GREEN");    break;   //GREEN
  case 0xFF609F: Serial.println(" YELLOW");    break;  //YELLOW
  case 0xFFE01F: Serial.println(" BLUE");   break;   //BLUE
  case 0xFF906F: Serial.println(" OFF"); break;   //OFF
  case 0xFF6897: Serial.println(" 1");    break;
  case 0xFF9867: Serial.println(" 2");    break;
  case 0xFFB04F: Serial.println(" 3");    break;
  case 0xFF30CF: Serial.println(" 4");    break;
  case 0xFF18E7: Serial.println(" 5");    break;
  case 0xFF7A85: Serial.println(" 6");    break;
  case 0xFF10EF: Serial.println(" 7");    break;
  case 0xFF38C7: Serial.println(" 8");    break;
  case 0xFF5AA5: Serial.println(" 9");    break;
  case 0xFF42BD: Serial.println(" *");    break;
  case 0xFF4AB5: Serial.println(" 0");    break;
  case 0xFF52AD: Serial.println(" #");    break;
  case 0xFFFFFFFF: Serial.println(" REPEAT");break;  

  default: 
    Serial.println(" other button   ");

  }// End Case

  delay(500); // Do not get immediate repeat


}

Try this

 irrecv.enableIRIn(); // Start the receiver

after every send().

DrDiettrich:
Try this

 irrecv.enableIRIn(); // Start the receiver

after every send().

I can't find an instance of send(). I did add that line to void setup(). No change.

" I verified this with the camera on my phone."

I have found that on my iPhone that the main camera (the one on the back) is not sensitive to IR, but switching to the front selfie camera then the IR light shows up.

Look into your code, where you send the IR code.

Due_unto, I can see the IR on the actual remote using the phone.

DrDiettrich, I have a hard time seeing things sometimes but I had the computer search for "send()" and got no results. Then I just searched "send" and got

IRsend irsend;

irsend.sendNEC(0xFFA05F, 32);

That's it. I'm sure I'm missing something that you think is simple but I'm just not seeing it. Sorry.

Sorry for the confusion, I don't like typing redundant information for coders :frowning:

You got it :slight_smile:
Now add the code to enable IR input again.

I've added it to two different places. Set up and Loop. Nothing's changed.

I'm pretty sure I've wired it up correctly. Ignore the LED on the right. It's not wired in.

Google Photos

The picture isn't showing up in the preview. I hope you can see it.

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
  Serial.println("IR Receiver Button Decode"); 
 irrecv.enableIRIn(); // Start the receiver

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?
{
 if(results.value == 0xFFA05F )
    Serial.println(" RED") ;
     irrecv.enableIRIn(); // Start the receiver
    irsend.sendNEC(0xFFA05F, 32);
    delay(200);
    irrecv.resume(); // receive the next value
}

You found the right place, but receiving must be re-enabled after sending. Swap the statements.

I'll test this in a bit.

void setup()   /*----( SETUP: RUNS ONCE )----*/
{
  Serial.begin(9600);
 irrecv.enableIRIn(); // Start the receiver
  Serial.println("IR Receiver Button Decode"); 

}/*--(end setup )---*/


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/
{
  if (irrecv.decode(&results)) // have we received an IR signal?
{
 if(results.value == 0xFFA05F )
    Serial.println(" RED") ;
    irsend.sendNEC(0xFFA05F, 32);
     irrecv.enableIRIn(); // Start the receiver
    delay(200);
    irrecv.resume(); // receive the next value
}

That solved one problem. Now I can get continuous readings but the IR TXer still isn't doing anything. Is there another way I can test that? Is there some way to just send anything to the TXer?

EDIT: I ripped an old remote apart and took the IR Txer out. I put a 150Ω resistor on the cathode and the anode to pin 3. I'm still not seeing anything. I have no idea if this would actually work anyway. I'm just playing with ideas.

I tried some of the other examples. IRsendRawDemo and LegoPowerFunctionsSendDemo. I assumed that they would send something. Nope.

Since that picture didn't work earlier, I'll do it this was.
GND to -
5V to center pin
Arduino pin 3 to S

None of the tutorials said that pin 3 needed to be declared as it was done in the library. None of the examples show a pinout. Is that correct? Is there anything else I need to do or should I just glue it to a target and take it out back with a few rifles? :stuck_out_tongue:

The pins depend on the controller and timer used. You'll have to lookup the sending pin in the library, or print out the value of SEND_PIN in setup().

DrDiettrich:
print out the value of SEND_PIN in setup().

How do I do that? Again, if I do println correctly, I'm shocked. I've VERY much a beginner at this.

Serial.println(SEND_PIN);

You really should learn a bit more about C and wriiting code. Start with simpler example projects before you dig into libraries.

I'm really trying to learn more. I've been studying the Paul McWhorter lessons. I've been on enough pain meds to kill a hippo for the last 19 years so my brain is Swiss cheese and it's really had to memorize and learn new things. Sorry.

Do not only study lessons, instead also practice some of the Arduino example projects. The code tells you how to do something, and when you modify it you learn how to debug and tweak it to your needs.

Sounds good. Thanks. Paul's videos give you homework and ask you to try different things to get different results. I had actually given up for a while. It was just too frustrating. We'll see what happens this time. :stuck_out_tongue:

I tried Serial.println(SEND_PIN); in setup (and loop) and got this.

Arduino: 1.8.5 (Windows 10), Board: "Arduino/Genuino Uno"

TEST_9_Sending_Codes_from_Codes:12: error: 'SEND_PIN' was not declared in this scope

Serial.println(SEND_PIN);

^

exit status 1
'SEND_PIN' was not declared in this scope

Some #include seems to be missing :frowning: