This repository contains a Python script that reads data from a DHT22 sensor connected to a Raspberry Pi, stores the data in a MariaDB database, sends the information to an OPC UA server, and finally displays the values on an LCD screen.
Connects to an OPC UA server to update temperature and humidity values.
Connects to a pre-created database to store the readings.
Saves readings in a table with the following fields:
id(auto-increment)temperaturehumidityreading_timestamp(timestamp)
Shows temperature and humidity on an LCD connected to the Raspberry Pi.
- Raspberry Pi with internet connectivity
- DHT22 sensor
- LCD display with I2C interface
- Python 3
opcuafor OPC UA communicationmariadbfor database connectivityAdafruit_DHTfor reading the DHT22 sensorCompatibility issues may occur; the recommended approach is to download from the official repository: https://github.com/adafruit/DHT-sensor-library.git
RPLCDfor the LCD screen
Before running the script, ensure you have a MariaDB database with the following structure:
CREATE DATABASE sensores;
USE sensores;
CREATE TABLE lecturas (
id INT AUTO_INCREMENT PRIMARY KEY,
temperatura FLOAT,
humedad FLOAT,
fecha_lectura TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);To connect successfully, update the database credentials inside the script with your user and password.
Clone the repository and run the script on your Raspberry Pi:
git clone https://github.com/L1LBRO/Sensor_DHT22.git
cd Sensor_DHT22
python3 SensorReading_ScreenSending.pyOnce running, the script reads temperature and humidity every 5 seconds. Data is sent to the OPC UA server and stored in MariaDB. Values are displayed on the LCD screen.
If you want to improve this project, feel free to fork the repository and submit a pull request with your enhancements.
This project is licensed under the MIT License.