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. Development
  3. MH-Z19 with Arduino R3 0 outputValue

MH-Z19 with Arduino R3 0 outputValue

Scheduled Pinned Locked Moved Development
5 Posts 2 Posters 2.0k Views 2 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.
  • D Offline
    D Offline
    douma rahma
    wrote on last edited by douma rahma
    #1

    Hi,
    I am using this code to get C02 value. But always I get this result (CRC 0/0) even after waiting more than 3 min for the healing process.

    #include <SoftwareSerial.h>;
    
    SoftwareSerial mySerial(A0, A1); // A0 - к TX сенсора, A1 - к RX
    
    byte cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79}; 
    unsigned char response[9];
    
    void setup() {
      Serial.begin(9600);
      mySerial.begin(9600);
    }
    
    void loop() 
    {
      mySerial.write(cmd, 9);
      memset(response, 0, 9);
      mySerial.readBytes(response, 9);
      int i;
      byte crc = 0;
      for (i = 1; i < 8; i++) crc+=response[i];
      crc = 255 - crc;
      crc++;
    
      if ( !(response[0] == 0xFF && response[1] == 0x86 && response[8] == crc) ) {
        Serial.println("CRC error: " + String(crc) + " / "+ String(response[8]));
      } else {
        unsigned int responseHigh = (unsigned int) response[2];
        unsigned int responseLow = (unsigned int) response[3];
        unsigned int ppm = (256*responseHigh) + responseLow;
        Serial.println(ppm);
      }
      delay(10000);
    }
    

    I used the sensor directly without any calibration. Another note, why I can only use 3.3V, the 5v make my Arduino card shutdown

    E 1 Reply Last reply
    0
    • D douma rahma

      Hi,
      I am using this code to get C02 value. But always I get this result (CRC 0/0) even after waiting more than 3 min for the healing process.

      #include <SoftwareSerial.h>;
      
      SoftwareSerial mySerial(A0, A1); // A0 - к TX сенсора, A1 - к RX
      
      byte cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79}; 
      unsigned char response[9];
      
      void setup() {
        Serial.begin(9600);
        mySerial.begin(9600);
      }
      
      void loop() 
      {
        mySerial.write(cmd, 9);
        memset(response, 0, 9);
        mySerial.readBytes(response, 9);
        int i;
        byte crc = 0;
        for (i = 1; i < 8; i++) crc+=response[i];
        crc = 255 - crc;
        crc++;
      
        if ( !(response[0] == 0xFF && response[1] == 0x86 && response[8] == crc) ) {
          Serial.println("CRC error: " + String(crc) + " / "+ String(response[8]));
        } else {
          unsigned int responseHigh = (unsigned int) response[2];
          unsigned int responseLow = (unsigned int) response[3];
          unsigned int ppm = (256*responseHigh) + responseLow;
          Serial.println(ppm);
        }
        delay(10000);
      }
      

      I used the sensor directly without any calibration. Another note, why I can only use 3.3V, the 5v make my Arduino card shutdown

      E Offline
      E Offline
      Ed1500
      wrote on last edited by Ed1500
      #2

      @douma-rahma
      I am using a simpeler code:
      Your calculation seems a bit complex.
      I do it as follows:
      The CO2 concentration = 2000 x (TH-2ms)/(TH+TL-4ms)

      As the total cycle is always 1004 ms, only need to read TH and can simplify the formula to Cppm=2x(TH-2ms).

      {
      int ppm = pulseIn(CO2Pin, HIGH);
      ppm = (2 * (ppm - 2));
      return ppm;
      }

      There might be many reasons why you want to do it by reading the registers, but at least could use the code above to see if your sensor is OK.
      Are you giving it enough power (minimally 150mA)

      D 2 Replies Last reply
      0
      • E Ed1500

        @douma-rahma
        I am using a simpeler code:
        Your calculation seems a bit complex.
        I do it as follows:
        The CO2 concentration = 2000 x (TH-2ms)/(TH+TL-4ms)

        As the total cycle is always 1004 ms, only need to read TH and can simplify the formula to Cppm=2x(TH-2ms).

        {
        int ppm = pulseIn(CO2Pin, HIGH);
        ppm = (2 * (ppm - 2));
        return ppm;
        }

        There might be many reasons why you want to do it by reading the registers, but at least could use the code above to see if your sensor is OK.
        Are you giving it enough power (minimally 150mA)

        D Offline
        D Offline
        douma rahma
        wrote on last edited by
        #3

        @Ed1500 Thank you for your response I will try it. Are you using PWM or not?

        E 1 Reply Last reply
        0
        • E Ed1500

          @douma-rahma
          I am using a simpeler code:
          Your calculation seems a bit complex.
          I do it as follows:
          The CO2 concentration = 2000 x (TH-2ms)/(TH+TL-4ms)

          As the total cycle is always 1004 ms, only need to read TH and can simplify the formula to Cppm=2x(TH-2ms).

          {
          int ppm = pulseIn(CO2Pin, HIGH);
          ppm = (2 * (ppm - 2));
          return ppm;
          }

          There might be many reasons why you want to do it by reading the registers, but at least could use the code above to see if your sensor is OK.
          Are you giving it enough power (minimally 150mA)

          D Offline
          D Offline
          douma rahma
          wrote on last edited by
          #4

          @Ed1500 I am connecting the Arduino via USB port

          1 Reply Last reply
          0
          • D douma rahma

            @Ed1500 Thank you for your response I will try it. Are you using PWM or not?

            E Offline
            E Offline
            Ed1500
            wrote on last edited by Ed1500
            #5

            @douma-rahma yes, I am using determining the Pulsewidth.
            can use TTLUART (like you) and analog I think but I found measuring pulsewidth easiest

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


            22

            Online

            11.7k

            Users

            11.2k

            Topics

            113.1k

            Posts


            Copyright 2025 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