from machine import Pin, ADC
from utime import sleep
LDR_Pin = ADC(Pin(12, Pin.IN))
LED_Pin = Pin(4, Pin.OUT)
GAMMA = 0.7
RL10 = 50;
while True:
analogValue = LDR_Pin.read()
#Convert the analog value into lux value:
voltage = analogValue / 4095. * 5;
print(voltage)
resistance = 2000 * voltage / (1 - voltage / 5);
print(resistance)
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
print('lux:',lux)
if lux < 1500:
LED_Pin.on()
else:
LED_Pin.off()
sleep(0.5)