Grove - CO2 Sensor

From Wiki
Jump to: navigation, search

Introduction

The Grove - CO2 Sensor module is infrared CO2 sensor high sensitivity and high resolution. Infrared CO2 sensor MH-Z16 Is a general-purpose, small sensors, the use of non-dispersive infrared (NDIR) Present in the principle of the air CO2 Detect, with good selectivity, oxygen- dependent, long life, built-in temperature sensor, temperature compensation, with UART output, easy to use. It can be widely used in HVAC and indoor air quality monitoring, industrial process monitoring and security, agriculture and livestock production process monitoring.


180px-Grove CO2 Sensor.jpg


Specification

Measuring the range of 0-2000 parts per million (PPM) Resolution of 1 PPM 0-2000 parts per million (PPM) Accuracy of 200 PPM A Warm - up time 3 minutes Response Time <90s Operating temperature 0 to 50℃ Operating Humidity 0% ~ 90% RH Storage temperature - 20-60℃ Operating Voltage4.5 V to 6 V DC The Current maximum Current of less than 100 ma, the average Current of less than 50 ma Output mode UART Demonstration

Connect the module with Grove Shield using like following picture and use the program below to gain the voltage. Please note that the best preheat time of the sensor is about 180s. For the detailed information about the sensor, please refer to the datasheet.


600px-5 副本.jpg


  1. include <SoftwareSerial.h>


const int pinRx = 8; const int pinTx = 7;


SoftwareSerial sensor(pinTx,pinRx);


unsigned char flg_get = 0; // if get sensor data


const unsigned char cmd_get_sensor[] = { 0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};


bool sendCmdGetDta(int *gas_strength, int *temperature) {

   for(int i=0; i<sizeof(cmd_get_sensor); i++)
   {
       sensor.write(cmd_get_sensor[i]);
   }
   
   long cnt_timeout = 0;
   while(!sensor.available())              // wait for data
   {
       delay(1);
       cnt_timeout++;
       
       if(cnt_timeout>1000)return 0;       // time out
   }
   
   int len = 0;
   unsigned char dta[20];
   
   while(sensor.available())
   {
       dta[len++] = sensor.read();
   }
   
   if((9 == len) && (0xff == dta[0]) && (0x86 == dta[1]))      // data ok
   {
       *gas_strength = 256*dta[2]+dta[3];
       *temperature = dta[4] - 40;
       
       return 1;
   }
   
   return 0;
  

}

void setup() {

   Serial.begin(115200);
   sensor.begin(9600);

}


void loop() {

// Serial.println("get a 'g', begin to read from sensor!");

       Serial.println("********************************************************");
       Serial.println();
       flg_get = 0;
       int gas, temp;
       
       if(sendCmdGetDta(&gas, &temp))          // get data ok
       {

// Serial.println("get data ok: ");

           Serial.print("gas_strength = ");
           Serial.println(gas);

// Serial.print("\ttemperature = "); // Serial.println(temp);

       }
       else 
       {
           Serial.println("get data error");
       }


   delay(1000);

}


void serialEvent() {

   while (Serial.available()) 
   {
       char c = Serial.read();
       if(c == 'g')flg_get = 1;
       
   }

}


600px-Uart co2.jpg



File:MH-Z16 CO2.pdf

File:MH-Z16 CO2 datasheet EN.pdf