Reading an IR code, and then sending it

Hi folks, I have been at this for quite a while now and I can't find the right software that works. Basically, I have a code that I can run on the arduino and scan IR codes from TV remotes, and then receive these codes and do actions. I want to take it a step further- I want to send the code the Arduino just received. That way I can build learning universal remotes and more. Here is an example of what I mean: I used the IR library and scanning code from this article: http://www.instructables.com/id/The-Easiest-Way-to-Use-Any-IR-Remote-with-Ardiuno/?ALLSTEPS. The result for one of the IR codes is: "2155839615". Now how do I send that code, preferably with the same library? Thanks a lot :) - Oren

I used the IR library

which comes with examples.

The result for one of the IR codes is: "2155839615".

I find that rather hard to believe. Which protocol results in strings?

Now how do I send that code, preferably with the same library?

"The same way that the example shows" was my first thought.

The examples only show how to send specific codes to specific TV models. The link that I downloaded from the link I gave you includes a special program that reads IR codes and shows a number in the serial thingy... That's the number I copied and pasted over here.

and shows a number

Not a string? Doesn't it tell you which protocol the value was determined to be?

in the serial thingy...

My thingy is not serial...

That's the number I copied and pasted over here.

Making it look like a string.

The examples only show how to send specific codes to specific TV models.

You can't really expect to have a remote that can read any kind of device and send to any kind of device. You can have an Arduino that can send all commands to a specific device/brand (TV, DVD player, etc.) or send specific commands (record, stop, play, change channel, change volume, etc.) to different devices/brands. Sending play to the TV hardly makes sense. Sending channel up to the DVD player hardly makes sense.

I copied here an int, a number with a lot of digits, how is this a string? And why not? What's wrong with a device that reads an infra-red pattern and then plays it?

how is this a string?

14 is an int. "14" is a string.

What's wrong with a device that reads an infra-red pattern and then plays it?

Nothing. But, the IR library is doing more that just reading an IR pattern. It is determining that the IR pattern is in some specific protocol.

If you want to use RAW mode, by all means, do so.

Ok, I tried the record example from the IRremote library and I got this: 807F807F It also said it's an NEC code. When I put it in the "IRsendDemo" example, instead of the sony code (I also replaced "sendSony" with "sendNEC"), there is an error during the compiling process. It says: IRsendDemo.cpp:25:22: error: invalid suffix "F807F" on integer constant What should I do?

What should I do?

Post your code.

#include <IRremote.h>

IRsend irsend;

void setup()
{
  Serial.begin(9600);
}

void loop() {
  if (Serial.read() != -1) {
    for (int i = 0; i < 2; i++)
    {
      irsend.sendNEC(807F); 
      delay(40);
    }
  }
}
      irsend.sendNEC(807F);

807F is not a valid integer value. 0x807F is.

Thanks, but it also told me to put an int after the long unassigned int with a comma separating them. How do I know what int to put?

try this

irsend.sendNEC(0x807F,32);

the 32 refers to the number of bits in the NEC protocol.

I was able to verify the above format by using google to search for ‘irsend.sendNEC’…= hint on using search to solve problems :slight_smile:

Also, if you search for ‘sb projects ir’ you will find out a lot about IR protocols…

Ok thanks but one more thing: The example that read the IR code wrote in the serial: "Recieved: NEC, 807F Recieved NEC again" So I guess my remote sends the same code twice, but how do I know the delay between them?

In the NEC protocol, the remotes typically send a repeat signal if the button is kept pressed down. The repeat signal consistes of just a header and trailer with no identifying bits in between. IRremote, reports the NEC repeat as 0xFFFFFFFF or something similar.

A typical gap would be circa 40ms, between NEC signals

However, I suspect you don't really need to send the repeat signal except for things like VOL+ or VOL- or similar keys where repeating makes sense. Also, just sending the original singnal instead of the repeat should also work.

It looks like the reason to use the repeat is that is uses less power than sending the full signal every time.

search 'sb projects IR' to find a great explanation of NEC & other IR protocols & all will be revealed :)