Problems measuring CO2

Hi:

Sometime ago I bought a CO2 sensor: the MG811 with an onboard signal conditioning circuit to make it proper for the arduino (link). I didn’t have any issue in the process of wiring it to my arduino (just one wire to the 5v plug, other to the ground and the last one to the analog input), but I am going crazy trying to make it work correctly.

I have followed this guide which basically says that you need the voltage corresponding to the value of 400ppm, and the voltage of 40.000ppm (I have tried this and then with the voltage of 4000ppm). The program used is very simple:

#include <math.h>

int co2 = 9999; // co2 is the co2 concentration. Preset value for code checking

// analog input
int analogPin = A0; // voltage input from sensor

// Setting Sensor Calibration Constants
 float v400ppm = 3.23;   //MUST BE SET ACCORDING TO CALIBRATION
 float v40000ppm = 1.88; //MUST BE SET ACCORDING TO CALIBRATION````````````````````````
 float deltavs = v400ppm - v40000ppm;
 float A = deltavs/(log10(400) - log10(40000));
 float B = log10(400);

void setup()
{
  Serial.begin(9600);

  Serial.println("initialization done.");
  
}
void loop()
{

// Read co2 data from sensor
  
  int data = analogRead(analogPin); //digitise output from c02 sensor
  float voltage = data/204.6;       //convert output to voltage

// Calculate co2 from log10 formula (see sensor datasheet)

  float power = ((voltage - v400ppm)/A) + B;
  float co2ppm = pow(10,power);
  co2 = co2ppm;

  Serial.print ("=====MEASURE======\n");
 
  Serial.print ("CO2:\t");
  Serial.println (co2); 
  Serial.print ("Voltage:\t");
  Serial.println (voltage); 

  delay (5000);

}

Basically it reads the voltage measured with the MG811 and replaces it in a line which slope is defined with the calibration points.

The problem I am having is that it works for some hours and then the values begin to make no sense. I am using paralelly a stable equipment to measure CO2 levels that I know works correctly, and the comparison between the curves is the as follows:

As you see the trend of both curves is the same, but the one connected to the arduino “grows” all the time.

I have also tried to implement some functions, for example, an automatic baseline calibration, which takes the highest voltage value of a day and assumes it is the voltage corresponding to the level of 400ppm, but didn’t get good results.

Has anyone of you tried this kind of sensor? I am running out of ideas and it seems weird to me because I suppose the sensor must work properly (it can’t be so bad you have to re-calibrate it every 10 hours…). It is a bit frustrating because I have used other sensors and haven’t had this problem for so long…

I appreciate any idea or commentary,

thank you all very much,

best regards,

Checho360.

Does the MG811 value ever stabilize or does it just go on rising? The article you quote does say that sensor drift is a problem especially when new -perhaps you should leave it for a few days and see if it settles down?
Alternatively I wonder if there is a dependency on temperature or some other environmental factor that's causing the drift.

rw950431:
Does the MG811 value ever stabilize or does it just go on rising? The article you quote does say that sensor drift is a problem especially when new -perhaps you should leave it for a few days and see if it settles down?
Alternatively I wonder if there is a dependency on temperature or some other environmental factor that's causing the drift.

It doesn't stabilize at anytime, I've been trying this for months, and as you suggest, some days I simply let it be, but I allways get the same problem. Answering the other question, yes, the humidity in the air afects greatly the sensor. Either way I think that is not the problem, because I also know that the other sensor has the same "debility" and doesn't show that kind of values.

Thank you very much for the help.

Anyone?

Are you turning your sensor off each day?
Leave it powered up and then calibrate after a week.
It doesn't look like there is any problem with your
code, it is just the drift of the sensor.
Dwight

No, i didn't turn it off anytime in the whole periods.

Thank you for the help.

The heating element :6 +/-0.1 Volt., 200mA

  • Test it with 6 V DC power supply and monitor its current.
  • Replace with current OP amplifier with better one.
  • Make sure power supply stable and clean

http://www.mouser.com/ds/2/321/CO2SensorDatasheetMG811-17599.pdf

Drop a line to OEM:

Please bring us update.

Just curious, does the heater supply need to
be isolated from the amps supply?
Dwight

dwightthinker:
Just curious, does the heater supply need to
be isolated from the amps supply?
Dwight

Isolated heater supply should not be hurt.