#include <DHT.h>
#include <Wire.h> // библиотека для управления устройствами по I2C
#include <LiquidCrystal_I2C.h> // подключаем библиотеку для QAPASS 1602
#define DHTTYPE DHT22
#define DHTPIN 3
#define relayPin_warm 2
#define relayPin_cold 11
DHT dht(DHTPIN, DHTTYPE);
float hum;
float temp;
byte temp_status = 0;
unsigned long timer = 0;
/*
start - temp_status = 0
too cold - temp_status = 1
too warm - temp_status = 2
*/
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
Serial.begin(9600);
pinMode(relayPin_warm, OUTPUT);
pinMode(relayPin_cold, OUTPUT);
dht.begin();
lcd.begin(16, 2);
}
void loop(){
if (millis() - timer > 1000) {
timer = millis();
hum = dht.readHumidity();
temp = dht.readTemperature();
// temp = 15;
if (temp < 18) {
if (temp_status != 1) {
if (temp_status == 2) {
digitalWrite(relayPin_warm, LOW); // disable warm relay
}
digitalWrite(relayPin_cold, HIGH); // enable cold relay
temp_status = 1;
}
}
else if (temp > 21) {
if (temp_status != 2) {
if (temp_status == 1) {
digitalWrite(relayPin_cold, LOW); // disable cold relay
}
digitalWrite(relayPin_warm, HIGH); // enable warm relay
temp_status = 2;
}
}
else {
if (temp_status) {
if (temp_status == 1) {
digitalWrite(relayPin_cold, LOW); // disable cold relay
}
else if (temp_status == 2) {
digitalWrite(relayPin_warm, LOW); // disable warm relay
}
temp_status = 0;
}
}
lcd.setCursor(0, 0); // working with
lcd.print("15:51 28.11.2022");
lcd.setCursor(0, 1); // lcd dispaly
lcd.print("t: "); //
lcd.print(temp); //
lcd.print(' ');
lcd.print("h: "); //
lcd.print(hum); //
}
}