import dht
from machine import Pin
import time
# Initialize the sensor
dht_sensor = dht.DHT22(Pin(15)) # GPIO 15 connected to DHT22 data pin
while True:
try:
dht_sensor.measure()
temp = dht_sensor.temperature()
hum = dht_sensor.humidity()
print('Temperature: %3.1f C' % temp)
print('Humidity: %3.1f %%' % hum)
# Add fire detection logic based on temperature thresholds
if temp > 50: # Fire detection threshold
print("Fire detected due to high temperature!")
time.sleep(2)
except OSError as e:
print('Failed to read sensor.')