Help with IRremote

Hello, I'm trying to built an IR remote converter using an KY-022 module as a receiver and a KY-005 module as a transmitter, my goal is to use my tv remote control to change the sound in my old Home Theater sound system(which uses samsung ir protocol). I have already scanned the info of the signal that the arduino must receive and the signal that it must send and i'm gonna write them down here. The fact is i'm not beeing able to make the arduino recognize the signal from the tv controller (it's a samsung smarttv remote but it's protocol is UNKNOWN).

The goal is to make the this:

Protocol=UNKNOWN 13 bits (incl. gap and start) received
Received noise or an unknown (or not yet enabled) protocol
rawData[26]:
-3276750
+1200,-1200
+ 400,- 550 + 450,- 850 + 450,-2350 + 450,- 850
+ 450,- 550 + 400,- 600 + 400,- 600 + 400,-2650
+ 450,-2600 + 450,-2350 + 450,- 550 + 450
Sum: 22100

Become this:

Protocol=Samsung Address=0x2C2C Command=0x17 Raw-Data=0xE8172C2C 32 bits LSB first
Send with: IrSender.sendSamsung(0x2C2C, 0x17, );

Any help on how i can make that happens?

My clairvoyant skills lead me to believe that the problem is on line 10 of your code ...

Seriously though, you need to post your code so we can see what you are doing. Make sure you use code tags (the < CODE / > in the toolbar) so that it knows that you are displaying code.

It appears that Samsung TVs use the NECx2 protocol. If so, the first question is whether the Receiver function in your library can properly decode NECx2. I don't know if IRRemote.h for Arduino will do that. Unless you have a scope, or can find a database with all the Samsung codes in it, I think the key will be finding the right library.

It's possible the the IRRemote RAW function would work for receive and send. Actually, you really need to find someone who's done this with Samsung TVs.

Edit: Maybe something in this link will help.

https://lookin-home.medium.com/how-does-the-remote-control-work-explained-564bc7cd0291

I'm sorry i totally forgot about the code. This is my first more complex arduino project, i just done some little projects in the past because i wanted to learn some arduino but never something with an actual application and with so many things that could go wrong.

Thanks

#include <IRremote.h>

const int RECV_PIN = 3;
const int SEND_PIN = 4;

IRrecv irrecv(RECV_PIN);
IRsend irsend;

void setup() {

  irrecv.enableIRIn();
  Serial.begin(9600);
}

void loop() {
  decode_results results;


  if (irrecv.decode(&results)) {
    if (results.value == 0x9DBCC18C) {
      irsend.sendSAMSUNG(0xE8172C2C, 32);
    }

    irrecv.resume();
  }
}

  1. Please confirm which version you are using. Versions 2 and 3 work a lot differently from version 4. The style of code you have included is for version 2/3. The version 4 code looks different. (see GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols)
  2. The iRemote library requires you to activate the protocols you want to decode. This is covered in the lib documentation and, from memory, is about editing a header file (IRemote.hpp). Check that you have enabled the right NEC protocol. The library distribution enables all protocols by default.
  3. Is your hardware correctly wired up? The receiver needs to be the correct frequency for the protocol (NEC2 should be 38kHz I think).

Hello, i tried using a lot of variations of codes and examples that i could find with the IRremote and another libraries for decoding and none have worked with my samsung remote control. Sorry for the lack of information.

1- I used the newer version to obtain the raw data that i posted originally, not using the v2/3 code anymore.

2-I activated the #defines, actually i did activate all of them for testing and yet none worked, the results keeps being protocol=UNKNOW

3-I'm using a KY-022 as a receiver and yes, it's 38kHz.

My remote control model is VG-TM2360E.
I've noticed that the sum of the raw signal is displayed and it dependes of the button that you're pressing, i'm thinking of a way to use this sum to recognize which button is being pressed, for the example here the Sum is always 22050 or 22100 so i would use that to recognize the buttom but i can't find the info that is printed in the serial monitor on the code (using the simple receiver example from IRremote) to try and use the sum for the recognition.

Thanks

Some updates. I managed to make the code works and recognize the hex that the older version of the IRremote library decoded. I'm using version 2.2.3 now and it only has one problem that i think it's because of my bad coding.

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int RECV_PIN = 4;

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
IRsend irsend;
decode_results results;

bool isReceiving = true; // Flag para controle do modo

void setup(){
  // Serial Monitor @ 9600 baud
  Serial.begin(9600);
  // Enable the IR Receiver
  irrecv.enableIRIn();
}

void loop(){
  unsigned long volup = 0x3434E817;
  unsigned long voldw = 0x34346897;
  
  if (isReceiving && irrecv.decode(&results)){
    isReceiving = false; // Muda para o modo de transmissão
    if(results.value == 0x9DBCC18C){
      Serial.println(results.value, HEX);
      irsend.sendSAMSUNG(volup, 32);
    } else if(results.value == 0x19495A7F){
      Serial.println(results.value, HEX);
      irsend.sendSAMSUNG(0x34346897, 32);
    }
    delay(100); // Adicionei um atraso aqui
    isReceiving = true; // Volta para o modo de recepção
    irrecv.resume(); // Reinicia a recepção
  }
}

After it recognizes the first time i press one of the buttons it freezes, the ir receiver has a led and it keeps blinking when i press the remote but none new information is shown in the serial monitor and the transmitter don't work again after the first time.

Tried to do this state mode that would define if the arduino is receiving ou sending but it didn't work.

Should this

irsend.sendSAMSUNG(0x34346897, 32);

be

irsend.sendSAMSUNG(voldw, 32);

And is there a difference? i forgot to change the first one too before posting here.

But doesn't it is supossed to be the same thing? Does this affect the program freezing after the first time it recognizes the signal?

So does anything work on the TV so far?

Yes, it results in the same program flow and it would not fix your problem.

However, if you then changed the constant value at the top of the file and expected it to change in the body of the program it would not work. This becomes especially difficult to track down when the program is large and/or the constant is a more common number (eg, 10). If you define constants, use them.

My goal is not to communicate with the TV but with my Home Theater system that coincidentally uses Samsung protocol for the remote (using my samsung smart tv control). But yes things are working separately. The receiver can identify the Hex for the command that i'm clicking and the transmitter can comunicate with the Sound system (i tested a code that would only send the signals for testing and it worked). My problem is putting the two things together to make it work as only one.

My next step is try to update my code for the newer IRremote version and try to use the same logic to make it work, but if any of you have any ideia on how to solve my problem with the program not reading any new signals after reading the first one and sending the signal to the sound system i would be grateful.

Thanks

I have some updates. Updated the code for the newer version of IRremote and followed the instructions on the github page to adapting the code and now it works fine!

Only problem i'm trying to solve now is consistency. The receiver decodes every signal and send and the transmitter sends the other signal everytime flawlessly but not all of the inputs the transmitter is creating are recognized by the sound system, i would say that 40% of the times i select volume up ou down it actually works.

But for now it's fine, i'll keep looking for ways to improve my experience, but thanks everyone for the help. Gonna put the code down bellow maybe it helps anyone

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int IR_RECEIVE_PIN = 4;

void setup(){
  Serial.begin(9600);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
  IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);
}

void loop(){

  if (IrReceiver.decode()) {
    if(IrReceiver.decodedIRData.decodedRawData == 2646393228){
      Serial.println(IrReceiver.decodedIRData.decodedRawData);
      IrSender.sendSAMSUNG(0x3434E817, 32);
      IrReceiver.resume();
    } else if(IrReceiver.decodedIRData.decodedRawData == 424237695){
      Serial.println(IrReceiver.decodedIRData.decodedRawData);
      IrSender.sendSAMSUNG(0x34346897, 32);
      IrReceiver.resume();
    }
    else {
      IrReceiver.resume();
    }
    // Allow time for the receiver to prepare for next signal
    delay(500);
  }
}

New Update! Everything working as intended! I don't know if the problem is the cheap transmitter ou the old receiver or another thing but i solved it by just creating a loop that sends the infrared signal 10 times instead of just one and now it works fine! Sometimes the vol go up/down two or more rarely three points instead of just one but i don't really care about this, i'm just happy that it works.

Gonna let the new code here:

// Include IR Remote Library by Ken Shirriff
#include <IRremote.h>

// Define sensor pin
const int IR_RECEIVE_PIN = 4;

void setup(){
  Serial.begin(9600);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
  IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN);
}

void loop(){

  if (IrReceiver.decode()) {
    if(IrReceiver.decodedIRData.decodedRawData == 2646393228){
      Serial.println(IrReceiver.decodedIRData.decodedRawData);
      for(int i =0;i<10;i++){
      IrSender.sendSAMSUNG(0x3434E817, 32);
      }
      IrReceiver.resume();
    } else if(IrReceiver.decodedIRData.decodedRawData == 424237695){
      Serial.println(IrReceiver.decodedIRData.decodedRawData);
      for(int j=0;j<10;j++){
      IrSender.sendSAMSUNG(0x34346897, 32);
      }
      IrReceiver.resume();
    }
    else {
      IrReceiver.resume();
    }
  }
}

Are you still using the KY-005? If so, that may be the problem. What I've found on this module is that it's just the IR LED. There's no transistor, and the middle pin isn't even connected to anything. Can you confirm that?

Anyway, if that's true, then you would just be directly driving the LED from the GPIO port, which would produce something like 20mA. Most remote controls operate at much higher currents, possibly as much as 1A. So it may be that the signal is so weak that it just doesn't get through much of the time.

One useful test is to have your processor transmit the command once a second, and see if all of those make it through. If only 40% of those make it, then I would strongly suspect that your LED is very underpowered.

Another test is to see if the completion rate improves as you move the KY-005 closer and closer to the Home Theater receiver.

Ideally you would want to drive the LED from a transistor or mosfet which is controlled by the GPIO pin.

Also, you don't know what kind of beam the LED produces - narrow or wide.

Some IR protocols require that the signal is sent 3 times. Not sure if this is the case for this protocol.