#define ldrPin 33
#define ntcPin 21
const float GAMMA = 0.7;
const float RL10 = 50;
const float BETA = 3950;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
analogReadResolution(12);
}
void loop() {
// put your main code here, to run repeatedly:
delay(100); // this speeds up the simulation
// Convert the analog value into lux value:
int analogValue = analogRead(ldrPin);
float voltagelux = analogValue / 4096. * 5;
float resistancelux = 2000 * voltagelux / (1 - voltagelux / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistancelux, (1 / GAMMA));
Serial.print("Kecerahan = ");
Serial.println(lux);
delay(100);
int analogTempValue = analogRead(ntcPin);
float voltageTemp = analogTempValue * (3.3 / 4095); // Convert ADC value to voltage (assuming 12-bit ADC)
float resistanceTemp = (3.3 * 10000) / voltageTemp - 10000; // Calculate resistance using voltage divider formula
float temperatureTemp = 1 / (log(resistanceTemp / 10000) / 3977 + 1 / 298.15) - 273.15; // Steinhart-Hart equation
Serial.print("Suhu: ");
Serial.println(temperatureTemp);
delay(100);
}