from machine import Pin
from time import sleep
from dht import DHT22
sensor = DHT22(Pin(15))
def celsius_to_kelvin(c):
return c + 273.15
def celsius_to_fahrenheit(c):
return (c * 9/5) + 32
while True:
sensor.measure()
temp_c = sensor.temperature()
humidity = sensor.humidity()
temp_k = celsius_to_kelvin(temp_c)
temp_f = celsius_to_fahrenheit(temp_c)
print('Temperature:')
print(' Celsius : %.2f °C' % temp_c)
print(' Kelvin : %.2f K' % temp_k)
print(' Fahrenheit: %.2f °F' % temp_f)
print('Humidity : %.2f %%' % humidity)
sleep(1)