// Program Using DHT 11 and DHT 22
#include <LiquidCrystal_I2C.h>
#include <dht.h>
#define outPin 3 // Defines pin number to which the sensor is connected
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
dht DHT; // Creates a DHT object
void setup() {
Serial.begin(9600);
lcd.init(); // initialize the lcd
lcd.backlight();
}
void loop() {
// Nota: Tukar kepada DHT.read11(outPin) jika anda menggunakan sensor DHT11
int readData = DHT.read22(outPin);
float t = DHT.temperature; // Read temperature
float h = DHT.humidity; // Read humidity
//lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0,0)
lcd.print("Temp.: ");
lcd.print(t);
lcd.print((char)223); // shows degrees character
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humi.: ");
lcd.print(h);
lcd.print("%");
delay(1000); // display the above for one second
Serial.print("Temperature = ");
Serial.print(t);
Serial.print("°C | ");
Serial.print((t * 9.0) / 5.0 + 32.0); // Convert celsius to fahrenheit
Serial.println("°F ");
Serial.print("Humidity = ");
Serial.print(h);
Serial.println("%");
Serial.println("");
delay(1000); // wait two seconds
}