Forum >Why does the CO2 results display results in negatives?
General

Why does the CO2 results display results in negatives?

userHead Account cancelled 2015-05-03 22:33:36 5133 Views4 Replies
I'm using the MG811 CO2 sensor and the results keep coming back with negative numbers randomly? Why does this occur? I've reviewed the code but could not figure it out. Also, how important is the threshold?

I am using an Arduino Uno and an MG811 CO2 sensor brought from this site.

Also, Side Note, I'm a newbie, so some or even more explanation may be needed.

Here's the code:

Code: Select all
/************************Hardware Related Macros************************************/
#define MG_PIN (0) //define which analog input channel you are going to use
#define BOOL_PIN (1)
#define DC_GAIN (8.5) //define the DC gain of amplifier


/***********************Software Related Macros************************************/
#define READ_SAMPLE_INTERVAL (50) //define how many samples you are going to take in normal operation
#define READ_SAMPLE_TIMES (5) //define the time interval(in milisecond) between each samples in
//normal operation

/**********************Application Related Macros**********************************/
//These two values differ from sensor to sensor. user should derermine this value.
#define ZERO_POINT_VOLTAGE (0.324) //define the output of the sensor in volts when the concentration of CO2 is 400PPM
#define REACTION_VOLTGAE (0.020) //define the voltage drop of the sensor when move the sensor from air into 1000ppm CO2

/*****************************Globals***********************************************/
float CO2Curve[3] = {2.602,ZERO_POINT_VOLTAGE,(REACTION_VOLTGAE/(2.602-3))};
//two points are taken from the curve.
//with these two points, a line is formed which is
//"approximately equivalent" to the original curve.
//data format:{ x, y, slope}; point1: (lg400, 0.324), point2: (lg4000, 0.280)
//slope = ( reaction voltage ) / (log400 –log1000)


void setup()
{
Serial.begin(9600); //UART setup, baudrate = 9600bps
pinMode(BOOL_PIN, INPUT); //set pin to input
digitalWrite(BOOL_PIN, HIGH); //turn on pullup resistors

Serial.print("MG-811 Demostration\n");
}

void loop()
{
int percentage;
float volts;


volts = MGRead(MG_PIN);
Serial.print( "SEN0159:" );
Serial.print(volts);
Serial.print( "V " );

percentage = MGGetPercentage(volts,CO2Curve);
Serial.print("CO2:");
if (percentage == -1) {
Serial.print( "<400" );
} else {
Serial.print(percentage);
}
Serial.print( "ppm" );
Serial.print( " Time point:" );
Serial.print(millis());
Serial.print("\n");

if (digitalRead(BOOL_PIN) ){
Serial.print( "=====BOOL is HIGH======" );
} else {
Serial.print( "=====BOOL is LOW======" );
}

Serial.print("\n");

delay(200);
}

2016-11-21 22:35:23 Hi sidharth.9677,

Did you try to connect your diagram according to our wiki:make_clickable_callback(MAGIC_URL_FULL, ' ', 'https://www.dfrobot.com/wiki/index.php/CO2_Sensor_SKU:SEN0159', '', ' class="postlink"')
You only need to connect the power pin to the +5V pin, GND-GND, signal pin-ananlog pin, similar with the uno diagram.

Any problem please let me know.
userHeadPic Wendy.Hu
2016-11-19 23:26:25 The sensor out put has +ve, -ve & data pin, how to connect to arduino mega 2560 board userHeadPic sidharth.9677
2016-11-19 23:23:21 Hello Sir, 19th Nov. 2016

I have a +MG811 Co2 sensor from DFROBOT .Can have the circuit diagram to connect it to arduino Mega 2560 R3 board.

regards
Sidharth
Bangalore
userHeadPic sidharth.9677
2015-05-05 21:39:44 Hi RowanRanthod,

This module is not hard to use,please noticed that:

1 Wire connection right.

2 Use external power supply, better using adapter but not battery which cannot offer enough current .
userHeadPic Leff