const float GAMMA = 0.7;
const float RL10 = 33;
void setup()
{
Serial.begin(9600);
}
void loop()
{
ldr();
delay(500);
}
void ldr(){
int analogValue = analogRead(26);
float voltage = analogValue / 4096. * 3.3;
float resistance = 2000 * voltage / (1 - voltage / 3.3);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Room: ");
if (lux > 50) {
Serial.print("Light! ");
} else {
Serial.print("Dark ");
}
Serial.print("Lux: ");
Serial.println(lux);
delay(1000);
}