import Adafruit_DHT
# Set the type of sensor
DHT_SENSOR = Adafruit_DHT.DHT22
# Set the GPIO pin where the sensor is connected
GPIO_PIN = 4 # Change this to the GPIO pin you're using
def main():
# Read the sensor data
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, GPIO_PIN)
if humidity is not None and temperature is not None:
print(f'Temperature: {temperature:.1f} C Humidity: {humidity:.1f} %')
else:
print('Failed to retrieve data from the sensor')
if __name__ == "__main__":
main()