EDIT: The question below was answered, but I had a new question again. This is in posed 4...
Learning can only be done by doing it yourself .
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
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);
}
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.......