--Updated from DHT11 to DHT22
After replacing it, I couldn't use it as it was, so I will explain it.
For those who haven't seen the previous article ➡︎ URL
Reference material Make a LINEbot that notifies the temperature with Raspberry Pi 3 + DHT22 ②
The source code is on GitHub, so I will quote it.
--First, RPi.GPIO installs a module that can control GPIO pins of Raspberry Pi.
$ sudo apt-get install python-rpi.gpio
--Install the package for the sake of your needs.
$ sudo apt-get install build-essential python-dev
--Install the DHT22 library
$ sudo git clone https://github.com/adafruit/Adafruit_Python_DHT.git
$ cd Adafruit_Python_DHT
$ sudo python setup.py install
――Same as last time. I'm sorry to quote that.
*** There is one caveat. </ font> ***
--It does not start well when 5V is given. (I don't know why)
So, please change to *** 3.3V *** voltage.
python
# coding: utf-8
import RPi.GPIO as GPIO
import time
import datetime
import MyPyDHT
#Declared to specify by GBCM number
GPIO.setmode(GPIO.BCM)
#Set pin 17 of BCM to output
DHT_PIN = 14
GPIO.setup(DHT_PIN,GPIO.OUT)
HEATER_PIN = 17
GPIO.setup(HEATER_PIN,GPIO.OUT)
HotTemp = 10
ColdTemp = -1
sleepSecond = 0
try:
while True:
humidity, temperature = MyPyDHT.sensor_read(MyPyDHT.Sensor.DHT22, DHT_PIN)
if humidity is not None and temperature is not None:
tmp = temperature
print(tmp)
if tmp <= ColdTemp:
# Heater running
GPIO.output(HEATER_PIN,1)
print("Heater ON")
sleepSecond = 10
elif tmp >= HotTemp:
# Heater stop
GPIO.output(HEATER_PIN,0)
print("Heater OFF")
sleepSecond = 10
else :
time.sleep(sleepSecond)
time.sleep(5)
except KeyboardInterrupt:
GPIO.cleanup()
*** It's a little different from before. Because it's only a little ***
Are you using *** 5V ***? Try replacing it with *** 3.3V ***!