const float GAMMA = 0.7;
const float RL10 = 33;
void setup()
{
Serial.begin(9600);
}
void loop()
{
ldr();
delay(500);
}
void ldr(){
int analogValue = analogRead(26);
float voltage = analogValue / 4096. * 3.3;
float resistance = 2000 * voltage / (1 - voltage / 3.3);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print("Room: ");
if (lux > 50) {
Serial.print("Light! ");
} else {
Serial.print("Dark ");
}
Serial.print("Lux: ");
Serial.println(lux);
delay(1000);
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
ldr1:VCC
ldr1:GND
ldr1:DO
ldr1:AO
led1:A
led1:C