void setup() {
Serial.begin(115200);
// Set resolusi ADC menjadi 12 bit (0-4096)
analogReadResolution(12);
pinMode(15, OUTPUT);
}
void loop() {
const float GAMMA = 0.7;
const float RL10 = 50;
const float Vcc = 3.3;
const float Rfixed = 2000; // Resistansi tetap (ohm)
int analogValue = analogRead(2);
float voltage = (analogValue * Vcc) / 4096.0;
float resistance = Rfixed * (Vcc / voltage - 1);
float lux = pow((RL10 * 1e3 * pow(10, GAMMA)) / resistance, (1 / GAMMA));
Serial.printf("Analog value = %d\n", analogValue);
Serial.printf("Voltage value = %.2f V\n", voltage);
Serial.printf("Resistance value = %.2f ohm\n", resistance);
Serial.printf("Lux value = %.2f lx\n", lux-1000);
if(lux>10){
digitalWrite(15, HIGH);
}digitalWrite(15, LOW);
delay(100);
}