#define ldrPin 2
#define ntcPin 4
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 voltage = analogValue / 4096. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Kecerahan = ");
Serial.println(lux);
delay(100);
int analogTempValue = analogRead(ntcPin);
float celsius = 1 / (log(1 / (4095. / analogTempValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
}