import machine
import dht
import time
# Define the pin numbers for DHT22 and potentiometer
dht_pin = machine.Pin(2)
temp_pin = machine.ADC(machine.Pin(34))
# Create DHT22 object
dht22 = dht.DHT22(dht_pin)
while True:
# Read temperature from potentiometer
temp_raw = temp_pin.read()
temp_c = ((temp_raw * 3.3 / 4095) - 0.5) * 100 # Map the analog value to a temperature in degrees Celsius
# Read humidity from DHT22 sensor
dht22.measure()
humidity = dht22.humidity()
# Check if reading humidity was successful
if isinstance(humidity, float):
# Print temperature and humidity to serial monitor
print("Temperature: {:.1f}°C, Humidity: {:.1f}%".format(temp_c, humidity))
else:
print("Failed to read humidity from DHT sensor!")
time.sleep(2)