MG811 Carbon Dioxide (CO2) Sensor
This page attempts to document how to best use the MG811 CO2 sensor to detect for CO2, as very little correct information exists on the web. Additionally, most of the documentation is in chinese-english, and is difficult to understand. This page aims to provide you with resources and diagrams that will help you in your project.
Note this information comes from personal experience working with the sensor, and may not be 100% accurate. Additionally, I do not claim to be a MG811 sensor expert.
MG811 Sensor Overview
The MG811 is a relatively inexpensive CO2 sensor, that can be purchased from many sources online. At the time of this writing, the sensor cost around $20, and can be purchased here: Futurlec Sensors
The same company also provides a datasheet for the sensor, which is worth looking at, but not the best datasheet in the world. The link to the datasheet is available here: MG811 CO2 Sensor Datasheet
Futurlec's website provides the following specs:
- High Sensitivity
- Detection Range: 0 - 10,000 ppm CO2
- Response Time: <60s (see the How the Sensor Works section for more info)
- Heater Voltage: 6.0V
- Dimensions: 16mm Diameter, 15mm High excluding pins, Pins - 6mm High
How the Sensor Works
The MG811 CO2 sensor works through an electrochemical reaction that occurs when carbon dioxide passes over the sensor. The exact chemical reaction that occurs is described in the datasheet linked to above, and in fact that part of the datasheet is fairly understandable. From a less technical perspective, when the sensor is first provided power, the sensor begins warming up, to aid in the chemical reaction. This takes roughly 30-60 seconds, after which time the sensor will be noticeably warm to the touch. During this time, the output voltage of the sensor increases until finally leveling off when the sensor is fully "warmed up". Note that this voltage is dependent on the voltage applied across the "heater pins", and thus will decrease as the batteries wear down.
Once the warm-up period has passed, the sensor will then be in a steady state that is ready to detect CO2. As CO2 is applied, the output voltage will decrease abruptly, indicating its presence. Measuring this voltage drop is how you will detect whether carbon dioxide is present or not. Once CO2 is no longer applied to the sensor, its output voltage will gradually increase back to its steady state voltage. Note that this increase is about at the same rate as the warmup time, so it can take around 15-30 seconds for the sensor to indicate normal levels again.
Using the MG811 with an Arduino Micro-controller
I recently used this sensor with an Arduino Micro-controller, and was successfully able to get it to work. There are a few barriers that must be addressed though, which are listed below:
Barriers that must be addressed
Listed here are problems that will likely need to be addressed to use the MG811 CO2 gas sensor with an Arduino (or any micro-controller for that matter).
MG811 sensor output voltage
As shown in the datasheet linked to above (in the chart entitled "Response and Resume Curve"), the sensor output voltage operates in the range of roughly 330 milliVolts (.33 Volts) without CO2 present to roughly 280 milliVolts (.28 Volts) with it present. This means that there is only a difference of about 30mv between when CO2 is present and when it is not. This small difference presents a challenge when reading the value with the Arduino's analogRead() function. Specifically, the analogRead() function is set up to accept voltages between 0 and 5 volts, returning a value between 0 and 1024, which means each value returned by the function corresponds to roughly 4.9 mV. Since the sensor's output range is only 30mV, this means that if you hook the sensor up directly to the arduino, you will only see a a difference of 5 returned by the analogRead() function.
This may or may not be a problem for you, and this will mainly depend on whether or not you want to be able to determine the relative concentration of CO2 in the air. With such a small dynamic range coming from the sensor itself, determining relative concentrations can be tricky (there are solutions though, keep reading).
Op-Amp +/- power supply requirements
To address the issues presented by the MG811's small dynamic output range, one of the easiest solutions is to hook the sensor's output up to an Operational Amplifier or "Op-Amp", or better yet an Instrumentation Amplifier. These circuit elements can do a wide variety of things, however here we would use them to amplify the voltage signal. Op-amps circuits can get quite complicated though, but if you are up for the challenge of designing the circuit yourself, refer to this guide:
The biggest drawback with most Op-Amp circuits is that they require a + and - input voltage. This can be problematic though, as most power sources only supply a + supply voltage. This means that powering Op-Amps from just one power supply (i.e one set of batteries, or the arduino +5 power pin) might not work.
To overcome this, there are 3 main solutions that I would recommend:
- Use two sets of batteries (hooked up opposite ways)
- Develop a circuit that splits a + voltage into an + and - voltage
- Use an Op-Amp that requires only a + voltage (see link below)
For the last option, refer to this guide: