#define relay 2
#define ldr A0
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
pinMode(relay, OUTPUT);
}
void loop() {
int analogValue = analogRead(ldr);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
if (lux > 50) {
digitalWrite(relay,LOW);
} else {
digitalWrite(relay,HIGH);
}
delay(100);
}