#include <dht.h> //Rob Tilaart library for AVR
#include <LiquidCrystal_I2C.h>
dht DHT;
LiquidCrystal_I2C lcd1(0x27, 16, 2);
const int DHT22_PIN = 4;
const int relayPin = 8;
int temperature;
int humidity;
int dataRead = 0;
bool relayStatus = 0; // Μεταβλητή για την αποθήκευση
// της κατάστασης του ρελέ
void setup()
{
pinMode(relayPin, OUTPUT);
digitalWrite(relayPin, HIGH);
lcd1.init();
lcd1.backlight();
lcd1.setCursor(0, 0);
lcd1.print("Askisi 12-Relay");
lcd1.setCursor(2, 1);
lcd1.print("Thermostat");
delay(2000);
lcd1.clear();
}
void loop()
{
int readData = DHT.read22(DHT22_PIN);
temperature = DHT.temperature;
humidity = DHT.humidity;
if(temperature > 29) // Αν η θερμοκρασία είναι μεγαλύτερη
{ // από κάποιο όριο (26 βαθμούς)
digitalWrite(relayPin, HIGH); // ενεργοποιήσε το ρελε με HIGH
relayStatus = 1; // Αποθήκευσε την κατάσταση του ρελέ
} //
else //
{ // Διαφορετικά
digitalWrite(relayPin, LOW); // Απενεργοποίησε το ρελέ με LOW
relayStatus = 0; // Αποθήκευσε την κατάσταση του ρελέ
}
lcd1.setCursor(1, 0);
lcd1.print("T= ");
lcd1.print(temperature);
lcd1.print((char) 223);
lcd1.print("C");
if(temperature < 10)
{
lcd1.print(" ");
}
lcd1.setCursor(9, 0);
lcd1.print("H= ");
if(humidity < 10)
{
lcd1.print(" ");
}
lcd1.print(humidity);
lcd1.print("%");
lcd1.setCursor(1, 1);
if(relayStatus == 1) // Αν το ρελέ είναι ενεργοποιημένο
{
lcd1.print("The LED is ON "); // Γράψε στην οθόνη The LED is ON
}
else // Αν το ρελέ είναι απενεργοποιημένο
{
lcd1.print("The LED is OFF"); // Γράψε στην οθόνη The LED is OFF
}
}