upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Attributes

API for the DFRobot CO2 Sensor. More...

Detailed Description

This sensor returns an an analog voltage that falls as the concentration of CO2 increases. It contains a heater that must be allowed to 'warm' up the sensor before measurements are stable (hours to days is the recommendation). It requires that the MCU be powered from an external power supply (not USB) at 5v, since the heater will consume significant current.

The sensor should be allowed to 'heat' up for some time before beginning use, typically a couple of hours minimum. It also needs fairly precise calibration at 400ppm and 1000ppm to return meaningful results.

The sensor also incorporates a potentiometer that can be adjusted to specific threshold. Once that threshold is reached, an LED on the sensor will light, and the digital pin will be driven high.

// Instantiate an MG811 on analog pin A0, and digital pin D2 with an
// analog reference voltage of MG811_AREF (5.0)
upm::MG811 sensor(0, 2, MG811_AREF);
// Every tenth of a second, sample the sensor and output it's
// detected CO2 concentration in parts per million (ppm)
while (shouldRun) {
cout << "CO2 concentration in PPM: " << sensor.ppm() << endl;

Public Member Functions

 MG811 (int pin, int dpin, float aref=5.0)
 ~MG811 ()
float getReferenceVoltage ()
void setCalibration (float ppm400, float ppm1000)
float volts ()
float ppm ()
bool thresholdReached ()

Protected Attributes

mraa::Aio m_aio
mraa::Gpio m_gpio
float m_zeroPointValue
float m_reactionValue
int m_aRes

Constructor & Destructor Documentation

MG811 ( int  pin,
int  dpin,
float  aref = 5.0 

MG811 constructor

pinAnalog pin to use
dpinDigital pin that indicates threshold
arefAnalog reference voltage; default is 5.0 V

Here is the call graph for this function:

~MG811 ( )

MG811 destructor

Member Function Documentation

float getReferenceVoltage ( )

Return a cumputed reference voltage to be used in calibration.

Computed reference voltage

Here is the call graph for this function:

void setCalibration ( float  ppm400,
float  ppm1000 

Set calibration parameters. You should measure the reference voltage you get when at CO2 concentrations of 400ppm (ambient) and 1000ppm using the getReferenceVoltage() method. Then specify those voltages here for more accurate results.

ppm400The measured reference voltage at 400 ppm
ppm1000The measured reference voltage at 1000 ppm

Here is the caller graph for this function:

float volts ( )

Returns the voltage detected on the analog pin

The detected voltage

Here is the caller graph for this function:

float ppm ( )

Returns the computed CO2 concentration in ppm (Parts Per Million). This method will return 0.0 if the reference voltage is greater than the ppm400 value. Essentially, ppm values below 400 will be reported as 0.

The computed CO2 concentration in ppm

Here is the call graph for this function:

bool thresholdReached ( )

Read the digital pin and return true if the set threshold has been reached or exceeded. This threshold is set by adjusting the potentiometer on the sensor.

true if the threshold has been reached, false otherwise

The documentation for this class was generated from the following files: