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:

https://dl.dropboxusercontent.com/u/77308503/co22.png

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.](http://www.veetech.org.uk/Prototype_CO2_Monitor.htm)](MG-811 CO2 Gas Sensor Module | Sandbox Electronics)

According to the formula in the datasheet of this sensor the response of the sensor is also dependant on the absolute temperature. As I don’t see a temperature sensor mentioned on this module I don’t think it is correcting for this. And I assume your other CO2 measuring equipment does correct for it. Was there a rising temperature trend in whatever you are calibrating it in?

I have read that what affects the sensor greatly is the humidity not the temperature. In the image, it is shown the measures of an unoccupied room for some days and there is a rising temperature every day at some hours. Either way, that would explain the de calibration for that hours, not the trend growing all the time, wouldn’t it?

You didn’t mention how you powered the module. You said you connected it to 5 volt, GND and the analog input of the arduino. But you didn’t mention the jackplug on it. How is that connected? It is important as it feeds the heating element in the sensor. Please show more detail how it is connected.

I would not be surprised if those daily fluctuations that are visible are because of ambient temperature changes due to the sun heating up the room or something. The multiday trend may just be a longer term heating trend. But I’ll admit, over the course of odd 12 days it does look too linear. If the weather is the cause of this trend I would expect at least a day’s worth of bucking the trend. But that may also depend on your climate.

I’m not familiar enough with this Nernst equation that describes the response to explain this. I’m sure there is someone else more knowledgeable about this. I would start to log the voltages in the circuit over a couple of weeks and see if there is the same trend too. Temperature is often an important factor in these sort of sensors so I would include it in your logging anyway.