Skip to content

LangerSword/dht11-raspberry-pi-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dht11-raspberry-pi-monitor

"""

🌡️ DHT11 Temperature & Humidity Monitoring System

IoT project for real-time temperature and humidity monitoring using Raspberry Pi and DHT11 sensor with Flask web dashboard.

📋 Project Overview

This system interfaces a DHT11 digital sensor with a Raspberry Pi to monitor environmental conditions and display the data on a responsive web dashboard that auto-updates every 2 seconds.

🎯 Objectives

  • ✅ Interface DHT11 sensor with Raspberry Pi GPIO
  • ✅ Read temperature and humidity data using Python
  • ✅ Display readings on terminal at regular intervals
  • ✅ Create Flask-based web dashboard for live data visualization
  • ✅ Understand GPIO pin configuration and sensor protocols

🛠️ Hardware Requirements

  • Raspberry Pi (any model with GPIO pins)
  • DHT11 Temperature & Humidity Sensor
  • 10kΩ Resistor (pull-up)
  • Jumper wires
  • Breadboard (optional)

📐 Circuit Diagram

DHT11 Sensor Pinout:
┌─────────────┐
│    DHT11    │
│  ┌───────┐  │
│  │ Front │  │
└──┴───────┴──┘
   │ │ │ │
   1 2 3 4

Pin 1 (VCC)  → Raspberry Pi 3.3V (Pin 1) or 5V (Pin 2)
Pin 2 (DATA) → Raspberry Pi GPIO4 (Pin 7) + 10kΩ resistor to VCC
Pin 3 (NC)   → Not Connected
Pin 4 (GND)  → Raspberry Pi Ground (Pin 6)

🔧 Installation

1. Clone Repository

git clone https://github.com/YOUR_USERNAME/dht11-raspberry-pi-monitor.git
cd dht11-raspberry-pi-monitor

2. Install Dependencies

sudo apt-get update
sudo apt-get install python3-pip
pip3 install -r requirements.txt

3. Hardware Setup

  1. Connect DHT11 sensor to Raspberry Pi GPIO4
  2. Add 10kΩ pull-up resistor between DATA and VCC
  3. Verify connections

4. Configure Application

Edit config.py to match your setup:

DHT_GPIO_PIN = 4  # Change if using different GPIO

5. Run Application

# Uncomment hardware lines in app.py first!
python3 app.py

6. Access Dashboard

Open browser: http://localhost:5000

📱 Features

  • Real-time Monitoring: Updates every 2 seconds
  • Responsive Design: Works on mobile and desktop
  • REST API: /api/sensor-data endpoint for integration
  • Error Handling: Graceful failure on sensor read errors
  • Status Indicators: Visual feedback for sensor status

🧠 Technical Details

GPIO Pin Configuration

  • Uses BCM (Broadcom) pin numbering
  • GPIO4 = Physical pin 7 on 40-pin header
  • Configured as INPUT with pull-up resistor

DHT11 Communication Protocol

  1. Start Signal: MCU pulls DATA LOW for 18ms
  2. Response: Sensor pulls DATA LOW for 80μs, then HIGH for 80μs
  3. Data Transmission: 40 bits sent (5 bytes)
    • Byte 1: Humidity integer
    • Byte 2: Humidity decimal (always 0 for DHT11)
    • Byte 3: Temperature integer
    • Byte 4: Temperature decimal (always 0 for DHT11)
    • Byte 5: Checksum (sum of bytes 1-4)
  4. Bit Encoding:
    • 0 bit: 50μs LOW + 26-28μs HIGH
    • 1 bit: 50μs LOW + 70μs HIGH

Flask Architecture

  • Backend: Flask serves API and web pages
  • Frontend: HTML/CSS/JavaScript for dashboard
  • AJAX: Periodic polling for live updates
  • REST API: JSON responses for sensor data

📊 API Endpoints

GET /api/sensor-data

Returns current sensor readings

{
  "temperature": 25.5,
  "humidity": 60.2,
  "timestamp": "2024-11-05 14:30:22",
  "status": "success"
}

GET /api/sensor-info

Returns sensor configuration

{
  "sensor_type": "DHT11",
  "gpio_pin": 4,
  "update_interval": 2,
  "temp_range": "0-50°C",
  "humidity_range": "20-90%"
}

🐛 Troubleshooting

Sensor reads return None:

  • Check wiring connections
  • Verify GPIO pin number
  • Ensure pull-up resistor is connected
  • Try different GPIO pin

Permission denied error:

  • Run with sudo: sudo python3 app.py
  • Or add user to gpio group: sudo usermod -a -G gpio $USER

Module not found:

  • Reinstall: pip3 install --upgrade -r requirements.txt
  • Check Python version: python3 --version (needs 3.7+)

📚 Learning Resources

👨‍💻 Author

Your Name - Next Tech Lab Assignment

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors