#Project Objectives
#Read temperature and humidity values from the DHT22 sensor
#Display the sensor readings in the console
#
#Hardware connections used:
#DHT22 Vcc Pin to 3.3V
#1k ohm pull-up resistor
#DHT22 GND Pin to GND
#modules
from machine import Pin
from time import sleep
from dht import DHT22
#creating a DHT object
dht=DHT22(Pin(14))
blue=Pin(0, Pin.OUT)
red=Pin(1, Pin.OUT)
green=Pin(2, Pin.OUT)
#continuously get the sensor data
while True:
#getting sensor readings
dht.measure()
temp = dht.temperature()
hum = dht.humidity()
#display the values of T and H to the console
print(f"Temperature: {temp} C Humidity: {hum}%")
#read the values from sensor every 2 secs
sleep(2)
if temp<15:
blue.on()
red.off()
green.off()
elif 15<=temp<=30:
blue.off()
green.on()
red.off()
elif temp>30:
blue.off()
green.off()
red.on()