Measuring CO2 with the MG811 Sensor

Indoor carbon dioxide is one of the clearest signals of how stuffy a room has become, and the MG811 is a common choice for hobbyists who want to track it. If you describe an indoor CO2 monitor to Compoden's AI build assistant, it returns a recommended parts list, wiring, sample code, and a kit shipped to your door, so you can skip the guesswork and start building. This guide explains what the MG811 does and how to read it well.

What the MG811 measures and how it works

The MG811 is an electrochemical carbon dioxide sensor. It produces a small analog voltage that changes as the surrounding CO2 concentration changes. Unlike a simple digital sensor, its output is a slowly varying signal that you read on an analog pin. Because the raw voltage is small and the relationship to concentration is not linear, most modules include an onboard amplifier and a comparator with a potentiometer for a rough threshold output.

The module versus the bare sensor

You will usually buy the MG811 on a breakout board rather than as a bare element. The board typically exposes an analog output pin, a digital threshold pin, power, and ground. The analog pin is the one you want for actual measurement; the digital pin only tells you whether the level has crossed the potentiometer setting. For any project that logs trends, ignore the digital pin and read the analog signal.

Wiring it to a microcontroller

Connect the module's power and ground to your board's supply, then run the analog output to an analog input pin. On an Arduino Uno this is straightforward because its pins read 0 to 5V. On an ESP32 or Raspberry Pi, you must respect the 3.3V analog input range, so check the module's output voltage and add a divider if needed. Keep the wiring short to reduce noise on the small analog signal.

Warm-up, calibration, and stable readings

The MG811 needs time to warm up before its readings settle, so let it run before you trust any numbers. Calibration matters: you establish a reference reading in clean outdoor-equivalent air, then interpret rising voltage as rising CO2. Treat the MG811 as a trend indicator rather than a laboratory instrument. For absolute accuracy you would step up to an NDIR sensor, but for relative changes in a room the MG811 is informative and affordable.

Build it with Compoden's AI

Rather than piecing together a sensor, a board, a display, and the calibration code yourself, describe your goal to Compoden's AI build assistant. Say something like "indoor CO2 monitor for my study that shows a number on a small screen," and it proposes a parts list, wiring diagram, and starter code, then ships the matching kit anywhere in India. You can browse related components at our full catalog while you plan.

Ready to measure the air in your own room? Tell Compoden's AI build assistant what you want to track and let it turn your idea into a buildable kit.

FAQ

Does the MG811 give an exact CO2 number in ppm? Not reliably without careful calibration; it is best used to track relative changes and trends in indoor air.

Can I use the MG811 with an ESP32? Yes, as long as you respect the 3.3V analog input range and scale the output voltage accordingly.

Why does it take a while before readings make sense? Electrochemical sensors need a warm-up period before the output stabilizes, so let it run before recording data.

Back to blog