ESP32-Based Gas Level Monitoring System with MQ6 Sensor and OLED Display
View and Edit Project In Cirkit Designer
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
SPconnected to Resistor (10 Ohms)G14connected to Piezo BuzzerGNDconnected to the ground network5Vconnected to the 5V networkG22(SCL) connected to OLED 1.3" SCLTXDconnected to SIM800L GSM Module SIM_TXDRXDconnected to SIM800L GSM Module SIM_RXDG21(SDA) connected to OLED 1.3" SDAG18connected to Servo pulse
Piezo Buzzer
pin 1connected to ESP32 G14pin 2connected to the ground network
SIM800L GSM Module
5Vconnected to the 5V networkGNDconnected to the ground networkSIM_TXDconnected to ESP32 TXDSIM_RXDconnected to ESP32 RXD
Resistor (10 Ohms)
pin1connected to ESP32 SPpin2connected to MQ6 A0
Resistor (20 Ohms)
pin1connected to the ground networkpin2connected to MQ6 A0
Servo
gndconnected to the ground networkvccconnected to the 5V networkpulseconnected to ESP32 G18
MQ6 Gas Sensor
VCCconnected to the 5V networkGNDconnected to the ground networkA0connected to Resistor (10 Ohms) and Resistor (20 Ohms)
Buck Converter
IN+connected to 2.1mm DC Barrel Jack switchIN-connected to 2.1mm DC Barrel Jack sleeveOUT+connected to the 5V networkOUT-connected to the ground network
OLED 1.3" Display
GNDconnected to the ground networkVCCconnected to the 5V networkSCLconnected to ESP32 G22SDAconnected to ESP32 G21
2.1mm DC Barrel Jack
switchconnected to Buck Converter IN+sleeveconnected to Buck Converter IN-centerconnected 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.