MQ2 vs MP2 sensor on ESPHome

Hi everyone,

Just wanted to share my experience with these 2 sensors, currently I’m just testing sensors before doing any integrations

The smaller MP2 was faster to pick up a burning cigarette placed right near it, while the MQ2 required the smoke to be inhaled right in, however after the smoke was gone the % of MQ2 recovered almost instantly, while the MP2 gradually reduced

All this being said, when I checked the graph of MQ2 - there was a 100% spike in a moment I didn’t test anything

So while it’s not really a scientific test, I’d just go ahead with a Chinese MP2 for smoke detection applications

Used the same code for both sensors:

sensor:
  - platform: adc
    pin: A0
    name: "MP2 Smoke Sensor"
    update_interval: 1s
    filters:
      - multiply: 100
    unit_of_measurement: "%"
    icon: "mdi:percent"

The sensors:

Being from Turkey I can only buy electronic from Aliexpress :frowning:

I suggest paying more and buying electronics from more reliable sources whenever possible, the MQ2 spike might have been caused by a clone NodeMCU 8266 board spiking things on power up, I could’ve never guessed I’d have to deal with so many power issues, these boards kill AMS1117’s like flies and my little remaining electrical experience is not enough to make sense of it all

1 Like

Interesting. I have had an MQ2 in service for a few months and hadn’t given it much thought. But I tested it recently and was very happy with its ability to notice a lit match underneath it quite quickly. I’ve been looking at the chart history and have noticed the MQ2 levels rising when I am home as opposed to not home as well. I think it’s a neat device and I haven’t observed any spikes in my charts. I think it might be the 8266, as you mentioned, or maybe not all MQ2 are created equal. Nonetheless, thanks for the informative thread.

Hi, a made YAML code for MQ2, witch output CO, Smoke and LPG level of percent.

 - platform: adc # MQ2  
    pin: GPIO03
    id: mq2_sensor
    name: "mq2_sensor_raw"
    update_interval: 0.5s
    accuracy_decimals: 6
    icon: mdi:smoke
    internal: False
    filters: 
      - sliding_window_moving_average:
          window_size: 50
          send_every: 2


  - platform: template 
    id: smoke_value
    name: "Smoke Level"
    update_interval: 1s
    accuracy_decimals: 2
    unit_of_measurement: "%"
    icon: mdi:smoke
    lambda: |-
          float  Ro  =  10; 
          float RO_CLEAN_AIR_FACTOR = 9.83;
          float RL_VALUE = 5;
          float adc_bit= 4095;
          float raw_value = id(mq2_sensor).state;
          float  SmokeCurve[3] = { 2.3, 0.53, -0.44 } ;
          Ro = ((((float)RL_VALUE*(adc_bit-raw_value)/raw_value)))/ RO_CLEAN_AIR_FACTOR;
          float rs_ro_ratio =  ((((float)RL_VALUE*(adc_bit-raw_value)/raw_value)))/Ro  ;
          return (pow(10,( ((log(rs_ro_ratio)-SmokeCurve[1])/SmokeCurve[2]) + SmokeCurve[0])))*100; 


  - platform: template 
    id: lpg_value
    name: "LPG Level"
    update_interval: 1s
    accuracy_decimals: 2
    unit_of_measurement: "%"
    icon: mdi:gas-burner
    lambda: |-
          float  Ro  =  10; 
          float RO_CLEAN_AIR_FACTOR = 9.83;
          float RL_VALUE = 5;
          float adc_bit= 4095;
          float raw_value = id(mq2_sensor).state;
          float  LPGCurve[3] = { 2.3, 0.21, -0.47 } ;
          Ro = ((((float)RL_VALUE*(adc_bit-raw_value)/raw_value)))/ RO_CLEAN_AIR_FACTOR;
          float rs_ro_ratio =  ((((float)RL_VALUE*(adc_bit-raw_value)/raw_value)))/Ro  ;
          return (pow(10,( ((log(rs_ro_ratio)-LPGCurve[1])/LPGCurve[2]) + LPGCurve[0])))*100; 

  - platform: template
    id: co_value
    name: "CO Level"
    update_interval: 1s
    accuracy_decimals: 2
    unit_of_measurement: "%"
    icon: mdi:molecule-co
    lambda: |-
          float  Ro  =  10; 
          float RO_CLEAN_AIR_FACTOR = 9.83;
          float RL_VALUE = 5;
          float adc_bit= 4095;
          float raw_value = id(mq2_sensor).state;
          float  LPGCurve[3] = { 2.3, 0.72, -0.34} ;
          Ro = ((((float)RL_VALUE*(adc_bit-raw_value)/raw_value)))/ RO_CLEAN_AIR_FACTOR;
          float rs_ro_ratio =  ((((float)RL_VALUE*(adc_bit-raw_value)/raw_value)))/Ro  ;
          return (pow(10,( ((log(rs_ro_ratio)-LPGCurve[1])/LPGCurve[2]) + LPGCurve[0])))*100; 

MQ-2 sensor work with 5 V

in code you can change
pin: GPIO03 # Sensor AO pin for your esp GPIO pin
adc_bit= 4095 # your esp GPIO bit value, change value with for 10-bit value 1023, 12-bit value 4095

All calculation from Manufactor Web Site