Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Hardware
  3. Air Quality Sensor

Air Quality Sensor

Scheduled Pinned Locked Moved Hardware
calibrationaqigas sensorhchoair quality
270 Posts 46 Posters 308.8k Views 35 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • paqorP Offline
    paqorP Offline
    paqor
    wrote on last edited by
    #124

    I've read about. It sounds interesting.

    I stand a little hard with the development. Is there a skit for MQ135.h and MYSENSORS?

    I will test this afternoon.

    1 Reply Last reply
    0
    • HeinzH Offline
      HeinzH Offline
      Heinz
      Hero Member
      wrote on last edited by
      #125

      Hi @paqor,
      I wrote a little sketch which you could use as a start, it uses the MQ135 library.
      I also used a timer library, but this could be replaced by a simple sleep, too.

      RZERO should be changed when calibrating the sensor, this can be done at compile-time or during runtime by sending the value to the sensor via the gateway.

      Unfortunately I could not test the sketch yet, but it should help you getting started.
      If you have a second sensor which provides humidity and temperature then you can also get the corrected ppm from the library,...

      good luck!

      /*
      MQ135 MySensor
      A0      white
      D0      black
      GND     brown
      5V      red
      */
      
      #include <SPI.h>
      #include <MySensor.h>
      #include <MQ135.h>
      #include "Timer.h"
      
      Timer timer;
      
      // 30 seconds
      #define TEMP_UPDATE_INTERVAL 30000
      
      // MQ135
      #define CHILD_ID_CO2 0
      #define CHILD_ID_R0 1
      
      #define CO2_SENSOR_ANALOG_PIN 0
      
      /// Calibration resistance at atmospheric CO2 level
      #define RZERO 300.0
      #define EEPROM_R0 0
      
      MQ135 gasSensor = MQ135(CO2_SENSOR_ANALOG_PIN, RZERO);
      int lastC02;
      float lastR0;
      
      //-----------------------------------------------------------------------------
      // MySensor
      MySensor gw;
      MyMessage msgCO2(CHILD_ID_CO2, V_VAR1);
      MyMessage msgR0(CHILD_ID_R0, V_VAR1);
      
      //-----------------------------------------------------------------------------
      void setup()
      {
          gw.begin(incomingMessage, AUTO, true);
          gw.sendSketchInfo("MQ135 Sensor", "1.0");
          gw.present(CHILD_ID_CO2, S_AIR_QUALITY);
          gw.present(CHILD_ID_R0, S_CUSTOM);
          
          uint8_t R02 = gw.loadState(EEPROM_R0);
      
          // get R0 from EEPROM
          float R0 = R02 * 2;
      
      	// do a plausibility check
          if (R0 > 1.0 && R0 < 400.0) 
          {
              Serial.print(F("Setting R0 from EEPROM: "));
          }
          else
          {
              Serial.print(F("Setting default R0: "));
              R0 = RZERO;
          }
      
          Serial.print(R0);
          Serial.println(F(""));
      
          gasSensor.setR0(R0);
          
          timer.every(TEMP_UPDATE_INTERVAL, timerHandler);
      }
      
      
      bool MQ135Changed()
      {
          bool changed = false;
      
          lastR0 = gasSensor.getRZero();
          Serial.print(F("R0: "));
          Serial.println(lastR0);
      
          {
              float ppm = gasSensor.getPPM();
      
              Serial.print(F("CO2 ppm: "));
              Serial.print(ppm);
      
      
              int roundedPpm = (int)ppm;
              Serial.print(F(" --> "));
              Serial.println(roundedPpm);
      
              if (roundedPpm != lastC02)
              {
                  lastC02 = roundedPpm;
                  changed = true;
              }
          }
      
          return changed;
      }
      
      
      void timerHandler()
      {
          bool airQualityChanged = MQ135Changed();
          if (airQualityChanged)
          {
              gw.send(msgCO2.set(lastC02));
              gw.send(msgR0.set(lastR0, 2));
          }
      }
      
      
      void loop()
      {
          gw.process();
          timer.update();
      }
      
      
      // Gets the R0 value from the gw passes ot to the lib and stores it into the EEPROM.
      void incomingMessage(const MyMessage& message)
      {
          Serial.println(F("Incoming Message:"));
      
          if (message.isAck())
          {
              Serial.println(F("This is an ack from gateway"));
          }
      
          uint8_t sensor = message.sensor;
          if (sensor == CHILD_ID_R0)
          {
              float R0 = message.getFloat();
      
              Serial.print(F("Incoming R0: "));
              Serial.print(R0);
              Serial.println(F(""));
      
              gw.saveState(EEPROM_R0, (uint8_t)(R0/2));
              gasSensor.setR0(R0);
              gw.send(msgR0.set(R0, 2));
          }
      }
      
      
      1 Reply Last reply
      0
      • paqorP Offline
        paqorP Offline
        paqor
        wrote on last edited by paqor
        #126

        I have compiled from various sources themselves something. The result is https://gleisnetze.de/2015/12/25/das-erste-kleine-programm/ described herein. The most plausible values I received with the MQ135.h library. For that I have then added the transfer after MySensors / FHEM.

        Bildschirmfoto vom 2015-12-25 07-53-25.png

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bhavika
          wrote on last edited by
          #127

          Hello

          In MiCS 2614 or in any gas sensor. what should be the value of R0... Because in datasheet they mentioned that value is measured in ambient condition. Any default value for that??

          epierreE 1 Reply Last reply
          0
          • B bhavika

            Hello

            In MiCS 2614 or in any gas sensor. what should be the value of R0... Because in datasheet they mentioned that value is measured in ambient condition. Any default value for that??

            epierreE Offline
            epierreE Offline
            epierre
            Hero Member
            wrote on last edited by
            #128

            @bhavika said:

            Hello

            In MiCS 2614 or in any gas sensor. what should be the value of R0... Because in datasheet they mentioned that value is measured in ambient condition. Any default value for that??

            The datasheed propose the "clean air calibration": "Sensing resistance in air R0 is measured under controlled ambient conditions, i.e. synthetic air at 23 ±5°C and 50 ± 10% RH. Sampling test."
            so you should go outside and mesure the defautl R0 value in your environment.

            z-wave - Vera -&gt; Domoticz
            rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
            mysensors -&gt; mysensors-gw -&gt; Domoticz

            1 Reply Last reply
            0
            • HeinzH Offline
              HeinzH Offline
              Heinz
              Hero Member
              wrote on last edited by
              #129

              MQ-135 with 10k results in a R0 of around 360 in my environment. So you could start experimenting with values around 300-500. I had to use a voltage regulator to get reliable values from the sensor.

              1 Reply Last reply
              0
              • epierreE Offline
                epierreE Offline
                epierre
                Hero Member
                wrote on last edited by epierre
                #130

                a little update on the MICS-6814:
                NO2: sensible
                CO: flat
                NH3 flat
                chartNO2.jpeg

                For the HCHO:
                charthcho.jpeg

                sorry for the flat part, some arduino issues at this time

                z-wave - Vera -&gt; Domoticz
                rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                mysensors -&gt; mysensors-gw -&gt; Domoticz

                1 Reply Last reply
                0
                • mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by
                  #131

                  Welcome @betthorn, great to have you here.

                  1 Reply Last reply
                  0
                  • epierreE Offline
                    epierreE Offline
                    epierre
                    Hero Member
                    wrote on last edited by
                    #132

                    I have had some questions about converting from mg/m3 to ppm gases, here are the weight values and a proposed method:
                    NH3 17.03 g/mol
                    CO2 44.01
                    CO 28.01
                    H2S 34.08
                    NO2 46.01
                    NO 30.01
                    O3 48.00
                    C6H6 78.11
                    C7H8 92.14

                    you have:
                    NO2 50 μg/m3 gives 26,5868821 ppm
                    O3 27 μg/m3 = 0.027 mg/m3 -> (8,31441298,15)/(48101,325)*27=13,7617025 ppm

                    correct me if I'm wrong

                    z-wave - Vera -&gt; Domoticz
                    rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                    mysensors -&gt; mysensors-gw -&gt; Domoticz

                    1 Reply Last reply
                    1
                    • epierreE Offline
                      epierreE Offline
                      epierre
                      Hero Member
                      wrote on last edited by
                      #133

                      2016 is where IoT for gas sensors are moving to more maturity, Cooking Hacks / Libellium proposed so far Fibaro sensors, but are now proposing more pricey one that are calibrated.

                      See https://www.cooking-hacks.com/shop/sensors/gas

                      z-wave - Vera -&gt; Domoticz
                      rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                      mysensors -&gt; mysensors-gw -&gt; Domoticz

                      1 Reply Last reply
                      0
                      • epierreE Offline
                        epierreE Offline
                        epierre
                        Hero Member
                        wrote on last edited by
                        #134

                        CO2 with MH-Z14
                        0_1455112054292_chart(7).png
                        NO2 MICS-6814
                        0_1455112065552_chart(8).png
                        HCHO sensor
                        0_1455112071878_chart(9).png

                        z-wave - Vera -&gt; Domoticz
                        rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                        mysensors -&gt; mysensors-gw -&gt; Domoticz

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          bhavika
                          wrote on last edited by bhavika
                          #135

                          In MQ135 sensor's datasheet , which line on the curve is used to find out the concentration of benzene?

                          epierreE 1 Reply Last reply
                          0
                          • B bhavika

                            In MQ135 sensor's datasheet , which line on the curve is used to find out the concentration of benzene?

                            epierreE Offline
                            epierreE Offline
                            epierre
                            Hero Member
                            wrote on last edited by
                            #136

                            @bhavika said:

                            In MQ135 sensor's datasheet , which line on the curve is used to find out the concentration of benzene?

                            MQ135 is sensitive to particle size, benzene is one of these. I rememer someone who used the chinese datasheet and found a chinese to translate it.

                            z-wave - Vera -&gt; Domoticz
                            rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                            mysensors -&gt; mysensors-gw -&gt; Domoticz

                            1 Reply Last reply
                            0
                            • supersjimmieS Offline
                              supersjimmieS Offline
                              supersjimmie
                              wrote on last edited by supersjimmie
                              #137

                              @epierre I am testing a stripped-down version of your code from your AirQuality-MQ135.ino. I stripped it to make it run just stand-alone.
                              What I don't understand is how to do the calibration. When I run it in outside environment (with 10k resistor), I get these values:

                              valr 223
                              Vrl / Rs / ratio:13387 / 20875.00 / 0.00
                              

                              What would be the next step for calibration?

                              epierreE 1 Reply Last reply
                              0
                              • supersjimmieS supersjimmie

                                @epierre I am testing a stripped-down version of your code from your AirQuality-MQ135.ino. I stripped it to make it run just stand-alone.
                                What I don't understand is how to do the calibration. When I run it in outside environment (with 10k resistor), I get these values:

                                valr 223
                                Vrl / Rs / ratio:13387 / 20875.00 / 0.00
                                

                                What would be the next step for calibration?

                                epierreE Offline
                                epierreE Offline
                                epierre
                                Hero Member
                                wrote on last edited by
                                #138

                                @supersjimmie replace MQ135_DEFAULTRO by your value 20875 in the sketch

                                z-wave - Vera -&gt; Domoticz
                                rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                                mysensors -&gt; mysensors-gw -&gt; Domoticz

                                supersjimmieS 1 Reply Last reply
                                0
                                • epierreE epierre

                                  @supersjimmie replace MQ135_DEFAULTRO by your value 20875 in the sketch

                                  supersjimmieS Offline
                                  supersjimmieS Offline
                                  supersjimmie
                                  wrote on last edited by supersjimmie
                                  #139

                                  @epierre Thanks, I thought it would be something like that, but that didn't work.
                                  I then got

                                  valr 242
                                  Vrl / Rs / ratio:5464 / 8520.00 / 0.00
                                  

                                  Nothing like around 400ppm.

                                  1 Reply Last reply
                                  0
                                  • epierreE Offline
                                    epierreE Offline
                                    epierre
                                    Hero Member
                                    wrote on last edited by
                                    #140

                                    yes for the code must be updated, the value is the CO2 (or something else) detected above the 399 in atmosphere

                                      gw.send(msg.set(MQ135_DEFAULTPPM+(int)ceil(valAIQ)));
                                    

                                    z-wave - Vera -&gt; Domoticz
                                    rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                                    mysensors -&gt; mysensors-gw -&gt; Domoticz

                                    1 Reply Last reply
                                    0
                                    • supersjimmieS Offline
                                      supersjimmieS Offline
                                      supersjimmie
                                      wrote on last edited by
                                      #141

                                      Thanks, but when calibrating something strange happens when I put the module outside:

                                      valr 270
                                      Vrl   / Rs       / ratio  / ppm
                                      61355 / 95673.00 / 0.00 / 399.00
                                      valr 265
                                      Vrl   / Rs       / ratio  / ppm
                                      62928 / 98126.00 / 0.00 / 399.00
                                      valr 260
                                      Vrl   / Rs       / ratio  / ppm
                                      64561 / 100673.00 / 0.00 / 399.00
                                      valr 256
                                      Vrl   / Rs       / ratio  / ppm
                                      378 / 589.00 / 0.00 / 399.00
                                      valr 252
                                      Vrl   / Rs       / ratio  / ppm
                                      1773 / 2764.00 / 0.00 / 399.00
                                      

                                      As you can see, the valr decreases slowly, but suddenly Vlr and Rs jump over.
                                      Vlr is the value of 'val', which is: uint16_t val = ((float)22000*(1023-valr)/valr);
                                      uint16_t is 16bit, so max 65535. It looks like my environment needs more than that?
                                      (in fact, your code defines the defaultro as 68550, which is also too much for a uint16?)

                                      epierreE 1 Reply Last reply
                                      0
                                      • supersjimmieS supersjimmie

                                        Thanks, but when calibrating something strange happens when I put the module outside:

                                        valr 270
                                        Vrl   / Rs       / ratio  / ppm
                                        61355 / 95673.00 / 0.00 / 399.00
                                        valr 265
                                        Vrl   / Rs       / ratio  / ppm
                                        62928 / 98126.00 / 0.00 / 399.00
                                        valr 260
                                        Vrl   / Rs       / ratio  / ppm
                                        64561 / 100673.00 / 0.00 / 399.00
                                        valr 256
                                        Vrl   / Rs       / ratio  / ppm
                                        378 / 589.00 / 0.00 / 399.00
                                        valr 252
                                        Vrl   / Rs       / ratio  / ppm
                                        1773 / 2764.00 / 0.00 / 399.00
                                        

                                        As you can see, the valr decreases slowly, but suddenly Vlr and Rs jump over.
                                        Vlr is the value of 'val', which is: uint16_t val = ((float)22000*(1023-valr)/valr);
                                        uint16_t is 16bit, so max 65535. It looks like my environment needs more than that?
                                        (in fact, your code defines the defaultro as 68550, which is also too much for a uint16?)

                                        epierreE Offline
                                        epierreE Offline
                                        epierre
                                        Hero Member
                                        wrote on last edited by
                                        #142

                                        @supersjimmie said:

                                        Vlr is the value of 'val', which is: uint16_t val = ((float)22000*(1023-valr)/valr);

                                        yes and this is why I did rewrite it to https://github.com/empierre/arduino/blob/master/AirQuality-Multiple_Gas_Sensor1_4.ino but did not updated this one...

                                        z-wave - Vera -&gt; Domoticz
                                        rfx - Domoticz &lt;- MyDomoAtHome &lt;- Imperihome
                                        mysensors -&gt; mysensors-gw -&gt; Domoticz

                                        supersjimmieS 1 Reply Last reply
                                        0
                                        • epierreE epierre

                                          @supersjimmie said:

                                          Vlr is the value of 'val', which is: uint16_t val = ((float)22000*(1023-valr)/valr);

                                          yes and this is why I did rewrite it to https://github.com/empierre/arduino/blob/master/AirQuality-Multiple_Gas_Sensor1_4.ino but did not updated this one...

                                          supersjimmieS Offline
                                          supersjimmieS Offline
                                          supersjimmie
                                          wrote on last edited by supersjimmie
                                          #143

                                          @epierre I striped-down that AirQuality-Multiple_Gas_Sensor1_4.ino to use only MQ135.
                                          When used inside, the analogRead is 473, so a reasonble value.
                                          But the MQCalibration function returns 0. Which means the MQResistanceCalculation also returns 0.

                                          MQResistenceCalculation only does one calc:
                                          return (long)((long)(1024 * 1000 * (long)rl_value)/raw_adc-(long)rl_value);
                                          rl_value = float RL4 = 0.990
                                          raw_adc = 473 (measured as said above)
                                          (1024 * 1000 * 0.990) / 473 - 0.990 = 2142.266
                                          I checked that raw_adc is filled with the correct value (to be sure it is not lost somewhere).

                                          What looks to fix this, I changed everything to float . So:
                                          return (float)((float)(1024 .* 1000. * (float)rl_value)/raw_adc-(float)rl_value);
                                          Which can be simplyfied as:
                                          return ((1024 * 1000*rl_value)/raw_adc-rl_value);
                                          I went to float, because the function is created as float MQResistenceCalculation.

                                          This now gives some ppm values that are within a reasonable range (about 2000 here).

                                          Now I have to figure out how to do calibration on this method again...

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          24

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular