#define LDR_PIN 2
#define LED_PIN 12
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(LDR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// These constants should match the photoresistor's "gamma" and "rl10" attributes
// 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<150){
digitalWrite(LED_PIN,HIGH);
}else{
digitalWrite(LED_PIN,LOW);
}
// if(digitalRead(LDR_PIN) == LOW){
// digitalWrite(LED_PIN,LOW);
// Serial.println("LED is off");
// }else {
// digitalWrite(LED_PIN, HIGH);
// Serial.println("LED is glowing");
// }
delay(100); // this speeds up the simulation
}