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)