This application measures temperature and humidity with a DHT22/AM2302 sensor connected to the Raspberry Pi.
The sensor is read out with a Python script and the library Adafruit_CircuitPython_DHT. The measurement data is displayed in the console and can optionally be save to a database (MariaDB) and displayed on a web server.
- Raspberry Pi
- Raspberry Pi OS (previously called Raspbian)
- Sensor: DHT22 (AM2302) (Buy: int./de)
- optional: Docker & docker-compose
It use physical PIN7 = GPIO4 (D4) by default. You can now* change the GPIO Pin over a env-Variable (see below).
The other two cable of AM2302 are connect to 3V (or 5V) and Ground.
# Clone Project
git clone https://github.com/Tob1as/rpi-sensors.git
# change in folder
cd rpi-sensors/Use Docker (recommended) or manual installation.
Requirements:
- installed Docker & Docker-Compose
- Note: On Raspbian/Debian > 11 it run only when you set
PRIVILEGED_MODE_ENABLE=truein.env-File (see below).
Steps:
- copy env-File:
cp example.env .env
- change settings in
.env-File, example Database Password or GPIO Pin. Then optional check config:docker compose config
- Run:
or:
docker compose up -d
docker compose up -d mariadb dht22 web
- [optional] Logs:
docker compose logs -f
- [optional] Stop:
docker compose down -v
- Install requirements:
sudo apt-get update sudo apt-get install -y build-essential python3-dev libgpiod2 libgpiod3 libmariadb-dev #sudo pip3 install rpi.gpio==0.7.1 sudo pip3 install adafruit-blinka==8.68.1 sudo pip3 install adafruit-circuitpython-dht==4.0.10 sudo pip3 install mariadb==1.1.14 sudo pip3 install paho-mqtt==2.1.0 - Setup local or external MariaDB/MySQL.
- Export Variable in
example.env-File or change default value indht_sensor.py. - Run:
python3 ./dht_sensor.py
- Optional: Copy html-Folder into Webserver with installed PHP-Modul and change database settings in php file.