I have just got an IR sensor with an IR remote. All I want to do is to get the Arduino board to print the button which is being pushed.
For that, I got the codes of the buttons online, but the problem is, they sometimes get printed, sometimes don't.
For example, I push the button "1", the sensor lights up and 1 gets printed. I push it again, the sensor lights up again, but no 1 is printed this time. (completely random) The sensor always lights up, which means it shouldn't be a problem with the remote or the sensor, but it should be remote sending different values every time.
I really don't know how I can get it to send the same value every time, hope you can help with it.
The code I wrote:
#include <IRremote.h>
IRrecv irrecv(2);
decode_results results;
#define UP 0xFF629D
#define LEFT 0xFF22DD
#define OK 0xFF02FD
#define RIGHT 0xFFC23D
#define DOWN 0xFFA857
#define BUTON1 0xFF6897
#define BUTON2 0xFF9867
#define BUTON3 0xFFB04F
#define BUTON4 0xFF30CF
#define BUTON5 0xFF18E7
#define BUTON6 0xFF7A85
#define BUTON7 0xFF10EF
#define BUTON8 0xFF38C7
#define BUTON9 0xFF5AA5
#define STAR 0xFF42BD
#define BUTON0 0xFF4AB5
#define HASH 0xFF52AD
void setup(){
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop(){
if (irrecv.decode(&results)){
if (results.value == UP){
Serial.println("UP");
}
if (results.value == LEFT){
Serial.println("LEFT");
}
if (results.value == OK){
Serial.println("OK");
}
if (results.value == RIGHT){
Serial.println("RIGHT");
}
if (results.value == DOWN){
Serial.println("DOWN");
}
if (results.value == BUTON1){
Serial.println("1");
}
if (results.value == BUTON2){
Serial.println("2");
}
if (results.value == BUTON3){
Serial.println("3");
}
if (results.value == BUTON4){
Serial.println("4");
}
if (results.value == BUTON5){
Serial.println("5");
}
if (results.value == BUTON6){
Serial.println("6");
}
if (results.value == BUTON7){
Serial.println("7");
}
if (results.value == BUTON8){
Serial.println("8");
}
if (results.value == BUTON9){
Serial.println("9");
}
if (results.value == STAR){
Serial.println("STAR");
}
if (results.value == BUTON0){
Serial.println("0");
}
if (results.value == HASH){
Serial.println("HASH");
}
irrecv.resume();
}
}