from machine import ADC, Pin
import math
import time
import dht
led = Pin(4, Pin.OUT)
led2 = Pin(21, Pin.OUT)
sensor = dht.DHT22(Pin(25))
GAMMA = 0.7;
RL10 = 85;
adc = ADC(Pin(15))
while(True):
#Convert the analog value into lux value:
analogValue = adc.read()
voltage = analogValue / 1024. * 3.3
resistance = 5000 * voltage / (1 - voltage / 3.3)
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA))
sensor.measure() # read the parameters from the sensor
t = sensor.temperature()
if t > 40:
led.on()
else:
led.off()
time.sleep(1)