from machine import Pin, UART, ADC
import dht, time
# DHT22 on GPIO14
dht_sensor = dht.DHT22(Pin(14))
# LDR on GPIO34
ldr = ADC(Pin(34))
ldr.atten(ADC.ATTN_11DB) # 0 - 3.3V range
# UART
uart = UART(1, baudrate=9600, tx=Pin(17), rx=Pin(16))
while True:
try:
dht_sensor.measure ()
t=dht_sensor.temperatue()
h=dht_sensor,humidity()
ldr_value=ldr.read()
msg="{:.1f},{:.1f},{}/n".format(t,h,ldr_value)
uart.write(msg)
print("sent",msg.script())
except Exception as e:
print("Error",e)
time.sleep(2)