IR Library

Hey guys, I am trying to use Ken Shirrif’s IR Remote library to send and receive IR codes from the same Arduino. I have a generic iPod dock that came with a remote, the remote IR siginal is very weak, so what I would like to be able to do is control that dock with my Apple Remote. I wrote a basic Sketch that accepts the IR code from the Apple Remote and then sends out the correct IR code to the dock. The library does not support simultaneous sending and receiving of IR codes. Transmitting will disable receiving.

I have been pulling my hair out trying to write a sketch that will get around this issue. I’ve even looking in the class to see if I could figure out how to get it to receive and send from the same Arduino.

The IR library:

Here is my sketch:

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

// IRSendPin fixed to 3 (PWM)
int RECV_PIN = 11;  // IR Receiver pin
IRsend irsend;

IRrecv irrecv(RECV_PIN);
decode_results results;

// Setup & Configuration
void setup()
{
// initialize serial communications at 9600 bps:
Serial.begin(9600);
irrecv.enableIRIn(); // Restart the receiver

}


// Main Loop
void loop() {

if (irrecv.decode(&results)) {  // if an IR signal is obtained from IR receiver

if(results.value == 2011242506) //Apple Remote Code
{
  //irsend.enableIROut(36);
  irsend.sendNEC(16711935, 36); // Dock Remote Code
  Serial.println("Test");
}

irrecv.enableIRIn(); // Start the receiver
}
}

All sketches need to have a loop function, even if it is empty.

I do not see you using the resume as detailed in the docs.

The decode() method is called to see if a code has been received; if so, it returns a nonzero value and puts the results into the decode_results structure. (For details of this structure, see the examples/IRrecvDump sketch.) Once a code has been decoded, the resume() method must be called to resume receiving codes.

Notice this example has resume() call.

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

Also .. what is the purpose this this line? I think that should be removed and replaced with the resume.
irrecv.enableIRIn(); // Start the receiver

Note: just from looking at docs, I have yet to use this library.

@Marklar, Thanks for the reply. It's my understanding that the irrecv.enableIRIn and irrecv.resume do the samething. The code will work with either. I did some tests and it looks like there is something in irrecv.enableIRIn that doesn't allow irsend.sendNEC to work. I checked the library, but I couldn't find out exactly what it was though.

Even this basic sketch doesn't work:

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  irsend.sendNEC(16711935, 36); // Send IR Code
  delay(15*1000);  //Wait 15 seconds 
}

enAbleIRIn from IRremote.cpp:

// initialization
void IRrecv::enableIRIn() {
  cli();
  // setup pulse clock timer interrupt
  //Prescale /8 (16M/8 = 0.5 microseconds per tick)
  // Therefore, the timer interval can range from 0.5 to 128 microseconds
  // depending on the reset value (255 to 0)
  TIMER_CONFIG_NORMAL();

  //Timer2 Overflow Interrupt Enable
  TIMER_ENABLE_INTR;

  TIMER_RESET;

  sei();  // enable interrupts

  // initialize state machine variables
  irparams.rcvstate = STATE_IDLE;
  irparams.rawlen = 0;

  // set pin modes
  pinMode(irparams.recvpin, INPUT);
}

receiving and sending examples:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1277840151

I would try receiving the data and storing it in an array, then transmitting it once the full string was received.

@Big oil, Thanks for the link to the receiving and sending examples, however, it’s still not working. I copied the and pasted the code from the “VOLUME -B- GONE” example and it still isn’t working. All I did is use my IR codes. After looking at all the receiving and sending examples, it should be working, including my original code.

In fact, I checked the code for receiving and sending separately and they both work. I’m starting to wonder if it’s my arduino uno.

Wow, this had me pulling my hair out, but I finally figured out what was going on. Apparently there is a difference between the earlier and latest version of the IRremote library. Turns out you can send and receive from the same arduino with the old library, but not with the new library. I'm not sure if this was done intentionally or not, but I will email the creator and let him know, well that's if he doesn't already know.

The old library can be found here:

There latest library can be found here: