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;
}