空调(空调)曾经被认为是奢侈品,只能在大酒店,电影院,餐馆等中找到...但是,现在几乎每个人都在家里有空调来度过夏天/冬天,而那些拥有它的人担心一件共同的事情。这就是他们的高耗电量和充电器。在这个项目中,我们将制作一个小型的自动温度控制电路,该电路可以通过根据室温自动改变交流温度来最小化充电器。通过定期改变设定温度,我们可以避免使交流电长时间以较低的温度值工作,从而使其消耗更少的功率。
我们大多数人都会遇到这样一种情况,即我们必须在一天中的不同时间将空调的设定温度更改为不同的值,以使我们始终保持舒适。为了自动化此过程,该项目使用温度传感器(DHT11),该传感器读取房间的当前温度,并根据该值,它将通过类似于AC遥控器的红外发射器向AC发送命令。AC 将对这些命令做出反应,就像它对遥控器做出反应一样,从而调节温度。随着房间温度的变化,Arduino还会调整空调的设定温度,以您想要的方式保持您的温度。听起来很酷吧?...让我们看看如何构建一个。
所需材料:
阿杜伊诺超级 2560
TSOP1738 (HS0038)
红外灯
DHT11 温度/湿度传感器
面包板
连接线
工作方法:
我们家中用于控制电视、家庭影院、空调等的所有遥控器都在红外发射器的帮助下工作。红外发射器只不过是一个红外 LED,可以通过重复脉冲来冲击信号;该信号将由电子设备中的接收器读取。对于遥控器上的每个不同按钮,将发出一个独特的信号,该信号在接收器读取后用于执行特定的预定义任务。如果我们能够读取从遥控器发出的信号,那么我们可以在需要执行该特定任务时使用红外 LED 模拟相同的信号。
TSOP是一种红外接收器,可用于解码来自遥控器的信号。该接收器将与Arduino接口,为每个按钮发送信号,然后IR LED将与Arduino一起使用,以在需要时模拟信号。这样,我们就可以使用Arduino控制AC。
现在,剩下的就是使用 DHT11 读取温度值,并使用 IR 信号相应地指示 AC。为了使项目看起来更具吸引力和用户友好性,我还添加了一个OLED显示屏,可以显示当前的温度,湿度和AC设定温度。
交流遥控器的工作:
在我们进入项目之前,请花一些时间并注意您的交流遥控器的工作原理。与电视、DVD 红外遥控器相比,交流遥控器的工作方式略有不同。遥控器上可能只有 10-12 个按钮,但它们将能够发送许多不同类型的信号。这意味着遥控器不会每次为同一按钮发送相同的代码。例如,当您使用向下按钮降低温度使其为 24°C(摄氏度)时,您将获得带有一组数据的信号,但是当您再次按下它以设置 25°C 时,您将不会获得相同的数据,因为温度现在是 25 而不是 24。同样,25 的代码也会因不同的风扇速度、睡眠设置等而异。因此,我们不要摆弄所有选项,而只是将温度值与其他设置的恒定值集中在一起。
另一个问题是每次按下按钮发送的数据量,普通遥控器发送 24 位或 48 位,但交流遥控器最多可以发送 228 位,因为每个信号都包含大量信息,如温度、风扇速度、睡眠时间、摆动风格等。这就是为什么我们需要Arduino Mega以获得更好的存储选项的原因。
电路图及说明:
幸运的是,这个自动交流温度控制项目的硬件设置非常简单。您可以简单地使用面包板并进行连接,如下所示。
下表还可用于验证连接。
S.No: | 元件引脚 | 阿杜伊诺引脚 |
1 | OLED – Vcc | 5V |
2 | OLED – Gnd | 格德 |
3 | OLED- SCK, D0,SCL,CLK | 4 |
4 | OLED-SDA, D1,MOSI, Data | 3 |
5 | OLED- RES, RST,RESET | 7 |
6 | OLED- 直流,A0 | 5 |
7 | OLED- CS,芯片选择 | 6 |
8 | DHT11 – Vcc | 5V |
9 | DHT11 – Gnd | 格德 |
10 | DHT11 – 信号 | 13 |
11 | TSOP – Vcc | 5V |
12 | TSOP – Gnd | 格德 |
13 | 红外发光二极管 – 阳极 | 9 |
14 | 红外发光二极管 – 阴极 | 格德 |
连接完成后,它应该如下所示。我使用面包板来整理东西,但您也可以直接将公对母线连接到所有组件
解码交流远程信号:
控制交流电的第一步是使用 TSOP1738解码交流遥控红外代码。按照电路图中所示进行所有连接,并确保已安装所有提到的库。现在打开示例程序“IRrecvDumpV2”,可以在文件 -> 示例 -> IRremote -> IRrecvDumpV2 中找到。将程序上传到Arduino Mega并打开串行监视器。
将遥控器指向 TSOP 并按任意按钮,对于您按下的每个按钮,信号将由 TSOP1738 读取,由 Arduino 解码并显示在串行监视器中。对于遥控器温度的每次变化,您将获得不同的数据。保存此数据,以便我们将在主程序中使用它。您的串行监视器将看起来像这样,我还显示了保存复制数据的Word文件。
屏幕截图显示了将我的交流遥控器的温度设置为 26°C 的代码。根据您的遥控器,您将获得一组不同的代码。同样,复制所有不同温度水平的代码。
主要Arduino程序:
完整的Arduino主程序可以在此页面底部找到,但您不能使用相同的程序。您必须更改我们刚刚从上面的示例草图中获得的信号代码值。打开Arduino IDE上的主程序,然后向下滚动到下面显示的该区域,您必须将数组值替换为为遥控器获得的值。
请注意,我使用了 10 个阵列,其中两个用于打开和关闭交流电,而其余 8 个用于设置不同的温度。例如,Temp23 用于在交流电上设置 23°C,因此请使用该阵列中的相应代码。完成后,您只需将代码上传到Arduino并将其放在AC对面,即可享受凉风。
代码的解释如下,首先我们必须使用DHT1温度传感器读取温度和湿度并将其显示在OLED上。这是通过以下代码完成的。
DHT.read11(DHT11_PIN); //Read the Temp and Humidity
Measured_temp = DHT.temperature + temp_error;
Measured_Humi = DHT.humidity;
// 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("%");
一旦我们知道房间的温度,我们只需要将其与所需的值进行比较。这个期望值是一个常量值,在我的程序中设置为 27°C(摄氏度)。因此,基于此比较,我们将设置相应的交流温度,如下所示
if (Measured_temp == Desired_temperature+3) //If AC is ON and measured temp is very high than desired
{
irsend.sendRaw(Temp24, sizeof(Temp24) / sizeof(Temp24[0]), khz); delay(2000);//Send signal to set 24*C
AC_Temp = 24;
}
当测量温度为 30°C 时,此处的 AC 将设置为 24°C(因为所需温度为 27)。同样,我们可以创建许多 If 循环,以根据测量的温度设置不同的温度级别,如下所示。
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;
}
自动交流温控系统工作原理:
当您的代码和硬件准备就绪时,将代码上传到您的主板,您应该注意到 OLED 显示与此类似的内容。
现在将电路放在空调的对面,您会注意到空调的温度会根据室温进行控制。
您可以调整程序以执行任何所需的操作;您所需要的只是从示例草图中获取的代码。希望您了解这个自动温度控制器项目,并喜欢构建非常相似的东西。
/*
* Automatic AC Temperature control using Arduino and TSOP
* Code by: Aswinth Raj B
* Dated: 25-10-2017
* Website: www.circuitdigest.com
*
S.No: Component Pin Arduino Pin
1 OLED – Vcc 5V
2 OLED – Gnd Gnd
3 OLED- SCK, D0,SCL,CLK 4
4 OLED- SDA, D1,MOSI, Data 3
5 OLED- RES, RST,RESET 7
6 OLED- DC, A0 5
7 OLED- CS, Chip Select 6
8 DHT11 – Vcc 5V
9 DHT11 – Gnd Gnd
10 DHT11 – Signal 13
11 TSOP – Vcc 5V
12 TSOP – Gnd Gnd
13 IR Led – Anode 9
14 IR Led – Cathode Gnd
*/
#include //Lib for IT Blaster and TSOP
#include // Inbuilt Lib
#include //Inbuilt Lib
#include //Lib for OLED
#include //Lib for OLED
#include //Library for dht11 Temperature and Humidity sensor (Download from Link in article)
// Assign pins for OLED (Software config.)
#define OLED_MOSI 3
#define OLED_CLK 4
#define OLED_DC 5
#define OLED_CS 6
#define OLED_RESET 7
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
#define SSD1306_LCDHEIGHT 64 //Change if you are using a Different OLED
#define DHT11_PIN 13 //Sensor output pin is connected to pin 13
dht DHT; //Sensor object named as DHT
#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[] = {2950,1750, 400,1100, 450,1050, 450,400, 400,400, 400,400, 450,1100, 400,400, 400,400, 450,1100, 400,1100, 450,350, 450,1100, 400,400, 400,400, 450,1100, 400,1100, 450,400, 400,1100, 400,1100, 450,400, 400,400, 400,1100, 450,350, 450,400, 400,1100, 450,400, 400,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,350, 450,350, 450,1100, 400,400, 450,400, 400,1100, 450,1050, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,1100, 450,350, 450,400, 400,400, 400,400, 450,400, 400,1100, 450,350, 450,400, 400,400, 400,400, 400,1100, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 450,350, 450,350, 450,400, 400,1100, 450,350, 450,350, 450,400, 450,350, 450,350, 450,1100, 450};
unsigned int ACon[] = {2950,1700, 450,1100, 400,1100, 450,350, 450,350, 450,400, 450,1050, 450,350, 450,400, 450,1050, 450,1100, 400,400, 450,1050, 450,350, 450,400, 400,1100, 450,1100, 450,350, 450,1050, 450,1100, 450,350, 450,350, 450,1100, 450,350, 400,400, 450,1100, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,1100, 400,400, 450,350, 450,1100, 400,400, 450,350, 450,1100, 400,1100, 450,350, 450,400, 400,400, 450,350, 500,300, 450,400, 450,350, 400,400, 450,1100, 400,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,1100, 450,350, 400,400, 450,350, 450,400, 450,350, 400,400, 450,400, 450,350, 450,350, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 400,400, 450,350, 450,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 450,350, 400,400, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 450,350, 450,1100, 400,400, 400,400, 450,350, 450,350, 450,1100, 400,400, 450};
unsigned int Temp23[] = {3000,1650, 550,950, 550,1000, 500,300, 550,250, 550,250, 550,1000, 500,300, 550,300, 500,1000, 550,950, 550,300, 550,950, 550,250, 550,300, 500,1000, 500,1050, 500,300, 500,1000, 550,1000, 500,300, 500,300, 550,1000, 450,350, 500,300, 500,1050, 450,350, 450,350, 450,350, 450,400, 450,350, 450,350, 450,400, 400,400, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,1100, 400,400, 400,400, 450,1050, 450,400, 400,400, 450,1100, 400,1100, 400,400, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 450,350, 450,1100, 400,400, 400,400, 450,350, 450,400, 400,400, 450,1100, 400,400, 400,1100, 450,1100, 400,1100, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,350, 450,400, 450,350, 400,400, 450,350, 450,400, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,350, 450,1100, 400,1100, 450,1100, 400,1100, 450,1100, 400,1100, 400,400, 450};
unsigned int Temp24[] = {3000,1650, 500,1050, 500,1000, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 500,300, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 500,300, 500,1000, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,1000, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,1000, 500,1050, 500,1000, 500,300, 500,350, 450,350, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,1050, 500,1000, 500,1050, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,300, 500,350, 500,300, 450,350, 500,350, 450,350, 450,350, 450,350, 450,400, 400,400, 400,400, 450,400, 400,400, 400,400, 400,400, 450,350, 450,400, 400,400, 450,350, 450,400, 450,350, 450,350, 450,350, 450,400, 450,350, 450,350, 450,350, 500,350, 450,1050, 500,300, 500,1050, 500,1000, 500,1050, 500,1000, 500,1000, 500,350, 550};
unsigned int Temp25[] = {3050,1650, 500,1000, 550,950, 550,300, 500,300, 500,300, 550,1000, 500,300, 500,300, 550,1000, 550,950, 550,250, 550,1000, 500,300, 550,250, 550,1000, 500,1000, 550,300, 550,950, 550,950, 550,300, 500,300, 500,1000, 550,250, 550,300, 550,950, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 600,250, 500,300, 550,250, 550,250, 550,300, 550,250, 500,300, 550,300, 500,300, 500,1000, 550,250, 550,300, 500,1000, 550,250, 550,300, 500,1000, 550,1000, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,1000, 550,950, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,950, 550,300, 500,1000, 550,1000, 500,1000, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 500,350, 500,1000, 500,1000, 500,1050, 500,1000, 500,1050, 500,300, 550};
unsigned int Temp26[] = {3000,1650, 500,1000, 500,1050, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 450,350, 500,1000, 500,300, 500,350, 500,1000, 500,1050, 500,300, 500,1000, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,300, 500,300, 500,1050, 450,350, 500,300, 500,1050, 500,1000, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,1000, 500,300, 500,1050, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,300, 500,1050, 450,1050, 500,1000, 500,350, 500,300, 500,300, 500,350, 450,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 450,350, 500,300, 500,350, 450,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 500,300, 500,300, 500,300, 500,350, 500,300, 500,300, 500,350, 450,1050, 500,1000, 500,350, 500,1000, 500,1000, 500,1050, 500,1000, 500,350, 500};
unsigned int Temp27[] = {3050,1600, 550,1000, 500,1000, 550,300, 500,300, 550,250, 550,1000, 500,300, 550,300, 500,1000, 550,1000, 500,300, 550,1000, 550,250, 500,300, 550,1000, 500,1050, 500,300, 500,1000, 550,1000, 500,300, 550,250, 550,1000, 550,250, 550,300, 500,1000, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 500,1000, 550,300, 500,300, 550,1000, 500,300, 500,300, 550,1000, 550,1000, 500,300, 500,300, 550,250, 550,300, 500,300, 550,300, 500,300, 500,300, 550,1000, 500,300, 550,250, 550,300, 500,300, 500,300, 500,350, 500,300, 550,250, 550,1000, 500,1000, 550,1000, 500,300, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 500,300, 550,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 500,300, 500,350, 500,300, 500,350, 500,300, 500,300, 500,1050, 500,1000, 500,1050, 500,1000, 500,350, 500}; // PANASONIC C4D3:64800024
unsigned int Temp28[] = {3100,1600, 550,950, 550,1000, 550,250, 550,250, 550,250, 550,1000, 500,300, 500,300, 550,1000, 500,1000, 550,250, 550,1000, 500,300, 550,250, 550,1000, 550,950, 550,300, 500,1000, 550,950, 550,300, 550,250, 500,1000, 550,300, 500,300, 550,950, 550,300, 500,300, 500,300, 550,250, 550,300, 550,250, 500,300, 550,300, 500,300, 500,300, 550,250, 550,250, 600,250, 500,300, 500,300, 550,300, 500,300, 500,1000, 550,300, 500,300, 500,1000, 550,250, 550,300, 500,1000, 550,1000, 550,250, 550,250, 550,250, 550,300, 500,300, 550,250, 550,1000, 500,1000, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,1000, 500,300, 500,1000, 550,1000, 500,1000, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 550,250, 500,300, 550,250, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,1000, 500,300, 500,300, 550,950, 550,1000, 500,1000, 550,1000, 500,300, 550};
unsigned int Temp29[] = {3100,1550, 600,950, 500,1000, 550,300, 500,300, 500,300, 550,950, 550,300, 550,250, 550,1000, 500,1000, 550,250, 550,1000, 500,300, 550,250, 550,950, 600,950, 550,250, 550,1000, 500,1000, 550,250, 600,250, 550,950, 550,250, 550,300, 550,950, 550,250, 550,300, 550,250, 550,250, 550,250, 550,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,250, 600,250, 550,950, 550,250, 550,300, 500,1000, 550,250, 550,300, 550,950, 550,1000, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,1000, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,300, 500,1000, 550,250, 550,1000, 500,1000, 550,1000, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,250, 550,1000, 500,1000, 550,1000, 500,1000, 550,300, 500};
unsigned int Temp30[] = {3000,1650, 500,1000, 550,1000, 500,300, 500,300, 550,250, 550,1000, 500,300, 500,300, 550,1000, 550,950, 550,250, 550,1000, 550,250, 550,250, 550,1000, 550,950, 550,300, 500,1000, 550,950, 550,300, 500,300, 550,950, 550,300, 550,250, 550,1000, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,300, 500,300, 500,300, 550,950, 550,300, 500,300, 500,1000, 550,250, 550,300, 550,950, 550,1000, 500,300, 550,250, 550,250, 600,250, 500,300, 550,250, 550,1000, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,950, 550,300, 500,1000, 550,950, 550,1000, 500,300, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,250, 550,300, 500,300, 550,250, 550,300, 500,300, 500,300, 550,250, 550,300, 500,300, 550,950, 500,1050, 500,1000, 500,350, 500,1000, 500,1000, 500,1050, 500,300, 500};
//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();
}
void loop() {
DHT.read11(DHT11_PIN); //Read the Temp and Humidity
Measured_temp = DHT.temperature + temp_error;
Measured_Humi = DHT.humidity;
// 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;
}
-
红外发射器
+关注
关注
0文章
46浏览量
16204 -
温度控制器
+关注
关注
1文章
175浏览量
33790 -
Arduino
+关注
关注
187文章
6463浏览量
186617 -
DHT11
+关注
关注
19文章
277浏览量
57540
发布评论请先 登录
相关推荐
评论