/**************************************
* Monitoring Suhu Kelembaban DHT22
* Input : DHT22 (pin 8)
* Out : LCD 16x2
* koneksi DHT22 -- Arduino UNO
* Vcc -- 5V
* Gnd -- GND
* Data -- pin 8
* koneksi LCD -- Arduino UNO
* RS -- 2
* E -- 3
* D4 -- 4
* D5 -- 5
* D6 -- 6
* D7 -- 7
* www.ardutech.com
**************************************/
#include <LiquidCrystal_I2C.h> //library LCD
//koneksi LCD, lihat rangkaian
//LiquidCrystal lcd(2,3,4,5,6,7);
LiquidCrystal_I2C lcd(0x27,16,2);
#include <DHT.h> //library DHT22
#define DHTPIN 2 //pin data DHT22 konek ke pin 8 Arduino
#define DHTTYPE DHT22 //jenis sensor DHT22
DHT dht(DHTPIN, DHTTYPE); //setup pin dan jenis DHTT ke library
//deklarasi variabel untuk menampung pembacaan suhu & kelembaban
float humi, temp;
void setup()
{
lcd.begin(16, 2); //type LCD 16x2
lcd.backlight();
lcd.setBacklight(HIGH);
lcd.print("Monitoring DHT22"); //tampilan pertama
delay(2000); //tunda 2 detik
lcd.clear(); //hapus tampilan
lcd.print("Temp=");//tampilkan di baris 1
lcd.setCursor(0,1);//pindah ke baris 2
lcd.print("Humi=");//tampilkan di baris 2
dht.begin();
}
//============================
void loop()
{
humi = dht.readHumidity(); //baca kelembaban
temp = dht.readTemperature();//baca suhu
if (isnan(humi) || isnan(temp)) { //jika tidak berhasil
//Serial.println(F("Failed to read from DHT sensor!"));
return;
}
else{ //jika berhasil membaca sensor
lcd.setCursor(6,0); //set kursor di baris 1, kolom 6
lcd.print(temp);//tampilkan nilai suhu
lcd.print(" C ");//Celcius
lcd.setCursor(6,1);//set kursor di baris 2, kolom 6
lcd.print(humi);//tampilkan nilai kelembaban
lcd.print(" % "); //% RH
}
delay(1000); //tunda 1 detik
}