//
// FILE: dht22_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.03
// PURPOSE: DHT library test sketch for DHT22 && Arduino
#include <dht.h> //เรียกไรบารีของ DHT22
#include <LiquidCrystal_I2C.h> //เรียกใช้งานไรบารี่
LiquidCrystal_I2C lcd(0x27,20,4);
dht DHT;
#define DHT22_PIN 5 //กำหนดขาเชื่อมต่อ (Digital pin 5)
void setup()
{
Serial.begin(115200);//กำหนดความเร็วในการสื่อสาร
Serial.println("dht22_test.ino");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tHumidity (%),\tTemperature (C)");
lcd.init();
lcd.backlight();
lcd.setCursor(6,0);//คอลั่มที่ 4 (คอลั่มแรก = 0) ,แถวแรก (แถวที่ 0)
lcd.print("Hello !!!");
lcd.setCursor(4,2);//คอลั่มที่ 4 (คอลั่มแรก = 0) ,แถวแรก (แถวที่ 0)
lcd.print("How are U today");
}
void loop()
{
// READ DATA
Serial.print("DHT22, \t");
int chk = DHT.read22(DHT22_PIN);//อ่านค่าจาก Sensor DHT22
// DISPLAY DATA
Serial.print(DHT.humidity, 1); //แสดงค่าความชื้นที่อ่านได้ ทศนิยม 1 จุด
Serial.print(",\t\t");
Serial.print(DHT.temperature, 1); //แสดงค่าความอุณหภูมิที่อ่านได้ทศนิยม 1 จุด
Serial.println();
delay(2000); //หน่วงเวลา 2000 ไมโครวินาที หรือ 2 วินาที
lcd.setCursor(3,0);
lcd.print("Humidity ="); //
lcd.print(DHT.humidity, 1);//แสดงค่าความชื้นที่อ่านได้ ทางจอ LCD
lcd.setCursor(3,2);
lcd.print("Temperature ="); //แสดงค่าอุณหภูมิที่อ่านได้ ทางจอ LCD
lcd.print(DHT.temperature, 1);
}