//Nilai Konstanta diambil dari data Wokwi
//https://docs.wokwi.com/parts/wokwi-photoresistor-sensor
const float GAMMA = 0.7;
const float RL10 = 50;
int LDR = 13;
void setup() {
Serial.begin(115200);
}
void loop() {
int analogValue = analogRead(LDR);
//menghitung nilai tegangan yang ada pada LDR
float voltage = analogValue * 5/4095.0; //ESP rangenya 4095 & Arduino 1023
//menghitung nilai resistensi pda DLR
float resistance = 2000 * voltage / (1 - voltage / 5);
//Konversi ADC to LUX
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA)); //Ketetapan dari LDR (Datasheet) konversi resistance ke LUX
Serial.print("Volt : ");
Serial.print(voltage);
Serial.print(" || ");
Serial.print("Resistansi : ");
Serial.print(resistance);
Serial.print(" || ");
Serial.print("Lux: ");
Serial.print(lux);
Serial.println();
delay(100);
}