How to make IR control codes to be able to control 2 brands of Air Conditioner

Hi all

I understand the subject might be confusing, that's because idk how to articulate my question :confused:

So my end goal is that I need to make a universal AC remote to control different brands of Air Conditioner.

What I have done is, wrote successful (separate)codes to control Daikin, and Hitachi AC, and I've made my AC with ESP8266 D1 mini and IR transmitter.

as I mentioned, now the control codes of the 2 brands of AC are separate, I wanna know how to combine those 2 sets of codes so I can control the 2 brands at the same time, aka, without going back to my laptop and uploading another brand's control code just to control another brand of AC.

My separated codes are attached

i think i can start with only combining power function, but even that, idk how:/

simplified_complete_daikin.ino (5.26 KB)

Power_Fan_Mode_Temp_HitachiAC.ino (4.77 KB)

simplified_complete_daikin.ino (5.26 KB)

Power_Fan_Mode_Temp_HitachiAC.ino (4.77 KB)

the attached is the configuration of my remote

There's a couple of ways. You can have a mode button that selects which control you're emulating. Or just send commands for both whenever you press a button.

Either way, you'll need to have two ac objects and you'll need to combine the code depending on which choice you make about how to do it.

wildbill:
There's a couple of ways. You can have a mode button that selects which control you're emulating. Or just send commands for both whenever you press a button.

Either way, you'll need to have two ac objects and you'll need to combine the code depending on which choice you make about how to do it.

that's the thing tho, I basically have no knowledge abt programming, so I don't have any clue abt how to combine the code. could you pls give me a tiny hint?? :confused:

You're going to have to combine the two sketches. Grumpy_Mike has a tutorial on the subject.

There are some pre-changes you can make to simplify the combination process though. As I said, you will need an ac object for each air conditioner and they will need different names, which they currently don't.

I suggest you pick one of your programs, take a copy of it and rename the ac object to something that includes the AC device's name. When you compile it you will get a lot of errors but they'll be easy to fix.

Then rename loop to something that tells you which AC unit it controls. Make a new loop that just calls the renamed function.

Do the same to the other program.

Then you can use Mike's tutorial to make a new program that combines the other two.

wildbill:
You're going to have to combine the two sketches. Grumpy_Mike has a tutorial on the subject.

There are some pre-changes you can make to simplify the combination process though. As I said, you will need an ac object for each air conditioner and they will need different names, which they currently don't.

I suggest you pick one of your programs, take a copy of it and rename the ac object to something that includes the AC device's name. When you compile it you will get a lot of errors but they'll be easy to fix.

Then rename loop to something that tells you which AC unit it controls. Make a new loop that just calls the renamed function.

Do the same to the other program.

Then you can use Mike's tutorial to make a new program that combines the other two.

Thank you so much

here is my combined code, is this what you mean? it worked

 #include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <ir_Hitachi.h>
#include <ir_Daikin.h>

const uint16_t kIrLed = 4;  // ESP8266 GPIO pin to use. Recommended: 4 (D2).
IRHitachiAc ac(kIrLed);  // Set the GPIO to be used for sending messages.

const int b1= 5; //D1 
int power = 0;// 0---off 1---on
int y=1;

void printHitachiState() {
  // Display the settings.
  Serial.println("Hitachi A/C remote is in the following state:");
  Serial.printf("  %s\n", ac.toString().c_str());
  // Display the encoded IR sequence.
  unsigned char* ir_code = ac.getRaw();
  Serial.print("IR Code: 0x");
  for (uint8_t i = 0; i < kHitachiAcStateLength; i++)
    Serial.printf("%02X", ir_code[i]);
  Serial.println();
}

void printDaikinState() {
  // Display the settings.
  Serial.println("Daikin A/C remote is in the following state:");
  Serial.printf("  %s\n", ac.toString().c_str());
  // Display the encoded IR sequence.
  unsigned char* ir_code = ac.getRaw();
  Serial.print("IR Code: 0x");
  for (uint8_t i = 0; i < kDaikinStateLength; i++)
    Serial.printf("%02X", ir_code[i]);
  Serial.println();
}

void setup() {
  pinMode(b1,INPUT); //Press ---1  not pressing---0 
  ac.begin();
  Serial.begin(115200);
  delay(200);
}


  // Now send the IR signal.
  void SendHitachi(){
#if SEND_HITACHI_AC
  Serial.println("Sending IR command to A/C ...");
  ac.send();
#endif  
  printHitachiState();
  delay(5000);
  }

 void SendDaikin(){
#if SEND_DAIKIN
  Serial.println("Sending IR command to A/C ...");
  ac.send();
#endif  
  printDaikinState();
  delay(5000);
  }
  
void HitachiLoop() {
  if (digitalRead(b1)==HIGH && power == 1){// its on alredy 
    ac.off();
    ac.setFan(1);
    ac.setMode(kHitachiAcCool);
    ac.setTemp(23);
    power = 0;
    SendHitachi();
    delay(1000);
    }
   else if (digitalRead(b1)==HIGH && power == 0){
    ac.on();
    ac.setFan(3);
    ac.setMode(kHitachiAcCool);
    ac.setTemp(20);
    power = 1; 
    SendHitachi();
    delay(1000);
   }
}

void DaikinLoop() {
  if (digitalRead(b1)==HIGH && power == 1){// its on alredy 
    ac.off();
    ac.setFan(3);
    ac.setMode(kDaikinCool);// why are the mode, fan , temp all needed here ???
    ac.setTemp(23);
    power = 0;
    SendDaikin();
    delay(1000);
    }
   else if (digitalRead(b1)==HIGH && power == 0){
    ac.on();
    ac.setFan(3);
    ac.setMode(kDaikinCool);
    ac.setTemp(23);
    power = 1; 
    SendDaikin();
    delay(1000);
   }
}

void loop(){
  if (  y==2 )
{
  DaikinLoop();
  }
  else 
  {
    HitachiLoop();
  }
}

you can see here

void loop(){
if ( y==2 )
{
DaikinLoop();
}
else
{
HitachiLoop();
}

the if condition to choose whose code to run is only an integer, so it's obviously not desired, I'm merely using this to see if the other part of the code is working

so im still having trouble to figure out the if condition, aka, how to pair your universal ac remote to you desired AC, namely, namely, how to program for this process https://www.youtube.com/watch?v=I7hemzOwQig&t=175s

when you try to pair your remote to your AC, you'd be waiting for those codes appear on your screen,

DAIKIN 0171-0183、0566、0567、0685、0693、0696

HITACHI 0118-0126、0500、0501、0631、0637

the remote would beep if its the right number. like in this video:

so what do those codes mean, how would my remote understand those code?

lingsun:
here is my combined code, is this what you mean? it worked

Not exactly. You still only have one ac object. Since you say it works, maybe that doesn't matter. Guessing, I would expect that an ac object of type IRHitachiAc would not work with the Daikin, does it?

Are you saying that the AC units send IR signals that identify them? IIRC, you can persuade an LED to act as a detector too, so you may be able to read what it's saying. Personally, I'd start with a selector switch to choose which model you're working with.

wildbill:
Not exactly. You still only have one ac object. Since you say it works, maybe that doesn't matter. Guessing, I would expect that an ac object of type IRHitachiAc would not work with the Daikin, does it?

Are you saying that the AC units send IR signals that identify them? IIRC, you can persuade an LED to act as a detector too, so you may be able to read what it's saying. Personally, I'd start with a selector switch to choose which model you're working with.

hey sry abt the late response, as I only work on this project 2 days a week.

so I understand when the number goes up on the remote control, the remote is changing its frequency to pair with different AC. but what confused me was, the common frequencies of AC remote are 30, 33, 36, 38, 40, and 56khz, so why are there so many codes to the different AC.

Also, i just can' t figure out how do i use LED as a detector. :confused: