Skip to content

Cloud-connected ESP8266 IoT gas monitoring system with MQ-9 CO sensing, DHT22 environmental data, OLED UI, remote threshold control, and automated email alerts via Thinger.io.

License

Notifications You must be signed in to change notification settings

ShayanSaed/IoT-Environmental-Monitoring-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IoT Environmental Monitoring System (ESP8266 + MQ-9 + DHT22 + OLED)

A fully integrated IoT-based environmental monitoring system built on ESP8266, capable of:

  • Real-time Carbon Monoxide (CO) monitoring (MQ-9)
  • Temperature & Humidity sensing (DHT22)
  • Local OLED visualization
  • Remote dashboard control via Thinger.io
  • Configurable gas threshold
  • Automated email alerting when safety limits are exceeded

Project Preview

Circuit Schematic

Circuit Schematic

Final Hardware Implementation

Final Hardware


Features

  • WiFi-connected IoT device
  • Cloud integration using Thinger.io
  • Live dashboard monitoring
  • Remote threshold configuration
  • Automated email alert system
  • Local OLED real-time display
  • Externalized credentials (secrets.h)
  • Non-blocking timing architecture
  • Edge-side data processing

Data Flow

  1. Sensors are sampled every 2 seconds.
  2. CO concentration is calculated in ppm.
  3. Values are pushed to Thinger.io.
  4. If ppm exceeds threshold:
    • Email alert is triggered
    • Local OLED shows ALERT state
  5. Threshold can be remotely modified from dashboard.

Hardware Components

Component Description
ESP8266 (NodeMCU) WiFi microcontroller
MQ-9 Carbon Monoxide Gas Sensor
DHT22 Temperature & Humidity Sensor
SSD1306 OLED (128x64) I2C Display
Breadboard + Jumpers Prototyping

Cloud Integration

Platform: Thinger.io

Dashboard Preview

Thinger Dashboard

The dashboard provides:

  • Live CO ppm gauge
  • Temperature & Humidity widgets
  • Remote threshold control slider
  • Real-time device status

Exposed Resources

  • environment
    • temperature
    • humidity
    • ppm
  • threshold
    • Read/Write numeric resource

Email Endpoint

gas_alert_email

Payload Structure

{
  "ppm": 350,
  "threshold": 200,
  "temperature": 27.5,
  "humidity": 33.8
}

Email Alert Example

When gas concentration exceeds the configured threshold, an email is automatically triggered.

Alert Email Preview

The email contains:

  • Current CO ppm
  • Configured threshold
  • Temperature
  • Humidity
  • Timestamp of alert

Security Configuration

Sensitive credentials are isolated in secrets.h

Example

#ifndef SECRETS_H
#define SECRETS_H

#define USERNAME "your_username"
#define DEVICE_ID "your_device"
#define DEVICE_CREDENTIAL "your_credential"

#define WIFI_SSID "your_wifi"
#define WIFI_PASSWORD "your_password"

#endif

Gas PPM Calculation

The CO concentration is calculated using the MQ-9 sensor resistance model:

Rs = (3.3 - Vout) * RL / Vout
ratio = Rs / R0
ppm = 1000 * pow(ratio, -1.5)

Where:

Value Description
RL Sensor load resistance (10 kΩ)
R0 Calibrated baseline resistance

NOTE: This measurement is approximate — calibration improves accuracy.


OLED Interface

Display Sections

  • Temperature (°C)
  • Humidity (%)
  • CO ppm
  • ALERT indicator when threshold exceeded

The UI layout uses dynamic text centering and split-screen visualization.


Setup Instructions

  1. Install required Arduino libraries:
    • Adafruit SSD1306
    • Adafruit GFX
    • DHT sensor library
    • ThingerESP8266
  2. Create secrets.h
  3. Upload code to ESP8266
  4. Configure device in Thinger.io
  5. Create Email Endpoint
  6. Add Dashboard widgets

Threshold Logic

if (currentPPM > gasThreshold && !alertSent)
  • Prevents alert spamming
  • Resets when ppm returns to safe range
  • Configurable remotely (200–500 ppm range)

Engineering Considerations

  • Non-blocking loop using millis()
  • Edge-side alert logic
  • Payload-based endpoint invocation
  • Resource-based Cloud API
  • Separation of configuration and logic
  • Memory-efficient design for ESP8266

License

This project is licensed under the MIT License.


Final Note

This project demonstrates a full-stack IoT pipeline:

Sensor → Embedded Processing → Cloud API → Dashboard → Automated Notification

It is suitable for:

  • Academic IoT demonstrations
  • Smart home gas monitoring
  • Industrial safety prototyping
  • Cloud-connected embedded system portfolios

About

Cloud-connected ESP8266 IoT gas monitoring system with MQ-9 CO sensing, DHT22 environmental data, OLED UI, remote threshold control, and automated email alerts via Thinger.io.

Topics

Resources

License

Stars

Watchers

Forks

Languages