#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include<ESP32Servo.h>
const int ldrPin =36;
const int relayPin =26;
const int ledPin = 25;
const int buzzerPin =27;
const int servoPin = 23;
const float GAMMA = 0.7;
const float RL10 = 50;
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myServo;
//int ldrThreshold = 500;
void setup() {
//lcd.begin(115200);
lcd.init();
lcd.backlight();
myServo.attach(servoPin);
myServo.write(0);
pinMode(ldrPin, INPUT);
pinMode(relayPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
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.setCursor(2, 0);
lcd.print("Room: ");
if (lux > 50) {
lcd.print("Light!");
} else {
lcd.print("Dark ");
}
lcd.setCursor(0, 1);
lcd.print("Lux: ");
lcd.print(lux);
lcd.print(" ");
delay(1000);
}