#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#define DHTPIN 8 // what digital pin the DHT22 is conected to
#define DHTTYPE DHT22 // there are multiple kinds of DHT sensors
LiquidCrystal_I2C lcd (0x27, 20,4);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.setTimeout(2000);
lcd.init();
lcd.backlight();
// Wait for serial to initialize.
while(!Serial) { }
dht.begin();
lcd.setCursor(2,0);
lcd.print("INDAH RAMADANI");
delay(150);
}
int timeSinceLastRead = 0;
void loop() {
// Report every 2 seconds.
if(timeSinceLastRead > 1000) {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
timeSinceLastRead = 0;
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print("°C ");
Serial.print("Fahrenheit: ");
Serial.print(hif);
Serial.println("°F ");
lcd.setCursor(0,1);
lcd.print("HUM : ");
lcd.setCursor(6,1);
lcd.print(h);
lcd.print("%");
lcd.setCursor(0,2);
lcd.print("Temp :");
lcd.setCursor(6,2);
lcd.print(t);
lcd.print("C");
lcd.setCursor(0,3);
lcd.print("Fahr :");
lcd.setCursor(6,3);
lcd.print(hif);
lcd.print("F");
timeSinceLastRead = 0;
}
delay(150);
timeSinceLastRead += 100;
}