Interfacing DHT11 Temperature and Humidity sensor with Raspberry pi pico in Mycropython programming.

 #Connect DHT11 VCC to Raspberry pi pico 3.3v(Phycical Pin 36)

#Connect DHT11 Gnd to Raspberry pipico GND

#Connect DHT11 Data to Raspberry pi pioco Pin# 16(Phycical pin 21)



from machine import Pin

import utime 

from dht import DHT11


dhtPin = Pin(16, Pin.IN , Pin.PULL_DOWN)

led=Pin(14,Pin.OUT)#Over temperature indicator led connected to GPIO-14

buzzer=Pin(15,Pin.OUT)#buzzer connected to Pin#15 of Raspberry pi pico

relay=Pin(13,Pin.OUT)#relay connected to Pin#13 of Raspberry pi pico


while True:#infinite loop to checking the temperature 

    utime.sleep(2)

    dhtSensor = DHT11(dhtPin)

    

    temp_value = dhtSensor.temperature

    

    hum_value = dhtSensor.humidity

    

    print("Temperature : ", temp_value, "Degree Celcius")#display the temperature on shell.

    print("Relative Humidity : ", hum_value, " %", "\n")#display the Humidity on shell.

    if temp_value >=32:#if temperature is Gteater than or equal the set value.

        led.on()#led indicator will turn on

        buzzer.toggle()#buzzer will toggle

        relay.on()#relat will turn on

    else:#if tempetatute is not greater than set value.

        relay.off()#relay will stay at off position

        led.off()#led indicator  will stay at off position

        buzzer.off()#buzzer will stay silent.

Comments

Popular posts from this blog

4 Stage Timer With DS3231RTC Module.

Interfacing KY038 sound sensor with Raspberry pi Pico

Interfacing MQ2 Gas & Smoke Sensor With Raspberry Pi Pico