What is the MQ6 Sensor?
The MQ6 gas sensor is designed to detect gases like Liquefied Petroleum Gas (LPG), propane, and butane. It is widely used in gas leak detection applications due to its sensitivity and reliability.
Advantages of the MQ6 Sensor:
- High Sensitivity: Capable of detecting low concentrations of gas, ensuring early detection of potential leaks.
- Wide Range of Detection: Effective for various gases, making it versatile for different applications.
- Analog and Digital Outputs: Provides both analog and digital signals for flexible integration into various systems.
- Cost-Effective: Affordable compared to other gas detection solutions, making it accessible for DIY projects.
How to Integrate the MQ6 Sensor with ESPHome
Integrating the MQ6 sensor with ESPHome allows you to monitor gas levels in real-time and send alerts via Home Assistant. Below are the steps to set up the MQ6 sensor with ESPHome.
Wiring the MQ6 Sensor
- Connections:
- A0 (Analog Output) to GPIO34 on the ESP32.
- GND to GND.
- VCC to 5V.
- DO (Digital Output) to GPIO35.
Sample ESPHome Configuration
Here’s an example of the YAML configuration to set up the MQ6 sensor in ESPHome:
esphome:
name: esp32-kitchen-gasleak
esp32:
board: nodemcu-32s
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX="
ota:
password: "XXXXXXXXXXXXXXXXXXXXXXXXXX"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
manual_ip:
static_ip: 192.168.0.XX
gateway: 192.168.0.XX
subnet: 255.255.255.0
dns1: 192.168.0.XX
dns2: 192.168.0.XX
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "esp32-gasleak_Fallback_Hotspot"
password: "XXXXXXXXXXXX"
captive_portal:
# Analog sensor (A0 connected to GPIO34)
sensor:
- platform: adc
pin: GPIO34
name: "Kitchen Gas Leak Sensor v1.1"
update_interval: 60s
attenuation: 11db
unit_of_measurement: "ppm"
# Digital sensor (DO connected to GPIO35)
binary_sensor:
- platform: gpio
pin: GPIO35
name: "Kitchen Gas Leak Detector (Digital)"
device_class: gas



Automation for Gas Leak Alerts
To ensure your safety, it’s essential to have an alert system in place. Below is an automation example that sends notifications and plays a warning sound based on gas concentration levels:
alias: LPG Gas Leak Alert
description: "Triggers notifications and alarm based on gas concentration levels"
mode: single
triggers:
- platform: numeric_state
entity_id: sensor.kitchen_gas_leak_sensor_v1_1
above: 100
for:
minutes: 1
id: "medium" # Medium alert level trigger
- platform: numeric_state
entity_id: sensor.kitchen_gas_leak_sensor_v1_1
above: 500
for:
seconds: 30
id: "high" # High alert level trigger
conditions: []
actions:
- choose:
# High gas concentration action (above 500 ppm)
- conditions:
- condition: trigger
id: "high"
sequence:
- service: telegram_bot.send_message
data:
message: "⚠️ High gas concentration detected! Immediate action required!"
title: LPG Sensor Alert
target: -XXXXXXX # Your Telegram chat ID
- service: media_player.play_media
target:
entity_id: media_player.blr_speaker_group # Your speaker group
data:
media_content_id: media-source://media_source/local/High_Alert.mp3
media_content_type: audio/mpeg
# Medium gas concentration action (above 100 ppm)
- conditions:
- condition: trigger
id: "medium"
sequence:
- service: telegram_bot.send_message
data:
message: "⚠️ Gas concentration has exceeded safe levels. Please check!"
title: LPG Sensor Warning
target: -XXXXXXXX
- service: media_player.play_media
target:
entity_id: media_player.blr_speaker_group
data:
media_content_id: media-source://media_source/local/Warning_LPGGas_Detected.mp3
media_content_type: audio/mpeg
default: []
Adjusting the Potentiometer for Digital Output Sensitivity
During the integration of the MQ6 sensor, I noticed that the digital output (DO
) pin was detecting gas even at very low concentrations, while the analog sensor showed lower values. This is because the digital output works on a simple high/low logic, which is based on a preset threshold controlled by a potentiometer on the sensor.
The potentiometer allows you to adjust the gas concentration level at which the digital sensor triggers an alert. By turning the potentiometer screw, you can increase or decrease the sensitivity:
- Increase Sensitivity: If you want the sensor to trigger alerts at lower gas concentrations, turn the potentiometer to lower the threshold.
- Decrease Sensitivity: If the sensor is too sensitive and triggers frequently, adjust the potentiometer to a higher threshold, so it only alerts you at higher gas concentrations.
This fine-tuning helps avoid false positives and ensures the system only triggers alerts when necessary. In my case, adjusting the potentiometer reduced the frequency of “detected” states, allowing the digital output to trigger only at higher gas levels.

Acknowledgments
I would like to express my gratitude to the following:
- MQ6 Sensor Vendors: Thank you for providing reliable and efficient gas detection solutions.
- ESPHome: For creating a user-friendly platform that allows seamless integration of sensors with Home Assistant.
- Home Assistant: For their powerful automation capabilities that enhance home security and safety.
- Open Source Community: Your contributions make projects like these possible, empowering DIY enthusiasts and makers worldwide.
Project Cost


Conclusion
Integrating the MQ6 gas sensor with ESPHome and Home Assistant not only enhances home safety but also provides a practical application for DIY projects. With the automation in place, you can rest assured knowing that you will be alerted in case of any gas leaks.