from machine import Pin, UART, ADC
import dht, time
dht_sensor = dht.DHT22(Pin(14))
ldr = ADC (Pin(34))
ldr.atten(ADC.ATTN_11DB)
uart = UART(1, baudrate = 9600, tx = Pin(17), rx = Pin(16))
while True:
try:
dht_sensor.measure()
temp = dht_sensor.temperature()
hum = dht_sensor.humidity()
ldr_value = ldr.read()
msg = "{:.1f},{:.1f},{}\n".format(temp, hum, ldr_value)
uart.write(msg)
print("Sent!", msg.script())
except Exception as e:
print("DHT22 ERROR!", e)
time.sleep(2)