#include "DHT.h"
#define DHTPIN 3
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const int RELAY_PIN = 9;
void setup() {
// put your setup code here, to run once:
lcd.init();
lcd.backlight();
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
pinMode(RELAY_PIN, OUTPUT);
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(14, 1);
lcd.print(":)");
delay(1000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
//Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) ) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Celsius (isFahreheit = false)
//float hic = dht.computeHeatIndex(t, h, false);
Serial.print(t);
Serial.print(dht.readHumidity());
lcd.setCursor(0, 0);
lcd.print("T: ");
lcd.print(t);
lcd.setCursor(0, 1);
lcd.print("H: ");
lcd.print(h);
lcd.setCursor(14, 1);
lcd.print("(:");
// digitalWrite(RELAY_PIN, HIGH);
delay(1000);
// digitalWrite(RELAY_PIN, LOW);
Serial.println(F("chequ"));
if(t > 20 ){
Serial.println(F("if"));
digitalWrite(RELAY_PIN, HIGH);
}
if(t < 24){
digitalWrite(RELAY_PIN, LOW);
delay(500);
}
}