#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define LDR_PIN 3
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
lcd.begin(16,2);
dht.begin();
lcd.backlight();
pinMode(LDR_PIN, INPUT);
}
void loop() {
int h = dht.readHumidity();
int t= dht.readTemperature();
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
///////////////////////////////////////////////////
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Kelembapan");
lcd.setCursor(6,1);
lcd.print(h);
lcd.print(" %");
delay (2500);
///////////////////////////////////////////////////
lcd.clear();
lcd.setCursor(3,0);
lcd.print("Suhu ");
lcd.setCursor(6,1);
lcd.print(t);
lcd.print(" C'");
delay (2500);
///////////////////////////////////////////////////
lcd.setCursor(2, 0);
lcd.print("Clima: ");
if (lux > 10000) {
lcd.print("Soleado!");
} else {
lcd.print("Nublado ");
}
lcd.setCursor(0, 1);
lcd.print("Lux: ");
lcd.print(lux);
lcd.print(" ");
delay(2500);
}