tobiasschuerg/MH-Z-CO2-Sensors

adjust measurement range (5000 ppm or 2000 ppm)

PaulMerk opened this issue · 1 comments

I would like to adjust the measurement range from 5000 to 2000.
quote:According to the MH-Z19B datasheet, you can configure the measurement range by putting the desired range in byte 3 and 4. However, unlike what the MH-Z19B datasheet says, you can set the range using the following command (in this case 0x07d0 = 2000 ppm in byte 6 and 7):
0xFF 0x01 0x99 0x00 0x00 0x00 0x07 0xD0 0x8F
^-range-^
unquote

How would a sketch look like to send this command to the MH-Z19B ?


#include <SoftwareSerial.h>
#include <MHZ.h>
// pin for pwm reading
#define CO2_IN 10
// pin for uart reading
#define MH_Z19_RX D7  // D7 D4
#define MH_Z19_TX D6  // D6 D0
MHZ co2(MH_Z19_RX, MH_Z19_TX, CO2_IN, MHZ19B);
void setup() {
  Serial.begin(9600);
  pinMode(CO2_IN, INPUT);
  delay(100);
  Serial.println("MHZ 19B");
  // enable debug to get addition information
  // co2.setDebug(true);
  if (co2.isPreHeating()) {
    Serial.print("Preheating");
    while (co2.isPreHeating()) {
      Serial.print(".");
      delay(5000);
    }
    Serial.println();
  }
}

void loop() {
???
0xFF 0x01 0x99 0x00 0x00 0x00 0x07 0xD0 0x8F
???
}

You need to create a byte array with the command that you want to send and then pass it over serial.
Something like:

byte command[9] = {0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x8F};
serial->write(command, 9);

Like in https://github.com/tobiasschuerg/MH-Z-CO2-Sensors/blob/master/MHZ.cpp#L116
Hope that helps.

See also the official documentation:
https://www.arduino.cc/reference/en/language/functions/communication/serial/write/