from machine import Pin
from time import sleep
import dht
import machine
import time
sensor=dht.DHT22(Pin(4))
p23=machine.Pin(23,machine.Pin.OUT)
buzzer=machine.PWM(p23)
buzzer.freq(1024)
buzzer.duty(50)
time.sleep(1)
buzzer.duty(0)
buzzer.deinit()
while True:
try:
sleep
sensor.measure()
temp=sensor.temperature()
hum=sensor.humidity()
temp_f=temp*(9/5)+32.0
print('Temperature:%3.1f C'%temp)
print('Temperature:%3.1f F'%temp_f)
print('Humidity:%3.1f %%'%hum)
except OSError as e:
print('Failed to read sensor')