import time
from machine import Pin
import dht
import math
DHT_PIN = 13 # Replace with the GPIO pin number to which your DHT sensor is connected
DHT_TYPE = dht.DHT22
dht_sensor = dht.DHT22(Pin(DHT_PIN))
while True:
dht_sensor.measure()
temperature = dht_sensor.temperature()
if not math.isnan(temperature):
temperature *= 1.0878
print("Temperature: " + str(temperature) + " degrees Celsius recorded")
else:
print("Error in reading temperature data from DHT sensor")
time.sleep(3)
#incase of OSError -202
'''while True:
try:
dht_sensor.measure()
temperature = dht_sensor.temperature() * 1.0878
print("Temperature: " + str(round(temperature, 2)) + " degrees Celsius recorded")
except OSError as e:
print("Error: " + str(e))
time.sleep(3) # Delay for 3 seconds before the next reading'''