MQ-5 Gas sensor reading

I have ESP32 with mq-5 gas sensor.

I am facing a problem, The sensor value is always 7.5% even if there is no gas around, And when there is gas it goes above 12%

Isn’t it should 0% when there is no gas? I’ve tried multiple solutions and nothing worked for me!

Here is my code:

substitutions:
  name: mq5-gas-sensor-1
  friendly_name: MQ-5 Gas Sensor 1

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  min_version: 2024.6.0
  name_add_mac_suffix: true
  project:
    name: esphome.web
    version: dev

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

# Allow Over-The-Air updates
ota:
  - platform: esphome

# Allow provisioning Wi-Fi via serial
improv_serial:

wifi:
  # Set up a wifi access point
  ap: {}

captive_portal:

dashboard_import:
  package_import_url: github://esphome/example-configs/esphome-web/esp32.yaml@main
  import_full_config: true

esp32_improv:
  authorizer: none

# To have a "next url" for improv serial
web_server:

# DIY MQ-5 Smoke & Gas Sensor for Home Assistant
sensor:
  - platform: adc
    pin: GPIO35
    name: "MQ-5 Gas Sensor 1"
    update_interval: 10s
    filters:
      - multiply: 100
    unit_of_measurement: "%"
    icon: "mdi:percent"

image

All you’re doing is taking the voltage measurement and multiplying it by 100, where did you get this from?

Not specifically familiar with that sensor, but in general the voltage just changes based on exposure to whatever gases it’s sensitive to. However, you typically have to calibrate them yourself, so you have to experimentally expose it to them and see what voltage it outputs and then calibrate accordingly.

You need to power it at 3.3V and connect Aout to adc pin of your esp.
Then calibrate the sensor for known gas levels using calibrate linear for example.

When I compile gas reading code in arduino ide
And do the following formula:
Reading / 4059 * 1000

I get real values, but when I do the same thing in esp home I don’t get same values even if using same formula

Esp adc resolution is 0-4095 so that conversion gives you 0-1000 for the whole voltage range 0-3.3V
Esphome ADC component outputs 0-3.3, so you need to multiply by 303 to get same reading.

mq-5 plugged to 5v pin
is that correct ?

Absolutely not with 3.3V MCU.
But it doesn’t change the conversion factor between “arduino code” and esphome…