CO2 sensor

This example shows how to use UART to connect MH-Z19 CO2 sensor to Z-Uno board.
  • Z-Uno board
  • Breadboard
  • Wires
  • MH-Z19 CO2 sensor
        char response[9];
byte cmd[9] = { 0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79 };
int newValue;
int responseHigh;
int responseLow;
int ppm;

ZUNO_SETUP_SLEEPING_MODE(ZUNO_SLEEPING_MODE_ALWAYS_AWAKE);

ZUNO_SETUP_CHANNELS(ZUNO_SENSOR_MULTILEVEL(ZUNO_SENSOR_MULTILEVEL_TYPE_CO2_LEVEL, 0, SENSOR_MULTILEVEL_SIZE_TWO_BYTES, SENSOR_MULTILEVEL_PRECISION_ZERO_DECIMALS, getter));

void setup() {
  Serial1.begin(9600); //connecting to sensor via UART
}

void loop() {
  int i = 0;
  for (i = 0; i < 9; i++) {
    Serial1.write(cmd[i]);
  }

  delay(100);

  i = 0;
  while (Serial1.available()) {
    response[i] = Serial1.read();
    i++;
  }

  responseHigh = (int) response[2]; // returned High level concentration
  responseLow  = (int) response[3]; // returned Low level concentration
  newValue = (256 * responseHigh) + responseLow;
  if ((newValue > (ppm + 100)) || (newValue < (ppm - 100))) {
    ppm = newValue;
    zunoSendReport(1);
  }
  delay(1000);
}

int getter(void) {
  return newValue;
}

Information from datasheet