#include <LiquidCrystal_I2C.h>
#define LDR_PIN 32
// LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
Serial.begin(115200);
pinMode(LDR_PIN, INPUT);
lcd.init();
lcd.backlight();
}
void loop() {
int analogValue = analogRead(32);
Serial.print("analogValue");
Serial.println(analogValue);
Serial.println(" ");
float voltage = analogValue / 4069. * 3.3;
Serial.print("voltage: ");
Serial.println(voltage);
Serial.println(" ");
float resistance = 3000 * voltage / (1 - voltage / 3.3);
Serial.print("resistance: ");
Serial.println(resistance);
Serial.println(" ");
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(100);
}