22 lines
No EOL
485 B
Python
22 lines
No EOL
485 B
Python
import machine
|
|
import utime
|
|
import dht
|
|
|
|
# Set up the DHT11 sensor on GPIO 14
|
|
sensor = dht.DHT11(machine.Pin(14))
|
|
|
|
while True:
|
|
try:
|
|
sensor.measure()
|
|
temp = sensor.temperature()
|
|
hum = sensor.humidity()
|
|
|
|
print("Temperature: {}°C".format(temp))
|
|
print("Humidity: {}%".format(hum))
|
|
print("------------------------")
|
|
|
|
except OSError as e:
|
|
print("Sensor error:", e)
|
|
|
|
# Wait 60 seconds
|
|
utime.sleep(60) |