import machine
import time
import dht
# Define the DHT22 sensor, LED, and Buzzer pins
dht22 = dht.DHT22(machine.Pin(15))
led = machine.Pin(16, machine.Pin.OUT)
buzzer = machine.Pin(17, machine.Pin.OUT)
# Set temperature and humidity thresholds
TEMP_THRESHOLD = 30 # degrees Celsius
HUM_THRESHOLD = 70 # percentage
while True:
# Read temperature and humidity from DHT22
dht22.measure()
temp = dht22.temperature()
hum = dht22.humidity()
print(f"Temperature: {temp}°C, Humidity: {hum}%")
# Check if the temperature or humidity exceeds the threshold
if temp > TEMP_THRESHOLD or hum > HUM_THRESHOLD:
print("Threshold exceeded!")
led.on()
buzzer.on()
else:
led.off()
buzzer.off()
time.sleep(2)