Receiving Different IR Codes From The Same Remote/Button


#1

I am working on a 4WD car controlled by TV remote. However, everytime I press the same button on my TV remote I get different results (codes) . I changed IR receiver but not work and the same problem persist. What is the cause of this and how can I solve the problem.

// generated by mBlock5 for
// codes make you happy

#include “src/boarddefs.h”
#include “src/IRremote.h”
#include “src/IRremoteInt.h”
#include “src/ir_Lego_PF_BitStreamEncoder.h”
#include “src/OfflineBroadcast.h”

#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

float ileri_tu_C5_9F = 0;
float geri_tu_C5_9F = 0;
float sol_tu_C5_9F = 0;
float sa_C4_9F_tu_C5_9F = 0;
float dur_tu_C5_9F = 0;
float h_C4_B1z_art_C4_B1r = 0;
float h_C4_B1z_azalt = 0;
float h_C4_B1z = 0;
float h_C4_B1z_50_art_C4_B1r = 0;

const int RECV_PIN = 8;

IRrecv irrecv(RECV_PIN);
decode_results results;
OfflineBroadcast broadcaster;
void _C4_B0LER_C4_B0(){
analogWrite(10,250);
digitalWrite(2,1);
digitalWrite(3,0);
analogWrite(11,250);
digitalWrite(4,0);
digitalWrite(5,1);

}
void GER_C4_B0(){
analogWrite(10,250);
digitalWrite(2,0);
digitalWrite(3,1);
analogWrite(11,250);
digitalWrite(4,1);
digitalWrite(5,0);

}
void SA_C4_9E(){
analogWrite(11,250);
analogWrite(10,250);
digitalWrite(4,0);
digitalWrite(5,1);
digitalWrite(2,0);
digitalWrite(3,1);

}
void SOL(){
analogWrite(10,250);
digitalWrite(2,1);
digitalWrite(3,0);
analogWrite(11,250);
digitalWrite(4,1);
digitalWrite(5,0);

}
void DUR(){
analogWrite(10,250);
digitalWrite(2,0);
digitalWrite(3,0);
analogWrite(11,250);
digitalWrite(4,0);
digitalWrite(5,0);

}

void _delay(float seconds) {
long endTime = millis() + seconds * 1000;
while(millis() < endTime) _loop();
}

void setup() {
irrecv.enableIRIn();
Serial.begin(115200);
pinMode(10,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(11,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
while(1) {
if(irrecv.decode(&results)){
broadcaster.broadcast(String(“message”),String(results.value));
if(results.value == 1181684798.000000){
_C4_B0LER_C4_B0();

    }
    if(results.value == 874738657.000000){
      SA_C4_9E();

    }
    if(results.value == 3508422680.000000){
      SOL();

    }
    if(results.value == 1785826176.000000){
      GER_C4_B0();

    }
    if(results.value == 2040752436.000000){
      DUR();

    }
    irrecv.resume();

  }

  _loop();

}

}

void _loop() {
broadcaster.loop();
}

void loop() {
_loop();
}


#2

Hi! The IR Receiver only works with the remote that comes with the kit and other mBots. But can you format the code? This is how to format codr:
Put 3 Back tics Like This " " Write your code here. Add another 3 Backtics " "
It should look like this:

code

#3

@adeger
The issue is probably because TV remotes use a different IR protocol than the extension you are using supports. The protocol can even vary by TV brand.
Are you using an Arduino UNO board, by the way?


#4

Hi, yes I use arduino r3 board and İ tried 2 different ir sensor using 38khz but mblock protocole may be not suitable for my ir sensor and/or remote controller.


#5

@adeger
You can try using the “Arduino UNO Plus” device, which has built in blocks for the IR sensor:
image

image

However, it may not work for newer Arduino devices.