#include "DHTesp.h"

const int photoresistorPin = 34; // Pin for the photoresistor
const int DHT_PIN = 21; // Pin for the DHT22 sensor

//// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;

DHTesp dhtSensor;

float calculateLux(int sensorValue) {
  float voltage = sensorValue / 4095.0 * 5.0; //esp32
  float resistance = 2000.0 * voltage / (1.0 - voltage / 5.0);
  float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1.0 / GAMMA));
  return lux;
}

void setup() {
  Serial.begin(115200);

  // Setup for DHT22 sensor
  dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}

void loop() {
  // Read the analog value from the photoresistor
  int sensorValue = analogRead(photoresistorPin);
  float luxValue = calculateLux(sensorValue);

  // Print the sensor values to the Serial Monitor
  Serial.print("Photoresistor Sensor Value: ");
  Serial.println(sensorValue);
  Serial.print("Estimated Lux: ");
  Serial.println(luxValue);
  
  TempAndHumidity data = dhtSensor.getTempAndHumidity();
  Serial.print("Temperature: ");
  Serial.print(data.temperature);
  Serial.println(" °C");
  Serial.print("Humidity: ");
  Serial.print(data.humidity);
  Serial.println(" %");
  Serial.println("---");

  delay(2000); // Delay for stability and control of readings
}
$abcdeabcde151015202530fghijfghij