const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
Serial.begin(115200);
pinMode(12, OUTPUT);
}
void loop() {
int analogValue = analogRead(25);
float voltage = analogValue * 5/4095.0;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Lux: ");
Serial.println(lux);
if (lux >= 50){
Serial.print("Status: ");
Serial.println("Terang");
digitalWrite(12, LOW);
} else {
Serial.print("Status: ");
Serial.println("Gelap");
digitalWrite(12, HIGH);
}
delay(100);
}