ESPHome a MQ-135 AirQuality senzor

www
Odpovědět
Uživatelský avatar
tiimsvk
Dárce - Donátor
Dárce - Donátor
Příspěvky: 801
Registrován: 06. květen 2021, 07:03
Dal poděkování: 72 poděkování
Dostal poděkování: 65 poděkování

ESPHome a MQ-135 AirQuality senzor

Příspěvek od tiimsvk »

Ahojte podarilo sa mi spojazniť pomocou dvoch tutoriálu na stránkach https://github.com/AlexBelfegor/esphome-mq135 a https://circuitdigest.com/microcontroll ... els-in-ppm

Tým druhym by som začal pre ziskanie hodnoty RZERO pomocou arduina.
Ak ziskate túto hodnotu tak je to potom jednoduché upraviť v mojom kóde

Kód: Vybrat vše

substitutions:
  rload: "24.0"
  rzero: "190.14"
#Parameters for calculating ppm of CO2 from sensor resistance
  para: "116.6020682"
  parb: "2.769034857"

#Parameters to model temperature and humidity dependence
  cora: "0.00035"
  corb: "0.02718"
  corc: "1.39538"
  cord: "0.0018"
 
#Atmospheric CO2 level for calibration purposes
  atmoco2: "419.03"

i2c:
    sda: D2
    scl: D1
    scan: true

sensor:
  - platform: aht10
    update_interval: 5s
    temperature:
      name: "AHT20 temp. (test)"
      id: temp
      accuracy_decimals: 1
    humidity:
      name: "AHT20 humidity (test)"
      id: humidity
      accuracy_decimals: 1

  - platform: bmp280
    temperature:
      name: "Outside Temperature"
      oversampling: 16x
    pressure:
      name: "Outside Pressure"
      id: "pressure"
    address: 0x77
    update_interval: 5s

  - platform: adc
    id: adcco2
    pin: A0
    name: "AnalogRead"
#    filters:
#     multiply: 1.024
    update_interval: 2s
    filters:
      - median:
          window_size: 7
          send_every: 4
          send_first_at: 3

#@brief  Get the correction factor to correct for temperature and humidity

#@param[in] t  The ambient air temperature
#@param[in] h  The relative humidity

#@return The calculated correction factor
  - platform: template
    id: "correctionfactor"
    name: "CorrectionFactor"
    lambda: |-
       return ($cora * id(temp).state * id(temp).state - $corb * id(temp).state + $corc - (id(humidity).state - 33) * $cord);
    update_interval: 3s

#@brief  Get the resistance of the sensor, ie. the measurement value

#@return The sensor resistance in kOhm
  - platform: template
    id: "resistance"
    name: "Resistance"
    lambda: |-
       return (((1.024 / id(adcco2).state) * 5.0 - 1.0) * $rload);
    update_interval: 3s

#@brief  Get the resistance of the sensor, ie. the measurement value corrected
#        for temp/hum

#@param[in] t  The ambient air temperature
#@param[in] h  The relative humidity

#@return The corrected sensor resistance kOhm	
  - platform: template
    id: "correctedresistance"
    name: "CorrectedResistance"
    lambda: |-
       return (id(resistance).state / id(correctionfactor).state);
    update_interval: 3s

#@brief  Get the ppm of CO2 sensed (assuming only CO2 in the air)

#@return The ppm of CO2 in the air
  - platform: template
    name: "PPM"
    id: "ppm"
    lambda: |-
       return ($para * pow((id(resistance).state / $rzero), (-1 * $parb)));
    update_interval: 3s
    unit_of_measurement: ppm
#@brief  Get the ppm of CO2 sensed (assuming only CO2 in the air), corrected
#        for temp/hum

#@param[in] t  The ambient air temperature
#@param[in] h  The relative humidity

#@return The ppm of CO2 in the air	
  - platform: template
    name: "CorrectedPPM"
    lambda: |-
       return ($para * pow((id(correctedresistance).state / $rzero), -$parb));
    update_interval: 3s

#@brief  Get the resistance RZero of the sensor for calibration purposes

#@return The sensor resistance RZero in kOhm	
  - platform: template
    id: "rzero1"
    name: "RZero"
    lambda: |-
       return (id(resistance).state * pow(($atmoco2 / $para), (1.0 / $parb)));
    update_interval: 3s

#@brief  Get the corrected resistance RZero of the sensor for calibration
#        purposes

#@param[in] t  The ambient air temperature
#@param[in] h  The relative humidity

#@return The corrected sensor resistance RZero in kOhm	
  - platform: template
    name: "CorrectedRZero"
    lambda: |-
       return (id(correctedresistance).state * pow(($atmoco2 / $para), (1.0 / $parb)));
    update_interval: 3s
Je to konverzia z originálnych knižníc pre arduino a mq135 sezor.
Upozornenie:
- Pred ešte riešením kódu ale doporučujemskontrolovať RL odpor ja som mal na doske 1kohm a nahradil podla datasheetu 24kohm (moze byt od 10 do 24)
- Senzor je velmi citlivý na vstupné napätie moje riešenie je vložený modul step up na 5,0V (esp dosky maju prepojený kolík 5V s usb priamo takze aké je napätie v usb zasuvke take je na koliku 5V) (Akonahle date ine vstupne napätie údaje velmi skresluje)

Nedávam tu uplne celý návod ale myslim ze toto skúsenjsiemu pouzivatelovi postačuje :)

Ešte foto zapojenia aj s oled displejom u mňa (Planujem to cele implementovať do Vindriktning Ikea krabičky na senzor prachu.
275424546_741792326741202_3652897033684618385_n.jpg
275305486_329757339114083_7965503670113402825_n.jpg
V prilohe je aj excel tabulka keby sa chcel niekto hrat so vstupnými datami
Přílohy
ppm mq135.zip
(7.16 KiB) Staženo 22 x

Odpovědět

Zpět na „ESPHome“