MHZ-14A NDIR CO2 Sensor

Hi. I recently purchased MHZ-14A NDIR CO2 Sensor. I try to test it with code and connection from this website http://domoticx.com/arduino-co2-sensor-mh-z14/. However, I only managed to get 0 PPM reading when I try it with UART connection. I’m using Arduino Mega as the microcontroller. Can anyone tell me whether there is anything that I missed out? This is my first time using this sensor.

I try to test it with code and connection from this website http://domoticx.com/arduino-co2-sensor-mh-z14/.

There are several methods on this page and the first one is even faulty. Post a wiring diagram of your setup and the code you’re actually using! Don’t forget the code tags, that’s the </> button in the editor!

Attached pic is the connection that I have use. The following is the coding that I have use.

#include <SoftwareSerial.h>
SoftwareSerial SerialCom (A1,A0);
int myDelay = 2000;
 
byte addArray[] = { 0XFF, 0x86, 0x02, 0x60, 0x47, 0x00, 0x00, 0x00, 0xD1 };
 
char dataValue[9];
String dataString = "";
 
void setup(){
  Serial.begin(9600);
  SerialCom.begin(9600);
  Serial.println("MH-Z14 C02 Sensor Test Code");
  Serial.println("------------------------------------");
}
 
void loop() {
  SerialCom.write(addArray, 9);
  SerialCom.readBytes(dataValue, 9);
  int resHigh = (int) dataValue[2];
  int resLow  = (int) dataValue[3];
  int pulse = (256*resHigh)+resLow;
  dataString = String(pulse);
  Serial.print("PPM: ");
  Serial.println(pulse);
  delay(myDelay);
}

I’m using Arduino Mega as the microcontroller.

The picture doesn’t show a Mega, that looks more like a Nano.

#include <SoftwareSerial.h>
SoftwareSerial SerialCom (A1,A0);

If you use a Mega it’s quite stupid to use that crippled SoftwareSerial if you have 3 spare hardware serial interfaces.

As the sensor is driven by 3.3V I doubt that it accepts a 5V signal on it’s I/O pins (at least the datasheet says maximum 3.3V). So you have to use a level converter between the sensor and the Mega (which is running on 5V). You might destroy the sensor if you connect 5V directly to it’s pins.

According to the specs Vin must have a voltage of 4-6V, so 3V3 is probably not enough voltage.

me ayudas tengo problema con este code mi conexion al inicio del code estan las referencias de conexion

001.txt (6.85 KB)