#include <dht.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
dht DHT;
#define DHT22_PIN 2
void setup()
{
Serial.begin(115200);
Serial.println("dht22_test.ino");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%)");
lcd.init(); // เริ่มต0น LCD
lcd.backlight();
}
void loop()
{
Serial.print("DHT22, \t");
uint32_t start = micros();
int chk = DHT.read22(DHT22_PIN);
uint32_t stop = micros();
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.print(DHT.temperature, 1);
Serial.print(",\t");
Serial.print(stop - start);
Serial.println();
lcd.setCursor(0, 0);
lcd.print("hum: ");
lcd.setCursor(4, 0);
lcd.print(DHT.humidity);
lcd.setCursor(9, 0);
lcd.print("%");
lcd.setCursor(0, 1);
lcd.print("Tem: ");
lcd.setCursor(4, 1);
lcd.print(DHT.temperature);
lcd.setCursor(9, 1);
lcd.print("C");
delay(2000);
}