UPM

The UPM API is a high level sensor library for IoT devices using MRAA. See examples here. Back to index page.
SparkFun sensor images provided under CC BY-NC-SA-3.0.

MG811 Class

Module: mg811

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.
mg811.jpg

Methods

MG811

(
  • pin
  • dpin
  • aref
)
Number

MG811 constructor

Parameters:

  • pin Number

    Analog pin to use

  • dpin Number

    Digital pin that indicates threshold

  • aref Number

    Analog reference voltage; default is 5.0 V

Returns:

Number:

getReferenceVoltage

() Number

Return a cumputed reference voltage to be used in calibration.

Returns:

Number:

Computed reference voltage

setCalibration

(
  • ppm400
  • 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.

Parameters:

  • ppm400 Number

    The measured reference voltage at 400 ppm

  • ppm1000 Number

    The measured reference voltage at 1000 ppm

volts

() Number

Returns the voltage detected on the analog pin

Returns:

Number:

The detected voltage

ppm

() Number

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.

Returns:

Number:

The computed CO2 concentration in ppm

thresholdReached

() Boolean

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.

Returns:

Boolean:

true if the threshold has been reached, false otherwise