from machine import Pin
from utime import sleep
import dht
led = Pin(23,Pin.OUT)
sensor = dht.DHT22(Pin(27))
while True:
try:
sleep(2)
sensor.measure()
temp = sensor.temperature()
if temp > 25.0:
led.value(1)
else:
led.value(0)
hum = sensor.humidity()
temp_f = temp * (9/5) + 32.0
print("Temprature: %3.1f C" %temp)
print("Temprature: %3.1f F" %temp_f)
print("Humidity: %3.1f" %hum)
except OSError as e:
print("Failed to read sensor")
print("Hello, ESP32!")