#define LDR_PIN1 25
#define LDR_PIN2 26
const float GAMMA = 0.7;
const float RL10 = 50;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(LDR_PIN1, INPUT);
pinMode(LDR_PIN2, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int analogValue1 = analogRead(LDR_PIN1);
float voltage1 = analogValue1 / 1024. * 5;
float resistance1 = 2000 * voltage1 / (1 - voltage1 / 5);
float lux1 = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance1, (1 / GAMMA));
Serial.println(lux1);
if (lux1 < 50) {
Serial.println(" LED 1 ON!");
} else {
Serial.println("LED 1 OFF!");
}
Serial.println(" ");
int analogValue2 = analogRead(LDR_PIN2);
float voltage2 = analogValue2 / 1024. * 5;
float resistance2 = 2000 * voltage2 / (1 - voltage2 / 5);
float lux2 = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance2, (1 / GAMMA));
Serial.println(lux2);
if (lux2 < 50) {
Serial.println(" LED 2 ON!");
} else {
Serial.println("LED 2 OFF!");
}
delay(100);
delay(10); // this speeds up the simulation
}
// 0000000000000000000000000000000000000000000000000000000000000)