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.
MQ-136
ESP32-POE2
Power Distribution Board
Adafruit SCD30
DHT22
SJH-100A Cubic 100% Methane Sensor
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
/*
* 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
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}