Anyone successfully use any of the MQx gas sensors with ESPHome?

I’m trying to build some natural gas detectors for my home using ESP32s and the MQ5 sensors. Has anyone used any of these sensors with ESPHome and HA?

I’m going to try one - I’ve watched videos showing how the sensor has a digital output and an analog output, and both can be used with an ESP’s inputs.

Thanks!

I think it only has analog sensor output , maybe alarm output on digital pin.

I’m using a MQ-2, with an ESP8266, in a smoke detector, which works nicely. I see no reason why a MQ-5 wouldn’t work.

As @Karosm mentions, the MQ-5 has an analog output for measuring the gas and a digital output that will trigger above a certain level, which can be adjusted using the pot-meter.

Thanks for the info. One question I have is the platform setting - would you mind sharing a snippet of your sensor code section?

I am not sure what the platform options are - for example I have used Dallas and DHT for temp sensors but I am not sure what the MQx sensors would use.

Thanks in advance!

I am using simple binary sensors for a smoke detector using MQx sensors on a nodemcu, using the digital output.

binary_sensor:
  - platform: gpio
    pin:
      number: D5
      inverted: true
    name: "Basement smoke"
    device_class: smoke
  - platform: gpio
    pin: 
      number: D6
      inverted: true
    name: "Basement CO"
    device_class: gas

Seems to work fine.

1 Like

Thanks, @rgilijamse, very much appreciated!

I didn’t know there was a simple platform called GPIO, that makes sense.

Curious why you had to invert the signal… do you recall?

Thanks, and it says this was your first post so thank you for your help and welcome to the forums!

It’s a while back, but I had to do some experimentation to get it working, especially since you have to mess with the pot-meter to get the sensor to trigger (by the way, in my case it’s an MQ-7 instead of an MQ-5, but that should be similar). I was testing with a burning match (creates smoke and CO), not sure how you can safely test the MQ-5.

Cool, I was going to use the analog sensor and log the readings I get when I hold it near my gas stove when lighting a burner. I always smell a little bit of gas right at the start when it lights so maybe that would register on the sensor.

I’m eventually going to use it in places where I already have existing Kidde NG sensors, but it turns out those have a 7 year life and one stopped working this morning and just sat there and beeped at me. Those things are a bit expensive, so if the MQ sensors have some sort of lifetime then at least they are cheap to replace.

Thanks, mine are on order and I’ll post any feedback or results I get from my testing since info on this setup seems to be a bit scarce.

I actually do not use the digital output pin at all.

I use this method:

I do not want to rely on HA/WiFi being up, so I decided on this approach. I also disabled ESPHome rebooting when losing connection.