#define PHOTORESISTOR 27
#define LED 13
#define GAMMA 0.7
#define RL10 50
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
}
void loop() {
int analogValue = analogRead(PHOTORESISTOR);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("LUX: ");
Serial.println(lux);
if (lux < 10)
digitalWrite(LED, HIGH);
else
digitalWrite(LED, LOW);
delay(1000);
}