#include "DHTesp.h"
#define pinRelay 26,23,2;
#include <LiquidCrystal_I2C.h>
#include <ESP32Servo.h>
const float GAMMA = 0.7;
const float RL10 = 50;
int DHT_PIN = 15;
DHTesp dhtSensor;
Servo myservo;
LiquidCrystal_I2C lcd(0x27,20,4);
void setup(){
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,2);
lcd.print("Selamat Datang!");
delay(3000);
lcd.clear();
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(19, OUTPUT);
pinMode(18, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(13, OUTPUT);
}
int LED_P = 19;
int LED_G = 18;
int LED_M = 5;
int LED_O = 4;
int LED_B = 13;
void loop(){
TempAndHumidity data = dhtSensor.getTempAndHumidity();
int analogValue=analogRead(35) ;
float voltage=analogValue*5/4095.0;
float resistance=2000*voltage/(1-voltage/5) ;
float lux=pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA)) ;
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
// Serial.print("temperature: ");
// Serial.println(data.temperature);
// Serial.print("humidity: ");
// Serial.println(data.humidity);
Serial.print("lux: ");
Serial.println(lux);
// delay(1000);
if (data.humidity < 75){
digitalWrite(LED_B, LOW);
digitalWrite (LED_P, HIGH) ;
digitalWrite (LED_G, LOW);
digitalWrite (LED_M, LOW);
digitalWrite (LED_O, LOW);
}
}