const int LDR_PIN = 34; // Pin ADC LDR pada ESP32 DevKitC
const float R1 = 10000.0; // Nilai resistor 10kΩ
const float VCC = 3.3; // Tegangan VCC ESP32 DevKitC
const float CALIBRATION_FACTOR = 2.5;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int adcValue = analogRead(LDR_PIN);
float voltage = (adcValue / 4095.0) * VCC; // Konversi ADC ke tegangan
float resistance = R1 * (VCC / voltage - 1.0); // Hitung resistansi LDR
float lux = 10000.0 / (resistance * CALIBRATION_FACTOR); // Hitung nilai Lux
Serial.print("Nilai ADC: ");
Serial.print(adcValue);
Serial.print(" | Tegangan: ");
Serial.print(voltage);
Serial.print("V | Resistansi: ");
Serial.print(resistance);
Serial.print("Ω | Lux: ");
Serial.println(lux);
delay(1000);
}