void setup() {
pinMode(32, INPUT);
Serial.begin(115200);
}
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(32);
float voltage = analogValue / 4096. * 5;
float resistance = 2000 * voltage / (1 - voltage/ 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Nilai ADC =");
Serial.println(analogValue);
delay(500);
Serial.print("Nilai Lux =");
Serial.println(lux);
}