import machine
import dht
import time
# Define the GPIO pin where DHT22 is connected
DHT_PIN = 18 # Changed to GPIO 18
# Initialize the DHT22 sensor
sensor = dht.DHT22(machine.Pin(DHT_PIN))
print("Starting DHT22 Sensor on GPIO 18...")
while True:
try:
sensor.measure()
temp = sensor.temperature()
humidity = sensor.humidity()
print(f"Temperature: {temp:.1f}°C, Humidity: {humidity:.1f}%")
except Exception as e:
print("Error reading DHT22:", e)
time.sleep(2)