#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
//These constants should match the photoresistor's "gamma" and "rl10"attributes
const float GAMMA = 0.7;
const float RL10 = 15;
int analogValue;
float voltage,resistance,lux;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("luminance");
}
void loop() {
// Convert the analog value into lux value:
analogValue = analogRead(A0);
voltage = analogValue / 1024. * 5;
resistance = 2000 * voltage / (1 - voltage / 5);
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 /GAMMA));
lcd.setCursor(3,1);
lcd.print(lux);
lcd.print(" lux ");
delay(500);
}