const int pinSensor = A0;
int adcValue = 0;
double volt = 0;
const float RL10 = 50;
const float GAMMA = 0.7;
void setup()
{
// inisiasi Serial comm dengan baud rate 115200
Serial.begin(115200);
pinMode(pinSensor, INPUT);
}
void loop()
{
// akuisisi nilai ADC sensor LDR
adcValue = analogRead(pinSensor);
float voltage = adcValue / 4095. * 5; //4095 = max ADC esp32
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1000 * pow (10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("nilai adc:");
Serial.print(adcValue);
Serial.print(" Lux:");
Serial.println(lux);
// jeda akuisisi data
delay(1000);
}