void setup() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
pinMode(A0, INPUT);
}
void loop() {
// These constants should match the photoresistor's "gamma" and "rl10" attributes
const float GAMMA = 0.7;
const float RL10 = 50;
// Convert the analog value into lux value:
int analogValue = analogRead(A0);
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<=215){
digitalWrite(2, LOW);
}else{
digitalWrite(2, HIGH);
}
}