const float GAMMA = 0.7;
const float RL10=50;
void setup() {
// put your setup code here, to run once:
pinMode(4, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int sensorValue=analogRead(A1);//read the sensor value
//convert sensor reading in to lux
float voltage = sensorValue/ 1024.0 * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
//decision making
if(lux>800){
digitalWrite(4, HIGH);
delay(500);
}
else{
digitalWrite(4, LOW);
delay(500);
}
}