Home Subscribe

2. Temperature and Humidity Monitoring System

An IoT-based temperature and humidity monitoring system using Arduino, DHT11 sensor, and Python for data analysis. This beginner-friendly project is perfect for students looking to explore the Internet of Things and data visualization.

2.1. Introduction

In this project, we will build a simple IoT-based temperature and humidity monitoring system using an Arduino, a DHT11 sensor, and Python for data analysis. This project is designed for beginners and provides a hands-on experience with IoT concepts and data visualization. You may contribute to this project on GitHub.

2.2. Required Components

To build the project, you will need the following components:

  • Arduino Uno or a similar board

  • Breadboard

  • DHT11 temperature and humidity sensor

  • LED (any color)

  • 330-ohm resistor

  • Jumper wires

2.3. Hardware Setup

Follow these steps to set up the hardware:

  • Connect the DHT11 sensor to the Arduino:

    • Connect the VCC pin of the DHT11 to the 5V pin on the Arduino.

    • Connect the GND pin of the DHT11 to the GND pin on the Arduino.

    • Connect the data pin of the DHT11 to digital pin 2 on the Arduino.

  • Connect the LED to the Arduino:

    • Connect the longer leg (anode) of the LED to digital pin 13 on the Arduino through a 330-ohm resistor.

    • Connect the shorter leg (cathode) of the LED directly to the GND pin on the Arduino.

2.4. Arduino Code

Install the Arduino IDE and the DHT library (DHT-sensor-library) from Adafruit. Write and upload the provided code to the Arduino board.

#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
#define LEDPIN 13

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
pinMode(LEDPIN, OUTPUT);
dht.begin();
}

void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();

if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");

if (temperature > 25) {
digitalWrite(LEDPIN, HIGH);
} else {
digitalWrite(LEDPIN, LOW);
}
delay(2000);
}

2.5. Python Data Analysis

Install Python and the necessary libraries (e.g., pyserial, pandas, matplotlib). Create a Python script to read and analyze the data:

import serial
import time
import pandas as pd
import matplotlib.pyplot as plt

ser = serial.Serial('COM#', 9600) # Replace 'COM#' with the appropriate port number
time.sleep(2)

data = {"Time": [], "Temperature": [], "Humidity": []}

try:
    while True:
        line = ser.readline().decode('utf-8').strip()
        if "Temperature" in line and "Humidity" in line:
            parts = line.split('\t')
            humidity = float(parts[0].split(': ')[1])
            temperature = float(parts[1].split(': ')[1])

            data["Time"].append(time.time())
            data["Temperature"].append(temperature)
            data["Humidity"].append(humidity)

except KeyboardInterrupt:
    ser.close()

df = pd.DataFrame(data)
df.to_csv('temp_humidity_data.csv', index=False)

plt.figure()
df.plot(x='Time', y=['Temperature', 'Humidity'])
plt.xlabel('Time (s)')
plt.ylabel('Temperature (C) / Humidity (%)')
plt.title('Temperature and Humidity Monitoring')
plt.legend(['Temperature', 'Humidity'])
plt.show()

2.6. Usage

Follow these steps to set up and use the temperature and humidity monitoring system:

  • Assemble the hardware components as described in the Hardware Setup section.

  • Upload the Arduino code to the board using the Arduino IDE. The code can be found in the Arduino Code section.

  • Run the Python script for data analysis, provided in the Python Data Analysis section. The script will read data from the Arduino and display a real-time plot of temperature and humidity.

  • Observe the LED on the Arduino board. It will light up when the temperature is above 25 degrees Celsius.

2.7. Areas of Improvement

The current implementation of the IoT temperature and humidity monitoring system serves as a foundation for a beginner-friendly project. However, there are several areas where contributors can improve the project, making it more versatile and feature-rich:

  • Wireless communication: Integrate a Wi-Fi or Bluetooth module (e.g., ESP8266, HC-05) to send data wirelessly from the Arduino to a remote device or server. This allows for real-time monitoring of temperature and humidity data on a smartphone or computer, even from a distance.

  • Web dashboard: Develop a web dashboard to display temperature and humidity data in a user-friendly manner. This can be achieved using web technologies such as HTML, CSS, JavaScript, and web frameworks like Flask or Django.

  • Alerts and notifications: Implement a system to send alerts or notifications via email, SMS, or other messaging platforms when certain thresholds are met, such as when the temperature or humidity exceeds a predefined limit.

  • Data storage: Store the collected data in a database (e.g., SQLite, PostgreSQL, InfluxDB) for long-term storage and analysis. This will allow for better historical data analysis and trend identification.

  • Advanced data analysis: Utilize machine learning techniques or statistical methods to predict future temperature and humidity levels, identify trends, or detect anomalies in the data.

  • Improved hardware design: Design and build a custom PCB or enclosure for the project, making it more robust and suitable for deployment in various environments.

  • Battery-powered operation: Integrate a battery power source and power management system to make the project portable and usable in locations without a direct power supply.

  • Additional sensors: Incorporate other environmental sensors, such as air quality sensors, light sensors, or sound sensors, to create a comprehensive environmental monitoring system.

By working on these areas of improvement, contributors can help enhance the project’s functionality and expand its potential applications, making it more valuable and appealing to a broader audience.

2.8. Conclusion

By following these instructions, you have successfully built an IoT temperature and humidity monitoring system using Arduino, DHT11 sensor, and Python for data analysis. This project is ideal for students who want to learn more about the Internet of Things, sensor data acquisition, and data visualization. Experiment with different settings, sensors, or visualization methods to further enhance your understanding of IoT and data analysis.



Add Comment

* Required information
1000
Drag & drop images (max 3)
Type the word for the number 9.

Comments

No comments yet. Be the first!