Grove - CO2 Sensor

Hello,

I have bought this MH-Z16 CO2 sensor and now I have problems to receive data from the sensor, I have connected this sensor with Arduino MEGA (I used Grove - Mega Shield v1.2).

I have run the code from https://wiki.seeedstudio.com/Grove-CO2_Sensor/ and get the output but all the 9 values get the same output at a time and they don’t change. After refreshing the serial monitor output I get the another result but all are same.

I have attached the output page below.

Please help me out from this problem as soon as possible.

do you calibrate the sensor according the wiki documents ?

Yes, I did. Maybe sensor is defective? I tested other code and sensor does not respond… Would you have another code (different from wiki code) to test the sensor?

Is the connection correct? You can take a picture. I’ll check it for you.

Similar problem here.
Connected the Sensor to the D2 Connector (D2/D3/VCC7GND) of an Arduino Grove Shield on a Seeeduino 4.2 and it only outputs noise, no valid readings.

My Connection looks like this. Sorry for seizing this thread but it may be helpful for all…

Its now working. This is the code I used:
#include <SoftwareSerial.h>

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

int gas, temp;

SoftwareSerial sensor(pinTx, pinRx);

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

const unsigned char cmd_calibrate[] = {
0xff, 0x87, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf2
};

bool sendCmdGetDta(){
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;
byte dta[20];

while (sensor.available()){
dta[len++] = sensor.read();
}

if ((9 == len) && (0xff == dta[0]) && (0x86 == dta[1])){ // data ok
gas = 256 * (int)dta[2] + (int)dta[3];
temp = (int)dta[4] - 40;
return 1;
}
return 0;
}

void setup(){
Serial.begin(115200);
sensor.begin(9600);
}

void loop(){
if (sendCmdGetDta()){ // get data ok
Serial.print("gas_strength = ");
Serial.println(gas);
Serial.print("temperature = ");
Serial.println(temp);

// 350~450ppm: General outdoor environment
// 350~1000ppm:The air is fresh and breathing smooth
// 1000~2000ppm:The air was stagnant and feel asleep
// 5000ppm:Permissible exposure limit for an 8h work day
}
else{
Serial.println(“get data error”);
}
delay(1000);
}

void serialEvent(){

}