MG811 (CO2) again

I am struggling with the MG811 since a while. As there are different types of breakout boards, I have this one: https://funduinoshop.com/elektronische-module/sensoren/gase/mg811-co2-sensor-modul
The wiring is as follows: The Vcc of the sensorboard is connected to a stabilized 6V supply. The GND lines of Arduino, sensor board and 6V power supply are connected. AO (analog out) of the sensor is connected with A0 of the Arduino (a Mega for experimenting, planned is a Pro mini).
The DO pin is not used. The Arduino gets its power via the USB line.
Sketches used:

/**
    Powered by SmartTech Benin
*/
#include <MG811.h>

MG811 mySensor = MG811(A0); // Analog input A0

float v400 = 4.535;
float v40000 = 3.206;

void setup(){
    Serial.begin(9600);
    Serial.println("MG811 CO2 Sensor");
    
    // Calibration is not done in this examples - use default value
    // mySensor.calibrate() 
    mySensor.begin(v400, v40000);
}


void loop(){
    Serial.print("Raw voltage: ");
    Serial.print(mySensor.raw());
    Serial.print("V, C02 Concetration: ");
    Serial.print(mySensor.read());
    Serial.println(" ppm");
    
    delay(1000); // 1 second
}

Library used is https://github.com/smart-tech-benin/MG811/blob/master/MG811.h
2nd sketch:

#define CO2_PIN A0  // Pin number to which the MG811 CO2 sensor module is connected

void setup() {
  Serial.begin(9600);  // Start serial communication at 9600 bps
}

void loop() {
  int sensorValue = analogRead(CO2_PIN);  // Read analog value from the sensor
  float voltage = sensorValue * 5.0 / 1023.0;  // Convert analog value to voltage (assuming 5V reference voltage)
  float ppm = voltage * 2000.0 - 200.0;  // Convert voltage to CO2 concentration in parts per million (ppm)
  Serial.print("CO2 Concentration (ppm): ");
  Serial.print(ppm);  // Print CO2 concentration to serial monitor
  Serial.print(" analog: ");
  Serial.print(sensorValue);  // Print CO2 concentration to serial monitor
  Serial.print(" Voltage (V): ");
  Serial.println(voltage,4);  // Print CO2 concentration to serial monitor

  delay(1000);  // Wait for 1 second
}

Output of both sketches are nonsense:
The first sketch gives something as
"Raw voltage: 0.00V, C02 Concetration: 2671410944.00 ppm
"

the second one
"CO2 Concentration (ppm): -141.35 analog: 6 Voltage (V): 0.0293
"
The documentation of this breakout board is very poor. Somewhere (don't find it anymore) I read something about a reference voltage, but there is no pin for this.

Does anyone has some experience with this board? I really would like to know what I'm doing wrong. Another sensor with NDIR technology is working quite well, but has some noise in the analog output. I'd like to find out if the output of the MG811 is more stable or noiseless.
Thanks for helping!
-richard

I've never used that sensor, but the product page says the output varies between 0 and 2v, and this formula...

...gives -200 ppm at 0 v and 0 ppm at 0.10 v. Is that right?

Also, the output is probably not ratiometric; if so, your calculated voltage and ppm will vary with fluctuations in your Arduino's power supply voltage (USB in your case). One way to deal with that would be to use the Mega's 2.56v internal reference, which doesn't vary with supply fluctuations but does need to be calibrated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.