Help with Ir receiver and sender

Hello!!

I have an Infrared receiver and a infrared sender, I don't now how to use it. I have two question:

  1. How can I do stuff on the arduino with a ir remote (turn led on/off)??

  2. How can i send ir code with the ir sender?? (send the same code as my TV remote are sending)

Thanks!!

PS: Sorry for my bad English:)

These two should get you started:

Cheers,

Jack

I tried the "examples/IRrecvDemo" sketch from the A Multi-Protocol Infrared Remote Library for the Arduino and it did'n work, it said: " 'IRrecv' does not name a type "
What is that mean???

Thanks!!!

Might it be possible you have not installed the libraries correctly ? Follow the instructions included in the library.

I haven`t installed the libraries, and after I put it in the libraries folder also install it, then it just said "Error compiling".
Plzz help.

Sorry if it are stupid question :slight_smile:

Questions are rarely stupid, but some are hard to answer. I haven't got enough information to answer yours at the moment. So, my questions are:

did you follow these instructions:

This is the IRremote library for the Arduino.

To download from github (http://github.com/shirriff/Arduino-IRremote), click on the "Downloads" link in the upper right, click "Download as zip", and get a zip file.  Unzip it and rename the directory shirriff-Arduino-IRremote-nnn to IRremote

To install, move the downloaded IRremote directory to:
arduino-1.x/libraries/IRremote
where arduino-1.x is your Arduino installation directory

After installation you should have files such as:
arduino-1.x/libraries/IRremote/IRremote.cpp

Then, did you try the program examples/IRrecvDemo:

#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

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
  }
}

The error "Error compiling" can indicate many things not working, so we need some more information to help you.

Where should I put the IR code if I want to do stuff like: "if it read that IR code then do that" :smiley: :smiley: :smiley:

Where should I put the IR code if I want to do stuff like: "if it read that IR code then do that"

void loop()
{
  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);
    if(results.value == valueForButton1)
    {
       // do one thing
    }
    else if(results.value == valueForButton2)
    {
       // do something else
    }
   // etc.
    irrecv.resume(); // Receive the next value
  }
}

My Philips RC6 remote sey "1045C" on OK button, where should I but the 1045C code to turn on such a LED with just the OK button??

if(results.value == "1045C")
{
   // The OK button was pressed
}

Well here's a snippet of my code:

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    
    //now check if it's correct key and act...
    //down
    if (results.value == 1041 || results.value == 3089) {
      led_bright = led_bright - led_step;
      if (led_bright < 10) {
        led_bright = 10;
        }
      Serial.print("Going down to ");
      Serial.println(led_bright);
      analogWrite(led_pin, led_bright);
    }
  // incomplete...

It did'n work:

void loop() {
  if (results.value == 1045C) 
  {
    tone(5,350,500);
    irrecv.resume();
  }

It did'n work:

Some proof that the remote control sends a 1045C would be useful. Some proof that the value in results.value was 1045C would be useful. Some clue as to how you defined the variable 1045C would be good.

Using 0x01045C as the value might be useful.

This works for me

void loop() {
  if (irrecv.decode(&results)) 
{
    Serial.println(results.value, HEX);
    if (results.value == 0xFF00FF)
    {
      Serial.println("!");
    }
    irrecv.resume();
  }
}

I'm tried everything but it just come up the orange line who said "Error compiling", why is taht coming up???

I'm tried everything but it just come up the orange line who said "Error compiling", why is taht coming up???

The compiler doesn't like you. Or your code. Since you haven't posted the code, we can only assume that it isn't the code.

If you'd like to confirm that it isn't you, post your code.

You obviously haven't tried everything. What does the error message say exactly ?

Look at my code, look at your code. Is the line that does the test for a code significantly different apart from the code being used ? The 0x at the start of my values being checked for may be significant.....

I'm sorry, I forget my code, this is the code the Error message came from:

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  irrecv.enableIRIn();
}

void loop()
{
  if (results.value == 0x01045C)
  {
    tone(5,350,500);
  }
}

Her is something else I did'n get to work, on this code it said "done upload" put it was a red text who said "avrdude: stk500_getsync(): not in sync: resp=0x30"

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);
IRsend irsend;

decode_results results;

void setup()
{
  irrecv.enableIRIn();
}

void loop() 
{
  if (results.value == 0xFFA15E)
  {
    irsend.sendRC6(10038,20);
  }
  irrecv.resume();
}

I'm sorry, I forget my code, this is the code the Error message came from:

This time, you forgot the error messages.

Where did the call to irrecv.decode() go?