#include <LiquidCrystal_I2C.h>
#define LDR_PIN A0
const float GAMMA = 0.7;
const float RL10 = 50;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
pinMode(LDR_PIN, INPUT);
lcd.init();
lcd.backlight();
}
void loop()
{
int val = analogRead(LDR_PIN);
float v = val / 1024. * 5;
float r = 2000 * v / (1 - v / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / r, (1 / GAMMA));
lcd.setCursor(0, 0);
lcd.print("Room: ");
if (lux > 50)
{
lcd.print("Light!");
}
else
{
lcd.print("Dark ");
}
lcd.setCursor(0, 1);
lcd.print("Lux : ");
lcd.print(lux);
delay(100);
}