// Do Trong Khang - 20ES
#include "DHTesp.h"
const int DHT_PIN = 16;
const int LDR_PIN = 36;
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
DHTesp dhtSensor;
void setup() {
Serial.begin(115200);
pinMode(LDR_PIN, INPUT);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
int LDRanalogValue = analogRead(A0);
float voltage = LDRanalogValue / 4095. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("-----");
Serial.println("Luminux: ");
Serial.print(lux);
Serial.println("\n-----");
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}