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

ESP32-Based Gas Level Monitoring System with MQ6 Sensor and OLED Display

Image of ESP32-Based Gas Level Monitoring System with MQ6 Sensor and OLED Display

Circuit Documentation

Summary

This circuit is designed to monitor gas levels using an MQ6 sensor and display the readings on an OLED 1.3" display via an ESP32 microcontroller. The ESP32 also controls a Piezo Buzzer for audible alerts and a Servo motor for physical responses. A SIM800L GSM Module is included for communication capabilities. Power management is handled by a Buck converter connected to a 2.1mm DC Barrel Jack. The circuit includes resistors for current limiting and voltage division.

Component List

ESP32 - 38 pins

  • A microcontroller with WiFi and Bluetooth capabilities.
  • It has a variety of GPIO pins for interfacing with sensors, actuators, and communication modules.

Piezo Buzzer

  • An electronic device that emits sound when an electric signal is applied.
  • Typically used for generating beeps, alarms, and other audio signals.

SIM800L GSM Module

  • A cellular communication module that allows the circuit to send SMS, make calls, and use GPRS for internet connectivity.

Resistor (10 Ohms)

  • A passive two-terminal electrical component that implements electrical resistance as a circuit element.

Resistor (20 Ohms)

  • Another resistor with a different resistance value for current limiting or voltage division.

Servo

  • An actuator that can be precisely controlled for angular or linear position, velocity, and acceleration.

MQ6 Gas Sensor

  • A gas sensor used for detecting the levels of LPG, butane gas, and propane in the air.

Buck Converter

  • A DC-to-DC power converter that steps down voltage from its input to its output.

OLED 1.3" Display

  • A small display module for showing text and graphics, interfaced via I2C.

2.1mm DC Barrel Jack

  • A power connector typically used for attaching external power sources to the circuit.

Wiring Details

ESP32 - 38 pins

  • SP connected to Resistor (10 Ohms)
  • G14 connected to Piezo Buzzer
  • GND connected to the ground network
  • 5V connected to the 5V network
  • G22 (SCL) connected to OLED 1.3" SCL
  • TXD connected to SIM800L GSM Module SIM_TXD
  • RXD connected to SIM800L GSM Module SIM_RXD
  • G21 (SDA) connected to OLED 1.3" SDA
  • G18 connected to Servo pulse

Piezo Buzzer

  • pin 1 connected to ESP32 G14
  • pin 2 connected to the ground network

SIM800L GSM Module

  • 5V connected to the 5V network
  • GND connected to the ground network
  • SIM_TXD connected to ESP32 TXD
  • SIM_RXD connected to ESP32 RXD

Resistor (10 Ohms)

  • pin1 connected to ESP32 SP
  • pin2 connected to MQ6 A0

Resistor (20 Ohms)

  • pin1 connected to the ground network
  • pin2 connected to MQ6 A0

Servo

  • gnd connected to the ground network
  • vcc connected to the 5V network
  • pulse connected to ESP32 G18

MQ6 Gas Sensor

  • VCC connected to the 5V network
  • GND connected to the ground network
  • A0 connected to Resistor (10 Ohms) and Resistor (20 Ohms)

Buck Converter

  • IN+ connected to 2.1mm DC Barrel Jack switch
  • IN- connected to 2.1mm DC Barrel Jack sleeve
  • OUT+ connected to the 5V network
  • OUT- connected to the ground network

OLED 1.3" Display

  • GND connected to the ground network
  • VCC connected to the 5V network
  • SCL connected to ESP32 G22
  • SDA connected to ESP32 G21

2.1mm DC Barrel Jack

  • switch connected to Buck Converter IN+
  • sleeve connected to Buck Converter IN-
  • center connected to Buck Converter IN-

Documented Code

/*
 * This Arduino Sketch monitors the gas level using the MQ6 sensor and
 * displays the gas level on an I2C OLED screen. The MQ6 sensor's analog
 * output is connected to pin SP of the ESP32, and the OLED is connected
 * via I2C to pins G21 (SDA) and G22 (SCL) of the ESP32.
 */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Initialize the OLED with the I2C address 0x27 and 16x2 display
LiquidCrystal_I2C lcd(0x27, 16, 2);

// Define the pin for the MQ6 sensor
const int mq6Pin = 34; // SP pin on ESP32

void setup() {
  // Initialize the OLED
  lcd.begin();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Gas Level:");

  // Initialize the serial communication for debugging
  Serial.begin(115200);
}

void loop() {
  // Read the analog value from the MQ6 sensor
  int gasLevel = analogRead(mq6Pin);

  // Print the gas level to the serial monitor
  Serial.print("Gas Level: ");
  Serial.println(gasLevel);

  // Display the gas level on the OLED
  lcd.setCursor(0, 1);
  lcd.print("Level: ");
  lcd.print(gasLevel);

  // Wait for a short period before the next reading
  delay(1000);
}

Note: The code provided is for an Arduino sketch that uses the LiquidCrystal_I2C library to interface with an I2C OLED display. The MQ6 sensor's analog output is read by the ESP32 and displayed on the OLED. Serial communication is also initialized for debugging purposes.