The weather IoT system that continuously monitors temperature and humidity using a DHT22 sensor transmitting real-time data for easy remote access and monitoring.
Report Bug
·
Request Feature
Table of Contents
This Weather IoT project is designed to monitor and transmit real-time environmental data—specifically temperature and humidity—using an ESP32 or ESP8266 microcontroller with a DHT22 sensor. The system connects to a WiFi network and uses the MQTT protocol to send sensor data to a cloud-based or local MQTT broker, such as HiveMQ’s public broker.
- ESP32 or ESP8266 Microcontroller: The main controller responsible for reading data from the sensor and handling network communication.
- DHT22 Sensor: A digital sensor that measures temperature and humidity, known for its accuracy and ease of use.
- Wiring and Power: The DHT22 sensor connects to one of the GPIO pins on the ESP board, while the board is powered via USB or battery.
- The ESP32/ESP8266 reads temperature and humidity data from the DHT22 sensor at regular intervals (e.g., every 2 seconds).
- Each data point (temperature and humidity) is packaged into a JSON-formatted message, allowing easy parsing and display on various devices or platforms.
- WiFi Connection: The ESP connects to a WiFi network, which provides internet access for transmitting data.
- MQTT Protocol: The project uses the MQTT (Message Queuing Telemetry Transport) protocol, a lightweight messaging protocol commonly used in IoT due to its low bandwidth requirements.
- MQTT Broker: All data is published to an MQTT broker (e.g.,
broker.mqttdashboard.com
), where it can be accessed in real-time by subscribing devices or applications.
- After processing, the ESP publishes the JSON message containing temperature and humidity data to a specified MQTT topic (e.g.,
wokwi-weather
oriot/weather
). - Using an MQTT client (like HiveMQ’s WebSocket client), users can subscribe to the MQTT topic to view real-time data updates in a browser or app. Each time the temperature or humidity changes, a new message is published to the MQTT topic.
- Real-Time Environmental Monitoring: Ideal for tracking temperature and humidity in homes, greenhouses, or storage facilities.
- Remote Weather Stations: The project can serve as a basic weather station that can be monitored remotely, without needing any on-site presence.
- Educational Projects: This setup is also a valuable educational tool, providing hands-on experience with IoT, MQTT, and sensor integration.
To successfully build and run the IoT Weather Monitoring System, you’ll need the following:
Component | Description |
---|---|
ESP32 or ESP8266 | Microcontroller board. Ensure your board is functional and compatible with the Arduino IDE. |
DHT22 Sensor | A DHT22 temperature and humidity sensor for environmental data collection. |
Wiring and Breadboard | Jumper wires and a breadboard for secure connections between the microcontroller and sensor. |
Power Supply | USB cable or battery pack to power the ESP32/ESP8266. |
Testing Platform | If you just want to test, you can go to Wokwi. Additionally, you can view this IoT project in This IoT's Wokwi. |
Diagram | Description |
---|---|
The wiring setup for connecting the DHT22 sensor to the ESP32/ESP8266 microcontroller. Click the image for Demo Test Video. |
Architecture | Description |
---|---|
The overall architecture of the IoT system, showing data flow from the sensor to the MQTT broker. |
Requirement | Description |
---|---|
Arduino IDE | Download and install the Arduino IDE for programming the ESP32 or ESP8266. Ensure the ESP32/ESP8266 board libraries are installed in the Arduino IDE. |
Arduino Libraries | PubSubClient library for MQTT communication. DHT Sensor Library for reading data from the DHT22 sensor. |
WiFi Network | Access to a 2.4GHz WiFi network (compatible with most ESP boards) with SSID and password available. |
- MQTT Broker (e.g., HiveMQ’s public broker or Mosquitto)
- If using the public HiveMQ broker, no additional setup is required.
- Ensure the MQTT broker is reachable from your network and supports the MQTT protocol on port
1883
.
- MQTT Dashboard or Client
- HiveMQ’s WebSocket Client or any other MQTT client for subscribing to the topic and viewing real-time data.
- Cloud Integration (optional)
- If you want to log or analyze data, consider setting up a cloud IoT platform (e.g., AWS IoT or Google Cloud IoT).
Follow these steps to install and set up the IoT Weather Monitoring System:
-
Connect the DHT22 Sensor to the ESP32 or ESP8266:
- Connect the VCC pin of the DHT22 to the 3.3V pin on the ESP board.
- Connect the GND pin of the DHT22 to the GND pin on the ESP board.
- Connect the Data pin of the DHT22 to a digital GPIO pin (e.g., GPIO15) on the ESP board.
-
Power the ESP32/ESP8266 using a USB cable connected to your computer or an external power source.
-
Download and Install the Arduino IDE:
- Download Arduino IDE and install it on your computer.
- Install the ESP32/ESP8266 board libraries via the Arduino Board Manager.
-
Install Required Libraries:
- Open the Arduino IDE and go to Sketch > Include Library > Manage Libraries.
- Search for and install the following libraries:
- PubSubClient (for MQTT communication)
- DHT Sensor Library (for reading data from the DHT22 sensor)
- Open the Code:
- Copy the provided code into a new sketch in the Arduino IDE.
- Update WiFi and MQTT Credentials:
- Replace
SSID
andPASSWORD
in the code with your WiFi network name and password. - Set the
mqtt_server
to"broker.mqttdashboard.com"
(or another MQTT broker if you have one).
- Replace
- Verify and Upload Code:
- Select your ESP32 or ESP8266 board from Tools > Board.
- Choose the correct Port from Tools > Port.
- Click on Verify to check for any errors, and then Upload the code to the board.
- Verify Connection:
- Open the Serial Monitor in the Arduino IDE to confirm that the ESP has successfully connected to WiFi and the MQTT broker.
- You should see periodic messages indicating the current temperature and humidity readings being published to the MQTT topic.
- Monitor Data with MQTT Client:
- Open an MQTT client, like the HiveMQ WebSocket Client.
- Connect to the MQTT broker and subscribe to the topic you set (e.g.,
iot/weather
) to view real-time data.
The IoT Weather Monitoring System is a powerful yet simple tool for continuously monitoring environmental conditions, providing real-time data that is easily accessible from anywhere. Below are some common use cases and the benefits of using this system:
Use Case | Description |
---|---|
Home Monitoring | Track indoor temperature and humidity to maintain a comfortable living environment, and receive alerts when conditions reach uncomfortable or potentially harmful levels. |
Greenhouses and Gardens | Monitor climate conditions in greenhouses to ensure optimal temperature and humidity for plant growth, reducing the risk of plant stress or disease. |
Storage Facilities | Maintain the ideal environment for sensitive materials (e.g., electronics, food, documents) by tracking temperature and humidity levels and preventing conditions that could lead to deterioration. |
- The system acts as a lightweight, affordable remote weather station, ideal for individuals, hobbyists, or researchers in rural or outdoor areas.
- Weather Data Collection: Collect environmental data over time, gaining insights into local weather patterns without the need for expensive equipment.
- Public Weather Sharing: Share data with local communities or organizations that may benefit from having real-time environmental data, especially in areas without formal weather stations.
- Hands-On Learning for IoT Concepts: This project serves as an excellent learning resource for students and beginners, providing experience with microcontrollers, sensors, and MQTT.
- Understanding Cloud and Network Communication: Gain knowledge of cloud-based communication, networking protocols (e.g., MQTT), and data publishing by seeing how sensor data travels from a device to the cloud.
- Data Analysis: Integrate with cloud platforms like AWS IoT or Google Cloud IoT to log data for long-term analysis, helping identify trends and enabling predictive insights.
- Smart Automation: Set up smart actions based on specific conditions, such as automatically turning on a fan or humidifier if temperature or humidity thresholds are exceeded.
- Remote Access: Data is accessible via any internet-connected device, allowing users to stay informed about environmental changes in real-time.
- Low-Cost and Scalable: Compared to commercial weather stations, this project is highly affordable and scalable, with the ability to add additional sensors or functionalities as needed.
- Flexibility: The system can be adapted to various environments and expanded to suit specific needs, making it suitable for both small and large applications.
This IoT Weather Monitoring System is a practical, versatile solution that combines ease of use with powerful capabilities, enabling users to gain valuable environmental insights and take proactive actions based on real-time data.