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

ESP32-Based Environmental Monitoring System with I2C Multiplexer and Gas Sensor

Image of ESP32-Based Environmental Monitoring System with I2C Multiplexer and Gas Sensor

Circuit Documentation

Summary

This circuit utilizes an ESP32 microcontroller to interface with various sensors and an I2C multiplexer (Adafruit TCA9548A). The ESP32 reads data from a DHT11 temperature and humidity sensor and an MQ-5 gas sensor. The I2C multiplexer allows multiple I2C devices to be connected to the ESP32. The data collected from the sensors is printed to the Serial Monitor.

Component List

  1. ESP32 (30 pin)

    • Description: A powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities.
    • Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
  2. Adafruit TCA9548A

    • Description: An I2C multiplexer that allows multiple I2C devices to be connected to a single I2C bus.
    • Pins: 2SDA, 2SCL, 3SDA, 3SCL, 4SDA, 4SCL, 5SDA, 5SCL, 6SDA, 6SCL, 7SDA, 7SCL, VCC, GND, INPUTSDA, INPUTSCL, RESET, A0, A1, A2, 0SDA, 0SCL, 1SDA, 1SCL
  3. 5 pin relimate connector

    • Description: A connector used to interface with various sensors and devices.
    • Pins: vcc, GND, SDA, SCL, ADDR
  4. DHT11

    • Description: A temperature and humidity sensor.
    • Pins: 5V, S, GND
  5. MQ-5

    • Description: A gas sensor used to detect the presence of gases such as LPG, methane, and hydrogen.
    • Pins: VCC, GND, Digi Out, Analog out

Wiring Details

ESP32 (30 pin)

  • D32: Connected to MQ-5 Analog out
  • GND: Connected to GND of multiple components (5 pin relimate connectors, Adafruit TCA9548A, MQ-5, DHT11)
  • D22: Connected to Adafruit TCA9548A INPUTSCL
  • D21: Connected to Adafruit TCA9548A INPUTSDA
  • D4: Connected to DHT11 S
  • 3V3: Connected to VCC of multiple components (5 pin relimate connectors, Adafruit TCA9548A, MQ-5, DHT11)

Adafruit TCA9548A

  • INPUTSCL: Connected to ESP32 D22
  • INPUTSDA: Connected to ESP32 D21
  • GND: Connected to GND of multiple components (5 pin relimate connectors, ESP32, MQ-5, DHT11)
  • VCC: Connected to 3V3 of ESP32
  • 2SDA: Connected to 5 pin relimate connector SDA
  • 2SCL: Connected to 5 pin relimate connector SCL
  • 3SDA: Connected to 5 pin relimate connector SDA
  • 3SCL: Connected to 5 pin relimate connector SCL
  • 4SDA: Connected to 5 pin relimate connector SDA
  • 4SCL: Connected to 5 pin relimate connector SCL
  • 5SDA: Connected to 5 pin relimate connector SDA
  • 5SCL: Connected to 5 pin relimate connector SCL
  • 6SDA: Connected to 5 pin relimate connector SDA
  • 6SCL: Connected to 5 pin relimate connector SCL
  • 7SDA: Connected to 5 pin relimate connector SDA
  • 7SCL: Connected to 5 pin relimate connector SCL
  • 0SDA: Connected to 5 pin relimate connector SDA
  • 0SCL: Connected to 5 pin relimate connector SCL
  • 1SDA: Connected to 5 pin relimate connector SDA
  • 1SCL: Connected to 5 pin relimate connector SCL

5 pin relimate connectors

  • vcc: Connected to 3V3 of ESP32
  • GND: Connected to GND of multiple components (ESP32, Adafruit TCA9548A, MQ-5, DHT11)
  • SDA: Connected to Adafruit TCA9548A SDA pins (2SDA, 3SDA, 4SDA, 5SDA, 6SDA, 7SDA, 0SDA, 1SDA)
  • SCL: Connected to Adafruit TCA9548A SCL pins (2SCL, 3SCL, 4SCL, 5SCL, 6SCL, 7SCL, 0SCL, 1SCL)

DHT11

  • 5V: Connected to 3V3 of ESP32
  • S: Connected to ESP32 D4
  • GND: Connected to GND of multiple components (ESP32, Adafruit TCA9548A, MQ-5, 5 pin relimate connectors)

MQ-5

  • VCC: Connected to 3V3 of ESP32
  • GND: Connected to GND of multiple components (ESP32, Adafruit TCA9548A, DHT11, 5 pin relimate connectors)
  • Analog out: Connected to ESP32 D32

Code Documentation

/*
 * This Arduino Sketch initializes the I2C multiplexer (Adafruit TCA9548A),
 * reads data from the DHT11 sensor, and reads the analog output from the
 * MQ-5 gas sensor. The data is printed to the Serial Monitor.
 */

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN 4
#define DHTTYPE DHT11
#define MQ5_PIN 32
#define TCAADDR 0x70

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22); // SDA, SCL
  dht.begin();
  tcaSelect(0);
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  int mq5Value = analogRead(MQ5_PIN);

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  } else {
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.println(" *C");
  }

  Serial.print("MQ-5 Analog Value: ");
  Serial.println(mq5Value);

  delay(2000);
}

void tcaSelect(uint8_t i) {
  if (i > 7) return;
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();
}

This code initializes the I2C multiplexer and the DHT11 sensor, reads data from the DHT11 sensor and the MQ-5 gas sensor, and prints the data to the Serial Monitor. The tcaSelect function is used to select the appropriate channel on the I2C multiplexer.