[SOLVED] IR doesnt work

EDIT: The question below was answered, but I had a new question again. This is in posed 4... :confused:

Learning can only be done by doing it yourself :wink: .
With that setting I started again with a next project.

On paper it must be a fairly simple project. I have an IR receiver and a remote. I have looked at the following program what the HEX number is behind different buttons:

/* To make this program work, a library is used. This library can be found at: https://github.com/z3t0/Arduino-IRremote.

  Required:
  - IR receiver - remote control

  What the program does:
  If the IR receiver is connected, this remote control can be read in the Serial.print. Here comes a hex code.
*/

#include <boarddefs.h>
#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
  }
}

This worked fine. I have discovered that behind button 1 E0E020DF sits and back button 2 E0E0A05F.
After some further research and trying, I have made the following program:

#include <boarddefs.h>
#include <IRremote.h>

int RECV_PIN = 11;
int redLED = 2;
int greenLED = 3;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
}

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

void translateIR() { // takes action based on IR code received
  switch (results.value) {
    case E0E020DF:
      Serial.println("button 1 is pushed");
      ledRED();
      break;

    case E0E0A05F:
      Serial.println("button 2 is pushed");
      ledGREEN();
      break;

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

void ledRED() {
 //do something
}

void ledGREEN(){
  //do something
}

The problem is, however, that if I run the program, get the following message:

C: \ Users \ 364 \ Documents \ Arduino \ sketch_may02c \ sketch_may02c.ino: In function 'void translateIR ()':

Sketch_may02c: 40: error: 'E0E020DF' was not declared in this scope

     Case E0E020DF:

          ^

Sketch_may02c: 45: error: 'E0E0A05F' was not declared in this scope

     Case E0E0A05F:

          ^

Exit status 1
'E0E020DF' was not declared in this scope

However, I do not know what to change to get rid of this. In several examples this should work.

Does anyone have advice on how to solve this? Thanks in advance :slight_smile:

case 0xE0E020DF:

Does anyone have advice on how to solve this?

   case 0xE0E020DF:

AWOL:

case 0xE0E020DF:

thanks that was the problem :smiley:

Good morning,

I have now been able to turn two LEDs on and off with a remote control.

One new goal is to do this now with an infrared emitter. I have two arduino connected to PC and use both a different port.

For the receiving side, I use the following program:

/* To make this program work, a library is used. This library can be found at: https://github.com/z3t0/Arduino-IRremote.

  Required:
  - IR receiver - remote control - 2leds

  What the program does:
  If the IR receiver is connected, this remote control can be read. There are different 'case'. When pushed to 1, a led will go on. 
  This also happens when you push 2. With the  off button everything goes out.
*/

#include <boarddefs.h>
#include <IRremote.h>

int RECV_PIN = 11;
int redLED = 4;
int greenLED = 3;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(19200);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(redLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
}

void loop()
{
  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX); //UN Comment to see raw values
    translateIR();
    irrecv.resume(); // Receive the next value
  }
}

void translateIR() { // takes action based on IR code received
  switch (results.value) {
    case 0xE0E020DF:
      Serial.println("button 1 is pushed");
      ledRED();
      break;

    case 0xE0E0A05F:
      Serial.println("button 2 is pushed");
      ledGREEN();
      break;

    case 0xE0E040BF:
      Serial.println("button off is pushed");
      off();
      break;
      
    default:
      Serial.println("other button");
  }
}

void ledRED() {
  digitalWrite(redLED, HIGH);
}

void ledGREEN() {
  digitalWrite(greenLED, HIGH);
}

void off(){
  digitalWrite(redLED, LOW);
  digitalWrite(greenLED, LOW);
}

And I use this program for the sending side:

#include <boarddefs.h>
#include <IRremote.h>

IRsend irsend;

const int buttonGREEN  = 5;
const int buttonRED  = 4;
const int buttonOFF  = 6;


void setup() {
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(buttonGREEN, INPUT);
  pinMode(buttonRED, INPUT);
  pinMode(buttonOFF, INPUT);
}

void loop() {

  if (digitalRead(buttonRED) == HIGH) {
    delay(50);
    irsend.sendNEC(0xE0E020DF, 32);
    Serial.println("buttonRED");
  }

  if (digitalRead(buttonGREEN) == HIGH) {
    delay(50);
    irsend.sendNEC(0xE0E0A05F, 32);
    Serial.println("buttonGREEN");
  }

  if (digitalRead(buttonOFF) == HIGH) {
    delay(50);
    irsend.sendNEC(0xE0E040BF, 32);
    Serial.println("buttonOFF");
  }
  delay(1);
}

With the serial monitor I checked if the buttons are working. That seems to be all right.

Does anyone have an idea what I have forgotten? Or has feedback on the program?

Does anyone have an idea what I have forgotten?

Yes. You forgot to tell us what the programs actually do, and how that differs from what you expect.

PaulS:
Yes. You forgot to tell us what the programs actually do, and how that differs from what you expect.

The sending side should send a certain value. This value must then be read by the receiving side.

Actually, it's basically as with an external remote control, I only want to make that remote control now myself.

The receiving side works with an external remote but not with my own remote.

It receives nothing and I do not know if it was sent

A schematic would certainly be useful. What kind of LED are you using? How is it connected?

PaulS:
A schematic would certainly be useful. What kind of LED are you using? How is it connected?

Electric scheme
I only made a quick sketch from the sending side. You can find this in the attachment.

Components:

Library
The is the libary i use GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols

There is a IRrecv demo. You might want to run that, to determine if the transmitter is sending anything.

The reseving side works. That i know for sure because i can turn the leds on and off with the remote from the tv.

I looked if the reseving side reseved something, whitout succes. So ther is a big change that the sending sid doent send anything. But i cant find out what rong with the program ore the way i connect it.......

That i know for sure because i can turn the leds on and off with the remote from the tv.

What you have NOT proven, though, is that the TV remote is using the NEC format.

I tryed de code. But doesnt work wit the sending part en does work with a tv remote......

Whoeeee i found the problem!! :smiley:

When you use a Arduino UNO you use pin 3 BUT when you use a Arduino MEGA it is pin 9

thanks for your help PaulS!!