Recently, it has become cold and it has become a difficult season for poor circulation. Therefore, I implemented IoT that turns on the heater when it reaches a certain temperature and turns it off when it gets warm to some extent.
-I quoted from GitHub.
sudo apt-get install git
--Sample python program installation
git clone https://github.com/szazo/DHT11_Python.git
――I liken it to someone who has nothing to do with the temperature sensor. sorry. --From the right (*** GND, PIN to read the sensor value, 5V ***) --The Heater is AC, so you can just connect it to the SSR and stab it into the power strip. ―― *** * If you make a mistake in the circuit, the temperature sensor will become extremely hot. Please be careful. *** ***
-I used Python3.
You can just quote dht11_example.py in DHT11_Python.
This time, I made this program.
dht11_example.py
# coding: utf-8
import RPi.GPIO as GPIO
import dht11
import time
import datetime
# initialize GPIO
GPIO.setwarnings(False)
#Declared to specify by GBCM number
GPIO.setmode(GPIO.BCM)
#Set pin 17 of BCM to output
GPIO.setup(17,GPIO.OUT)
# read data using pin 14
instance = dht11.DHT11(pin=14)
HotTemp = 20
ColdTemp = 5
sleepSecond = 0
try:
while True:
result = instance.read()
if result.is_valid():
tmp = result.temperature
print(tmp)
if tmp <= ColdTemp:
# Heater running
GPIO.output(17,1)
print("Heater ON")
sleepSecond = 10
elif tmp >= HotTemp:
# Heater stop
GPIO.output(17,0)
print("Heater OFF")
sleepSecond = 10
else :
time.sleep(sleepSecond)
except KeyboardInterrupt:
GPIO.cleanup()
*** I think it's a very easy-to-understand program. *** ***
Let's implement it for the time being!
sudo python3 dht11_example.py
*** Did it work? *** ***
--Try adding *** as GPIO *** to the first part of dht11.py of DHT11.
dht11.py
import time
#Add as GPIO to import RPi
import RPi as GPIO
class DHT11Result:
'DHT11 sensor result returned by DHT11.read() method'
ERR_NO_ERROR = 0
ERR_MISSING_DATA = 1
ERR_CRC = 2