int photoresistor = A2, light = A0, inp = 0;
void setup() {
// put your setup code here, to run once:
pinMode(photoresistor, INPUT);
pinMode(light, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
inp = analogRead(photoresistor);
float voltage = inp / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(50 * 1e3 * pow(10, 0.7) / resistance, (1 / 0.7));
Serial.println(inp);
if(lux < 500)
digitalWrite(light, HIGH);
else
digitalWrite(light, LOW);
delay(1000); // this speeds up the simulation
}