Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Powered Environmental Monitoring System with SCD30, MQ-136, and Methane Sensors

Image of ESP32-Powered Environmental Monitoring System with SCD30, MQ-136, and Methane Sensors

Circuit Documentation

Summary

This document provides a detailed overview of a circuit designed to measure various environmental parameters using multiple sensors and an ESP32 microcontroller. The circuit includes sensors for detecting H2S, CH4, CO2, temperature, and humidity. The data collected by these sensors is processed by the ESP32 microcontroller and can be integrated with Home Assistant using ESPHome.

Component List

  1. MQ-136

    • Description: H2S Gas Sensor
    • Pins: GND, OUT1, OUT2, VCC
  2. ESP32-POE2

    • Description: ESP32 microcontroller with Power over Ethernet (PoE) capability
    • Pins: 12/24V Selectable, 5VP, 5V, 3.3V, EN, GPIO0, GPIO1\U0TXD, GPIO2\HS2_DATA0, GPIO3\U0RXD, GPIO4\U1TXD, GPIO5\SPI_CS, GPIO12\PHY_PWR (MTDI), GPIO13\12C-SDA (MTCK), GND, GPI39, GPI36\U1RXD, GPI35, GPI34\BUT1, GPIO33, GPIO32, GPIO16\I2C-SCL, GPIO15\HS2_CMD(MTDO), GPIO14\HS2_CLK(MTMS), GPIO13\I2C-SDA(MTCK)
  3. Power Distribution Board

    • Description: Board for distributing power to various components
    • Pins: Output 1+, Input +, Input -, Output 2+, Output 2-, Output 3+, Output 4+, Output 5+, Output 1-, Output 4-, Output 3-, Output 5-, Output 6+, Output 6-, Output 7+, Output 7-, Output 8+, Output 8-, Output 9+, Output 9-, Output 10+, Output 10-, Output 11+, Output 11-, Output 12+, Output 12-, Output +, Output -
  4. Adafruit SCD30

    • Description: CO2, Temperature, and Humidity Sensor
    • Pins: VCC, 3.3V, GND, SCL, SDA, RDY
  5. DHT22

    • Description: Temperature and Humidity Sensor
    • Pins: VCC, OUT, GND
  6. SJH-100A Cubic 100% Methane Sensor

    • Description: CH4 Gas Sensor
    • Pins: Vi, GND, TX, Vout, RX

Wiring Details

MQ-136

  • GND: Connected to Power Distribution Board (Output 7-)
  • OUT1: Connected to ESP32-POE2 (GPIO2\HS2_DATA0)
  • OUT2: Connected to ESP32-POE2 (GPI34\BUT1)
  • VCC: Connected to Power Distribution Board (Output 7+)

ESP32-POE2

  • 5VP: Connected to Power Distribution Board (Input +)
  • GND: Connected to Power Distribution Board (Input -)
  • GPIO2\HS2_DATA0: Connected to MQ-136 (OUT1)
  • GPI34\BUT1: Connected to MQ-136 (OUT2)
  • GPIO3\U0RXD: Connected to SJH-100A Cubic 100% Methane Sensor (TX)
  • GPIO12\PHY_PWR (MTDI): Connected to Adafruit SCD30 (RDY)
  • GPIO13\12C-SDA (MTCK): Connected to Adafruit SCD30 (SDA)
  • GPIO14\HS2_CLK(MTMS): Connected to Adafruit SCD30 (SCL)
  • GPIO33: Connected to SJH-100A Cubic 100% Methane Sensor (RX)

Power Distribution Board

  • Output 7-: Connected to MQ-136 (GND)
  • Output 7+: Connected to MQ-136 (VCC)
  • Input +: Connected to ESP32-POE2 (5VP)
  • Input -: Connected to ESP32-POE2 (GND)
  • Output 8+: Connected to SJH-100A Cubic 100% Methane Sensor (Vi)
  • Output 8-: Connected to SJH-100A Cubic 100% Methane Sensor (GND)
  • Output 9+: Connected to Adafruit SCD30 (VCC)
  • Output 9-: Connected to Adafruit SCD30 (GND)

Adafruit SCD30

  • VCC: Connected to Power Distribution Board (Output 9+)
  • GND: Connected to Power Distribution Board (Output 9-)
  • SCL: Connected to ESP32-POE2 (GPIO14\HS2_CLK(MTMS))
  • SDA: Connected to ESP32-POE2 (GPIO13\12C-SDA (MTCK))
  • RDY: Connected to ESP32-POE2 (GPIO12\PHY_PWR (MTDI))

SJH-100A Cubic 100% Methane Sensor

  • Vi: Connected to Power Distribution Board (Output 8+)
  • GND: Connected to Power Distribution Board (Output 8-)
  • TX: Connected to ESP32-POE2 (GPIO3\U0RXD)
  • RX: Connected to ESP32-POE2 (GPIO33)

Documented Code

MQ-136 Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

ESP32-POE2 Code

/*
 * This Arduino Sketch is designed for an ESP32 microcontroller connected to
 * MQ-4, SCD30, and MQ-136 sensors. The code measures moisture, temperature,
 * CO2, H2S, and CH4 levels. The data is integrated with Home Assistant using
 * ESPHome.
 */

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_SCD30.h>
#include <ETH.h> // Include the Ethernet library

Adafruit_SCD30 scd30;

// Pin definitions
const int MQ4_A0_PIN = 1; // GPIO1\\U0TXD
const int MQ4_D0_PIN = 35; // GPI35
const int MQ136_OUT1_PIN = 2; // GPIO2\\HS2_DATA0
const int MQ136_OUT2_PIN = 34; // GPI34\\BUT1
const int SCD30_RDY_PIN = 12; // GPIO12\\PHY_PWR (MTDI)
const int ETH_CLK_MODE = ETH_CLOCK_GPIO0_IN; // Define GPIO0 as Ethernet clock source pin

void setup() {
  Serial.begin(115200);
  Wire.begin();

  // Initialize Ethernet
  ETH.begin(ETH_CLK_MODE);

  // Initialize SCD30
  if (!scd30.begin()) {
    Serial.println("Failed to find SCD30 chip");
    while (1) { delay(10); }
  }
  Serial.println("SCD30 Found!");
}

void loop() {
  // Read SCD30 data
  if (scd30.dataReady()) {
    if (!scd30.read()) {
      Serial.println("Error reading SCD30");
      return;
    }
    Serial.print("CO2: ");
    Serial.print(scd30.CO2, 2);
    Serial.print(" ppm, Temp: ");
    Serial.print(scd30.temperature, 2);
    Serial.print(" C, Humidity: ");
    Serial.print(scd30.relative_humidity, 2);
    Serial.println(" %");
  }

  // Read MQ-4 data
  int mq4_analog = analogRead(MQ4_A0_PIN);
  int mq4_digital = digitalRead(MQ4_D0_PIN);
  Serial.print("MQ-4 Analog: ");
  Serial.print(mq4_analog);
  Serial.print(", Digital: ");
  Serial.println(mq4_digital);

  // Read MQ-136 data
  int mq136_out1 = digitalRead(MQ136_OUT1_PIN);
  int mq136_out2 = digitalRead(MQ136_OUT2_PIN);
  Serial.print("MQ-136 OUT1: ");
  Serial.print(mq136_out1);
  Serial.print(", OUT2: ");
  Serial.println(mq136_out2);

  delay(2000); // Delay for 2 seconds
}

Power Distribution Board Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}