#include <DHT22.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2);
#define relay 2
#define pinDATA 3
DHT22 dht22(pinDATA);
void setup() {
// put your setup code here, to run once:
pinMode(relay, OUTPUT);
Serial.begin(115200); //1bit=10µs
Serial.println("\ntest capteur DTH22");
lcd.init();
lcd.backlight();
}
void loop() {
float temp = dht22.getTemperature();
float h = dht22.getHumidity();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Suhu:");
lcd.print(temp);
lcd.setCursor(0,1);
lcd.print("Kelembaban: ");
lcd.print(h);
if (dht22.getLastError() != dht22.OK) {
Serial.print("last error :");
Serial.println(dht22.getLastError());
}
if (temp > 25){
digitalWrite(relay, HIGH);
}
else {
digitalWrite(relay, LOW);
}
Serial.print("h=");Serial.print(h,1);Serial.print("\t");
Serial.print("temp=");Serial.println(temp,1);
delay(2000); //Collecting period should be : >1.7 second
}