Automatic AC Temperature Control

Everything related to protocols and IR codes
Post Reply
elfadlulhadi
Posts: 2
Joined: Fri Mar 06, 2020 5:02 pm

Automatic AC Temperature Control

Post by elfadlulhadi »

Hi! I am doing a mini-project of automatic AC temperature control. Here, I use DHT11 temperature sensor, IR led (transmitter), TSOP (receiver) and OLED. The whole code is working and the IR led is sending the signal as I can see the TSOP is receiving signal. However, the AC (GREE) is not responding to the instruction/code. The AC remains in the same temperature. It would be grateful if anybody able to help me.
Here is my code

Code: Select all

#include <IRremote.h> //Lib for IT Blaster and TSOP
#include <SPI.h> // Inbuilt Lib
#include <Wire.h> //Inbuilt Lib
#include <Adafruit_GFX.h> //Lib for OLED
#include <Adafruit_SSD1306.h> //Lib for OLED
#include "DHT.h"
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels


#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define NUMFLAKES     10

#define LOGO_HEIGHT   16
#define LOGO_WIDTH    16

#define DHTPIN 13   
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

#define Desired_temperature 27 //The desired temperature is 27*C at any time

//Decoded Remote Signals For my AC ##CHANGE IT FOR YOUR REMOTE
unsigned int ACoff[] = {8850,4400, 700,1600, 650,500, 700,500, 650,550, 650,500, 700,500, 650,1600, 700,500, 650,1600, 700,1550, 700,1600, 650,500, 700,500, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,1550, 700,500, 700,500, 650,500, 700,500, 700,500, 650,500, 700,500, 700,500, 650,550, 650,1600, 650,500, 700,1600, 650,500, 700,500, 700,1600, 650,500, 700};  // NEC 82E1200A
unsigned int ACon[] = {8900,4350, 700,1600, 650,550, 650,550, 650,1600, 650,550, 650,500, 700,1600, 650,500, 700,1600, 650,500, 700,1600, 650,1600, 650,1600, 650,500, 700,500, 700,1600, 650,500, 700,500, 700,1550, 700,500, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,500, 650,500, 700,500, 650,1650, 650,500, 700,1600, 650,500, 700,500, 650,1600, 650,550, 650};  // NEC 92B9220A 
unsigned int Temp23[] = {8850,4400, 650,1600, 700,500, 650,550, 650,1600, 650,550, 650,550, 650,1600, 650,550, 650,1600, 650,1600, 650,1600, 650,550, 650,550, 650,500, 650,550, 650,1600, 650,550, 650,550, 650,1600, 700,500, 650,500, 650,550, 650,1600, 650,550, 650,550, 650,500, 650,550, 650,550, 650,1600, 650,550, 650,1600, 650,550, 650,500, 650,1650, 650,500, 650};  // NEC 92E1220A   
unsigned int Temp24[] = {8850,4350, 700,1600, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,1550, 700,500, 700,500, 650,500, 700,500, 700,1550, 700,500, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,1550, 650,550, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,500, 650,500, 700,500, 700,1550, 700,500, 700,1550, 700,500, 700,500, 650,1600, 650,550, 650};  // NEC 9211220A
unsigned int Temp25[] = {8850,4350, 700,1600, 650,550, 650,500, 700,1600, 650,500, 700,500, 650,1600, 650,550, 650,1600, 650,550, 650,550, 650,1600, 650,550, 650,500, 700,500, 650,1600, 650,550, 650,550, 650,1600, 650,550, 650,500, 700,500, 650,1600, 700,500, 650,550, 650,500, 700,500, 650,550, 650,1600, 650,550, 650,1600, 650,550, 650,500, 700,1600, 650,500, 700};  // NEC 9291220A   
unsigned int Temp26[] = {8850,4350, 700,1600, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,1550, 650,550, 700,500, 650,1600, 700,500, 650,1600, 700,500, 650,500, 700,500, 700,1550, 650,550, 700,500, 650,1600, 700,500, 650,500, 700,500, 700,1550, 700,500, 700,500, 650,500, 700,500, 700,500, 650,1600, 650,550, 650,1600, 650,550, 650,500, 700,1600, 650,500, 700};  // NEC 9251220A
unsigned int Temp27[] = {8850,4350, 700,1600, 650,550, 650,500, 700,1600, 650,500, 700,500, 700,1550, 700,500, 700,1550, 700,1600, 650,500, 700,1600, 650,500, 700,500, 700,500, 650,1600, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,500, 650,1600, 700,500, 650,500, 700,500, 700,500, 650,500, 700,1600, 650,500, 700,1600, 650,500, 700,500, 700,1550, 700,500, 700};  // NEC 92D1220A
unsigned int Temp28[] = {8850,4400, 700,1550, 700,500, 700,500, 650,1600, 650,550, 650,500, 700,1600, 650,500, 700,500, 700,500, 650,1600, 650,1600, 700,500, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,1550, 700,500, 700,500, 650,500, 700,1600, 650,500, 700,500, 700,500, 650,500, 700,500, 700,1550, 700,500, 700,1550, 650,550, 700,500, 650,1600, 700,500, 650};  // NEC 9231220A
unsigned int Temp29[] = {8850,4400, 700,1550, 700,500, 700,500, 650,1600, 650,550, 650,500, 700,1600, 650,500, 700,1600, 650,500, 700,1600, 650,1600, 650,550, 650,500, 700,500, 650,1600, 650,550, 650,550, 650,1600, 650,550, 650,500, 700,500, 650,1600, 650,550, 650,550, 650,500, 700,500, 650,550, 650,1600, 650,550, 650,1600, 650,550, 650,500, 700,1600, 650,500, 700};  // NEC 92B1220A
unsigned int Temp30[] = {8900,4350, 700,1600, 650,500, 700,500, 700,1550, 700,500, 700,500, 650,1600, 650,550, 650,500, 700,1600, 650,1600, 650,1600, 650,1650, 650,500, 700,500, 650,1600, 700,500, 650,550, 650,1600, 650,550, 650,500, 700,500, 650,1600, 700,500, 700,500, 650,500, 700,500, 700,500, 650,1600, 700,500, 650,1600, 700,500, 650,500, 700,1600, 650,500, 700};  // NEC 9279220A   
//Change it for your remote

IRsend irsend;

int Measured_temp;
int Measured_Humi;
int AC_Temp;
char temp_error = 2;
int Pev_value;
boolean AC = false;

int khz = 38; // 38kHz carrier frequency for the NEC protocol

void setup()
{
  Serial.begin(9600);
  display.begin(SSD1306_SWITCHCAPVCC);
  display.clearDisplay();
  dht.begin();
}

void loop() {
  delay(2000);
//  DHT.read11(DHT11_PIN); //Read the Temp and Humidity
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
 
  Measured_temp =  t;
  Measured_Humi =  h;
 

  Serial.print(F("Measured Humi: "));
  Serial.print(Measured_Humi);
  Serial.print(F("%  Measured Temp: "));
  Serial.print(Measured_temp);
  Serial.print(F("°C "));

// text display tests
 display.setTextSize(1);
 display.setTextColor(WHITE);
 display.setCursor(0,0);
 display.print("Temperature: "); display.print(Measured_temp);display.println("C");
 display.setCursor(0,10);
 display.print("Humidity: "); display.print(Measured_Humi);display.println("%");
 display.setCursor(0,20);
 display.print("AC Temp: "); display.print(AC_Temp);display.println("C");

 display.display();
 delay(500);
 display.clearDisplay();
 
 if ((Measured_temp <= (Desired_temperature-3)) && AC == true) //If AC is turned on and temperature is less than 3 degree of Desired value #24 turn off
 {
  irsend.sendRaw(ACoff, sizeof(ACoff) / sizeof(ACoff[0]), khz);  delay(2000);//Send signal to Turn Off the AC
  AC_Temp = 0; AC=false;
 }

 if ((Measured_temp >= Desired_temperature+4) && AC == false) //If AC is off and measured Temp is greater than Desired Temp
 {
  irsend.sendRaw(ACon, sizeof(ACon) / sizeof(ACon[0]), khz); delay(2000); //Send Signal to Turn On the AC
  delay(2000);
  irsend.sendRaw(Temp27, sizeof(Temp27) / sizeof(Temp27[0]), khz); //Send signal to set 27*C
  AC_Temp = 27; AC=true;
 }

  if ( Measured_temp != Pev_value) //Change the temperature only if the measured voltage value changes
  {

  if (Measured_temp == Desired_temperature+3) //If AC is ON and measured temp is very very high than desired
  {
   irsend.sendRaw(Temp24, sizeof(Temp24) / sizeof(Temp24[0]), khz); delay(2000);//Send signal to set 24*C
  AC_Temp = 24;
  }

  if (Measured_temp == Desired_temperature+2) //If AC is ON and measured temp is very high than desired
  {
   irsend.sendRaw(Temp25, sizeof(Temp25) / sizeof(Temp25[0]), khz); delay(2000);//Send signal to set 25*C
  AC_Temp = 25;
  }

  if (Measured_temp == Desired_temperature+1) //If AC is ON and measured temp is very high than desired
  {
   irsend.sendRaw(Temp26, sizeof(Temp26) / sizeof(Temp26[0]), khz); delay(2000);//Send signal to set 26*C
  AC_Temp = 26;
  }

  if (Measured_temp == 27 ) //If AC is ON and measured temp is desired value
  {
  irsend.sendRaw(Temp27, sizeof(Temp27) / sizeof(Temp27[0]), khz); //Send signal to set 27*C
  AC_Temp = 27;
  }

  if (Measured_temp == Desired_temperature-1) //If AC is ON and measured temp is low than desired value
  {
  irsend.sendRaw(Temp28, sizeof(Temp28) / sizeof(Temp28[0]), khz); delay(2000);//Send signal to set 28*C
  AC_Temp = 28;
  }

  if (Measured_temp == Desired_temperature-2 ) //If AC is ON and measured temp is very low than desired value
  {
  irsend.sendRaw(Temp29, sizeof(Temp29) / sizeof(Temp29[0]), khz); delay(2000);//Send signal to set 29*C
  AC_Temp = 29;
  }

  if (Measured_temp == Desired_temperature-3 ) //If AC is ON and measured temp is very very low desired value
  {
  irsend.sendRaw(Temp30, sizeof(Temp30) / sizeof(Temp30[0]), khz); delay(2000);//Send signal to set 30*C
  AC_Temp = 30;
  }

  }
  Pev_value = Measured_temp;
  }
User avatar
AnalysIR
Site Admin
Posts: 794
Joined: Sat Aug 31, 2013 3:51 pm
Location: Dublin, Ireland
Contact:

Re: Automatic AC Temperature Control

Post by AnalysIR »

When posting, please use code tags for inserting code (I cleaned it up for you above. Also please format the code in your IDE before posting!).

I checked your TEMP23 signal with AnalysIR & it decodes as GREE 64 bit AC signal.

Try the following with a basic IRremote sketch (nothing else):

Code: Select all

/*
Automatically Generated by AnalysIR - Batch Export Utility
Registered to: xxxxxxxx
Session History
Type : Key : Value : Bits : Carrier Frequency (kHz)
0 : GREE32_64_128AC :  : 92E1220A : 32 : 0
Note: Be sure to use the correct Carrier frequency, for each individual signal, as(or if) indicated above
*/

// NB: Not all protocols are supported by IRremote or IRLib. You may need to edit the code below manually
// Automatically Generated by AnalysIR for xxxxxxxx, visit https://www.AnalysIR.com/ or email info@....... for further details
int khz=38; //NB Change this default value as neccessary to the correct carrier frequency


unsigned int Signal_0_0[] = {9000,4500,600,1690,600,600,600,600,600,1690,600,600,600,600,600,1690,600,600,600,1690,600,1690,600,1690,600,600,600,600,600,600,600,600,600,1690,600,600,600,600,600,1690,600,600,600,600,600,600,600,1690,600,600,600,600,600,600,600,600,600,600,600,1690,600,600,600,1690,600,600,600,600,600,1690,600,600,600}; //AnalysIR Batch Export (IRremote) - RAW

irsend.sendRaw(Signal_0_0, sizeof(Signal_0_0)/sizeof(int), khz); //AnalysIR Batch Export (IRremote) - RAW
 // AnalysIR IR Protocol: GREE32_64_128AC, Key:  
The signal above was 'cleaned by AnalysIR'.
elfadlulhadi
Posts: 2
Joined: Fri Mar 06, 2020 5:02 pm

Re: Automatic AC Temperature Control

Post by elfadlulhadi »

I am sorry for the messy post. However, I've tried your code and it still doesn't work (AC is not responding). Could you please give me the signal only for turning on the AC?
Thanks for your assistance
User avatar
AnalysIR
Site Admin
Posts: 794
Joined: Sat Aug 31, 2013 3:51 pm
Location: Dublin, Ireland
Contact:

Re: Automatic AC Temperature Control

Post by AnalysIR »

Try this sketch from our blog to record your signals.
https://www.analysir.com/blog/2014/03/1 ... s-arduino/

Also, make sure you AC is OFF before trying to turn it ON!

You can adjust any signal you have using the timings I provided in my last post...just swap the values with the closest value from my signal.

If it still does not work...then we should consider what you are using to send the signals. In this case please post photos of your setup showing the wiring and provide details of your IR emitter circuit.

Make sure to point the IR LED directly at the AC unit and get as close a possible for testing.
Post Reply