How to Control the Air Conditioner A/C at Home With Arduino, Even Remotely!

118K8929

Intro: How to Control the Air Conditioner A/C at Home With Arduino, Even Remotely!

Arduino really allows you to do many things concerning the Internet of things, just have a little 'desire and intuition to create any type of project.
In this post we will see how to remote control your air conditioner at home, through the Arduino, which is connected to the Internet. Yes, you just read that right!

Requirements hardware

• 1 x Arduino Uno + 1 x or 2 x Arduino Mega Arduino Uno
• IR receiver TSOP1738
• IR LED
• 1 x 330 Ohm resistor
• Some flexible cable

Requirements software

Library iRemote Arduino
Programs available in my Github repo


STEP 1: How Does the System Work ?

As many will know , the mechanism of regulation of various settings between user and conditioner , is via a remote control , which is based on sending infrared signals . To investigate the function of these signals , I recommend you look at the post in reference to Chapter 10 of the Arduino design becomes simple (in Italian).
Obviously , the code of an air conditioner , vary depending on the model and according to the manufacturer. For this reason, as the first phase of the work , you must do the procedure that is called reverse engineering , that is to obtain the codes for your device , using the sensor TSOP1738 .
Once you have obtained the codes for your air conditioner, we're almost to complete "the work ." You need to use a small program that simplifies setting the code to insert into the Arduino , and you can send the various encodings . These codes can be set by the user through a simple web page , with or without protection.
As you have read in the " Hardware requirements " , I wrote that you need two Arduino , the main reason is that the sequences of bits to be sent to the air conditioners are too large to be contained in a single device , which among other things should also take care of the part of management commands that will be transmitted via the Internet.
In practice there will be a device that will take care of the part webserver and the other to send IR signals . The other reason that prompted me to do this project with two device , is that you can safely use Raspberry PI for the management of the webserver , so definitely improve the look and feel of the web page.

STEP 2: How to Set Up the Various Data

As stated in the previous rows, you must obtain encodings of our remote control to retransmit them to the Arduino. To do this we will make use of the library for Arduino iRemote, in particular this code:

/* Modified by Chris Targett
* Now includes more protocols
* Novemeber 2011

* IRremote: IRrecvDump - dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*
* Modified by Chris Targett to speed up the process of collecting
* IR (HEX and DEC) codes from a remote (to put into and .h file)
*
*/

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
//  decode_results *results = (decode_results *)v
void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
    else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");
  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == SAMSUNG) {
    Serial.print("Decoded SAMSUNG: ");
  }
  else if (results->decode_type == JVC) {
    Serial.print("Decoded JVC: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded Panasonic: ");
  }
  Serial.print(results->value, HEX);
  Serial.print("(");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("#define Something_DEC ");
  Serial.println(results->value, DEC);
  Serial.print("#define Something_HEX ");
  Serial.println(results->value, HEX);
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");
  for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println("");
}

void loop() {
  if (irrecv.decode(&results)) {
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}

You can see in the picture how to link Arduino with the device.

After loading the code on the Arduino, we should press the buttons on the remote control and copy somewhere the results shown by the serial.
In my case, I got the following sequence of encodings:

Accensione 20 C° Caldo
Raw (150): -5320 3000 -3000 3000 -4400 550 -1600 600 -550 550 -1650 550 -550 550 -550 550 -1650 550 -550 550 -1650 500 -550 550 -1650 550 -550 550 -500 600 -500 600 -550 550 -550 550 -1650 500 -550 550 -600 500 -1700 500 -550 550 -550 550 -550 550 -600 500 -550 550 -550 550 -550 550 -550 550 -1650 550 -1650 550 -1650 500 -1650 550 -1650 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -1650 550 -500 550 -550 550 -1700 500 -1650 550 -550 550 -500 600 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 500 -1700 500 -550 550 -550 550 -550 550 -550 550 -550 550 -600 500 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -500 550 -1700 500 -550 550 -550 550 -550 550 -1650 550

Spegnimento
Raw (150): -3276 3100 -2900 2950 -4400 700 -1500 700 -400 700 -1500 700 -400 650 -450 550 -1650 550 -550 650 -1500 600 -500 600 -1600 600 -500 600 -500 600 -450 650 -450 600 -550 550 -550 550 -550 550 -600 500 -1600 600 -500 600 -500 600 -550 550 -500 600 -500 600 -550 550 -550 550 -1600 600 -500 600 -500 600 -500 550 -1650 550 -1600 600 -500 600 -500 600 -550 550 -550 550 -1600 600 -1600 550 -550 550 -550 550 -1650 550 -1600 600 -550 550 -500 600 -500 600 -550 550 -550 550 -500 600 -500 600 -1600 600 -1600 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -500 600 -550 550 -550 550 -500 600 -500 600 -500 600 -1600 600 -500 600 -1600 550 -550 550 -1600 600 -550 550 -550 550

Accensione 23 C° Freddo 2 FAN
Raw (150): -16044 3050 -3000 3000 -4400 550 -1600 600 -550 550 -1650 550 -550 550 -550 550 -1650 550 -500 600 -1600 550 -550 550 -1650 550 -1650 550 -1650 550 -550 550 -550 550 -500 600 -1600 550 -550 550 -550 550 -1650 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -500 600 -1650 500 -550 550 -600 500 -1700 500 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -1650 550 -550 550 -500 550 -1650 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -550 550 -550 550 -550 550 -550 550 -500 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -1600 600 -550 550

Accensione 20 C° Caldo e Swing
Raw (150): 18566 3000 -3000 3000 -4400 550 -1650 550 -500 600 -1600 600 -500 600 -500 600 -1600 550 -550 550 -1650 550 -500 600 -1600 600 -550 550 -550 550 -550 550 -1600 600 -500 600 -500 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -550 550 -1600 550 -550 550 -600 500 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -1650 550 -550 550 -550 550 -1600 550 -1650 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -1650 550 -550 550 -550 550 -550 550 -550 500 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -1650 550 -1650 500 -1650 550 -550 550 -1700 500

Accensione 23 C° Freddo 2 FAN e Swing
Raw (150): 2084 2950 -3050 2950 -4400 550 -1600 600 -550 550 -1650 550 -550 550 -550 550 -1600 600 -500 600 -1600 550 -500 600 -1650 550 -1650 550 -1600 600 -500 600 -1600 600 -500 600 -500 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -500 600 -550 550 -500 600 -1650 550 -550 550 -1600 600 -500 600 -1600 550 -1600 600 -500 600 -500 600 -550 550 -500 600 -1650 550 -1600 600 -500 600 -500 550 -1650 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -500 600 -500 600 -500 600 -500 600 -500 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -550 550 -1650 550 -1650 550 -1600 600 -1600 550 -550 600 -500 550 -550 550 -550 550

As reported in the library iRemote, in order to retransmit these data, it is necessary to make some changes, in particular, need to replace the hyphens, delete the first value and place among the various values​​, a comma, as in the Arduino code will be inserted in a vector of integers.
To facilitate this, I created a small program in Java that can do these tasks automatically.
Also this program is available in the Github repo and is called AcToolArduino. In this first version, the program automates the process by entering the information in the TextField. In the next version, you can load from file, the results obtained from the serial Arduino.

STEP 3: Sending IR Command to A/C

With the following code, you will be able to send IR command to A/C via Arduino:

#include "IRremote.h"

IRsend irsend;

void setup()
{
  Serial.begin(9600);
}

int khz=38; //NB Change this default value as neccessary to the correct modulation frequency
// ON and 2O C° with 1 FAN heat
unsigned heat[] = {3000,3000,3000,4400,550,1600,600,550,550,1650,550,550,550,550,550,1650,550,550,550,1650,500,550,550,1650,550,550,550,500,600,500,600,550,550,550,550,1650,500,550,550,600,500,1700,500,550,550,550,550,550,550,600,500,550,550,550,550,550,550,550,550,1650,550,1650,550,1650,500,1650,550,1650,550,550,550,550,550,550,550,550,550,1650,550,1650,550,500,550,550,550,1700,500,1650,550,550,550,500,600,550,550,550,550,550,550,550,550,550,550,1650,500,1700,500,550,550,550,550,550,550,550,550,550,550,600,500,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,500,550,1700,500,550,550,550,550,550,550,1650,550};
// OFF the A/C
unsigned OFF[] = {3100,2900,2950,4400,700,1500,700,400,700,1500,700,400,650,450,550,1650,550,550,650,1500,600,500,600,1600,600,500,600,500,600,450,650,450,600,550,550,550,550,550,550,600,500,1600,600,500,600,500,600,550,550,500,600,500,600,550,550,550,550,1600,600,500,600,500,600,500,550,1650,550,1600,600,500,600,500,600,550,550,550,550,1600,600,1600,550,550,550,550,550,1650,550,1600,600,550,550,500,600,500,600,550,550,550,550,500,600,500,600,1600,600,1600,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,500,600,550,550,550,550,500,600,500,600,500,600,1600,600,500,600,1600,550,550,550,1600,600,550,550,550,550};
// ON and 23° with 2 FAN cold
unsigned cold[] = {3050,3000,3000,4400,550,1600,600,550,550,1650,550,550,550,550,550,1650,550,500,600,1600,550,550,550,1650,550,1650,550,1650,550,550,550,550,550,500,600,1600,550,550,550,550,550,1650,550,550,550,550,550,550,550,550,550,550,550,550,550,500,600,1650,500,550,550,600,500,1700,500,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,1650,550,550,550,500,550,1650,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,550,550,550,550,550,550,550,550,500,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,1600,600,550,550};
// ON and 20 C° with 1 FAN heat and SWING
unsigned heat_with_swing[] = {3000,3000,3000,4400,550,1650,550,500,600,1600,600,500,600,500,600,1600,550,550,550,1650,550,500,600,1600,600,550,550,550,550,550,550,1600,600,500,600,500,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,550,550,1600,550,550,550,600,500,550,550,550,550,550,550,550,550,550,550,1650,550,1650,550,550,550,550,550,1600,550,1650,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,1650,550,550,550,550,550,550,550,550,500,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,1650,550,1650,500,1650,550,550,550,1700,500};
// ON and 23° with 2 FAN cold and SWING
unsigned cold_with_sqwing[] = {2950,3050,2950,4400,550,1600,600,550,550,1650,550,550,550,550,550,1600,600,500,600,1600,550,500,600,1650,550,1650,550,1600,600,500,600,1600,600,500,600,500,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,500,600,550,550,500,600,1650,550,550,550,1600,600,500,600,1600,550,1600,600,500,600,500,600,550,550,500,600,1650,550,1600,600,500,600,500,550,1650,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,500,600,500,600,500,600,500,600,500,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,1650,550,1650,550,1600,600,1600,550,550,600,500,550,550,550,550,550};

void loop() {

irsend.sendRaw(heat, sizeof(heat)/sizeof(int), khz);
delay(10000);
irsend.sendRaw(OFF, sizeof(OFF)/sizeof(int),khz);
delay(10000);
}

If we went out to operate the air conditioner at home, we are well on track to complete the project!
As indicated previously, it is necessary to use two Arduino, one that manages the webserver, the other that handles the communication with the air conditioner.
To connect the two Arduino in a correct way, care should be taken to the below image.
On the device connected to the Ethernet Shield is necessary to load the program that takes the name of AC_Webpage_Controller.ino, while nell'Arduino that will send IR commands, you must load the program that takes the name of AC_Sender_Code.ino. You can find the software on my Github repo https://github.com/jackbell16/AC-Progetto-Arduino/tree/master/Arduino_Code

Now that we have completed the loading process, we just have to do some work to improve the project, the most useful, is to make it accessible from a remote webserver. To do that we should "open the doors" of our router to properly route requests that are made outside of our local network.
It should be stated that in the version of the code on Github reported, there is no level security password, to simplify a bit 'the project. However, with some modifications to the code AC_Webpage_Controller.ino, you can also implement this feature.

STEP 4: Port Forwarding, to Put the Arduino and A/C on the WEB

The operation of port forwarding, it varies from router to router, but in general, you can proceed as follows:

• Identify the IP address of the webserver Arduino
• Identify the IP address of the gateway
• Open your browser and type the IP address of your router and enter the credentials
• Open the port forwarding section and enter data such as the IP port as the Arduino and 80.

Now we could also access outside of our local network, simply by opening a web page with the public IP of your ADSL connection (to retrieve this value, simply type on Google.com "my ip").
Now we can finally test our project!



STEP 5: Download the Android Application !

If you don't want to use the webpage, you can download the application for Android !

You can do this by typing RemoteAC from the Play Store, or use this link:

https://play.google.com/store/apps/details?id=com....

Remember that once you open the application you need to set the IP of Arduino in the preferences !

19 Comments

Hi can i know should i declare the Ir LED pin ? Because when i run the coding, there's no action to my aircond.
Hey, nice post!
I have a question though:

"int khz=38; //NB Change this default value as neccessary to the correct modulation frequency"

How do you know which frequency you should put in?

Hi everyone I´ve made it but not at all , i have found an issue when i try to send the signal to McQuay air conditioner doesn´t work, I have tried everything as change the frequency, i have been searching on internet hex codes for Mc Quay brand but i haven´t found them. Have someone found the same issue? because I used this instructable to control televisions , air conditioner (other brands),projectors and works.

I can succesfully control my McQuay air conditioner using the Broadlink RM3 (black bean) using https://github.com/davorf/BlackBeanControl to send commands from Linux. Unfortunately the codes seem to be scrambled somehow and I haven't worked out how to decode them. But you can capture all the commands from the remote.

hi jackbell,

I'm trying to emulate your project.

I can successfully receive, record and then send the RAW data (my AC is Hitachi).

However, during the receive / record phase, I noticed that the RAW code changes EVERY time, even if the command is always the same (e.g. I switch on the AC with the same setting, and the code is everytime different).

I also tried to intercept wih another Arduino what the first Arduino is sending (I send the same string every 10 sec), and changes everytime....

Is it normal in your opinion? maybe there is some problem in the IR receiver?

thanks

Had the same problem. Did you find your way out?

My airconditioner's signals were the only ones I could not reproduce. Even when I could detect the same code every time after averaging the raw values from several recordings, the AC did not recognize them. So I used a different library - google for an IR tutorial by ladyada (adafruit) - where the microseconds between each ON and OFF signal are recorded, and suddenly sending this code was recognized by the AC. Keep in mind that the code alternates between AC-ON and AC-OFF every time you press the button, so record at least two button presses.

I also realized that the IRRemote library recorded 68 or 76 (I don't remember which one was my TV) raw values, while the ladyada version detected 100 values (it were 100 even when I tried to record more), so the IRRemote RAW detection seems to fail in some way.

My comfee AC turned on using the standard 38khz modulation. I was using a 2N2222 transistor on an Arduino Nano to make the IR Diode brighter at the time I succeeded, I did not try a direct connection (with a resistor) yet. I'm waiting for a network interface to arrive so I can go on and make my AC controllable from far away.

I have tried Lady Ada example, but it can not detect my AC remote. It works with a samsung TV remote.

So your circuit is fully operational, but the IR receiver is not triggered by your AC remote's IR diode? That is strange. I belive the (usually 38kHz) frequency is being "ignored" by the whole setup as the detector is too sluggish for such fast on-off-signals. That means, even if your AC remote uses a different frequency, it should still be detected.
Another problem might be the wave length of the IR signal. I did not experiment with any but one IR receiver because mine simply worked for the remotes I tried.
Sorry I cannot give a better advise as to get some different IR detectors and see if one responds.

In reverse engineering, my Remote give me FFFFFFFF hex value for all button .please help me to solve this problem.

when I read raw code then I get the following result:


FFFFFFFF(0 bits)
#define Something_DEC 4294967295
#define Something_HEX FFFFFFFF
Raw
(194): -7300 600 -1550 650 -1550 550 -1650 550 -1600 550 -1650 550
-1600 600 -1600 500 -1650 600 -550 550 -550 500 -600 600 -550 600 -500
550 -600 550 -550 600 -500 550 -1650 550 -1600 550 -1650 550 -1600 600
-1600 500 -1650 600 -1600 550 -1600 550 -600 550 -550 600 -500 550 -600
550 -550 600 -500 600 -550 550 -550 600 -1550 550 -1650 600 -1600 550
-1600 500 -1700 550 -1600 600 -1550 550 -1650 600 -550 550 -550 500 -600
600 -550 550 -550 550 -550 550 -600 550 -550 550 -1600 600 -1600 600
-1550 550 -1650 600 -1600 550 -1600 500 -1700 550 -1600 550 -550 600
-550 550 -550 500 -600 600 -550 600 -500 550 -600 550 -550 600 -500 550
-600 550 -1600 550 -550 550 -1650 600 -500 550 -1650 550 -1600 600 -1600
500 -1650 600 -500 600 -1600 600 -550 550 -1600 500 -600 600 -550 550
-550 500 -1700 550 -550 550 -1600 550 -600 550 -1600 600 -550 550 -550
600 -1550 550 -600 550 -1650 550 -550 500 -1650 600 -500 600 -1600 600
-1600 550

I send code o Air conditioner. AC not control

please help me solve problem




What range do you get with the led? or how far do you put the led relative to the AC?

I tried to do the same but I get about 10cm range, this is way too close..

Your Project is really awesome but there is some issues i found explained below :-

i
did same what you did but when i place this setup infront of ac then it
send off and cold signal continously with delay of 1000 ms however it
is supposed to work with commands from webserver. Unfortunately its not
working. i think we have to setup code in Arduino uno shield which is
connected to IR LED to send signal only after received from Arduino
Mega(Connected with ethernet shield). please help and let me know how to
fix this. i will be very thankful to you..

Hi

my A/C can't seem to detect the IR codes sent while the detector is detecting the same code can someone help ?

Thnks

Hello,

How should I fix the code to send only on/off signals? With them only 1 Uno will be enough I guess.

Many thanks Rossos for "RAWBUF" hint as for my A/C (Sharp) code length is (212) so I increased RAWBUF to 255 then got it worked.

Main thanks for auther jackbell16.

Hi,

I’m irinakim and I’m work in the Wiznet.

Thank you for using our product.

We are collecting so much data using ourproduct.

And I will post the this project on our Web site.( http://wiznetmuseum.com)

Can I post your product on our Web site?

my A/C can't seem to detect the IR codes sent via TR LED can someone help ?

I've Made it! (sry no pictures)

One small remark: if you have Sony or some other R5/R6 protocol Infrared remote control, which apparently sends their signal 3 times instead of using checksum last bits, you may need to open up <IRremote.h> file manually and go all the way down and adjust the RAWBUF constant. By default it is 100, but my codes were of the size 182. I've set the constant to 192 (higher values were causing crashes on my Arduino Nano) and everything started working.