How Do You Interface a Gas or CO2 Sensor to a Microcontroller?
Last updated 8 July 2026 · 8 min read
Direct Answer
Gas and CO2 sensing for embedded products uses one of three distinct measurement technologies, and they are not interchangeable: NDIR (non-dispersive infrared) sensors measure absolute CO2 concentration directly by how much infrared light a gas sample absorbs, and are the correct choice whenever an actual parts-per-million CO2 reading is required (HVAC control, occupancy/ventilation monitoring). MOx (metal-oxide semiconductor) sensors measure a change in a heated sensing element's resistance caused by a broad mix of volatile organic compounds and don't measure CO2 directly — they report a relative air-quality index, and firmware maps a modelled 'equivalent CO2' figure from that index rather than a true gas-specific measurement. Electrochemical sensors use a chemical reaction at an electrode to detect a specific target gas (commonly CO, O2, or a toxic gas) and are the correct choice when the requirement is safety-critical detection of one particular gas rather than general air quality. Nearly all integrated parts in each category expose their measurement over I2C, but each technology has its own warm-up time, calibration requirement, and power profile that must be designed around.
Detailed Explanation
"Gas sensor" and "CO2 sensor" are used loosely across consumer and industrial products to describe three genuinely different measurement technologies, each with its own accuracy characteristics, calibration burden, and power profile. Choosing the wrong one for the application — most commonly, using a VOC sensor's estimated CO2 figure where an actual measured CO2 value is required — is a common and avoidable design mistake.
NDIR (Non-Dispersive Infrared) CO2 Sensors
An NDIR sensor shines infrared light through a small gas-sample chamber onto a detector. CO2 absorbs infrared light strongly at a specific wavelength (around 4.26 µm); the detector measures how much light at that wavelength is absorbed, and the sensor's internal signal processing converts that absorption into a CO2 concentration. Because the measurement is based on a specific physical property of the CO2 molecule itself, NDIR is the only one of the three technologies covered here that measures CO2 directly rather than inferring it.
Integrated NDIR modules such as the Sensirion SCD40/SCD41 or Sensair S8 combine the optical bench, detector, and signal processing into a single package that reports a calibrated ppm value directly over I2C (SCD4x) or UART (S8) — no analog front-end design is required, in contrast to older discrete NDIR modules. The main design considerations are optical: the sensor typically requires an open path or vent to ambient air (a fully sealed enclosure prevents the gas sample chamber from equilibrating with the surrounding air), and the automatic self-calibration behaviour covered in the FAQ above needs to be understood for the specific deployment environment.
MOx (Metal-Oxide Semiconductor) VOC/Air-Quality Sensors
A MOx sensor uses a heated metal-oxide sensing element (commonly tin dioxide) whose electrical resistance changes when reducing gases and volatile organic compounds adsorb onto its surface at operating temperature. This makes MOx sensors broadly sensitive to a wide range of VOCs, combustible gases, and general "air freshness" — but not specifically selective to any one gas, and largely insensitive to CO2 itself.
Because MOx sensors don't measure CO2 directly, integrated parts like the Bosch BME680 and Sensirion SGP30/SGP41 report either a relative index (IAQ — Indoor Air Quality index) or a modelled "equivalent CO2" (eCO2) estimate derived from the raw VOC signal by an onboard or vendor-supplied algorithm — see the FAQ above for why this estimate can diverge from true CO2 concentration. MOx sensors also draw meaningfully more power than NDIR or electrochemical alternatives, because the sensing element's heater typically needs tens to over 100 mW continuously (or during each duty-cycled measurement) to reach and hold its operating temperature — a significant factor for battery-powered designs.
Electrochemical Gas Sensors
An electrochemical sensor uses a chemical reaction at a sensing electrode, specific to a target gas, to produce a small current proportional to that gas's concentration. This makes electrochemical sensors highly selective — a CO sensor responds to carbon monoxide specifically, not to a broad mix of VOCs — which is why this technology dominates safety-critical single-gas detection: CO detectors, O2 depletion monitors, and toxic industrial gas detectors (H2S, NH3, Cl2, and others, each requiring its own sensor type).
Electrochemical sensors have two design considerations the other two technologies don't: a finite operating lifetime (commonly one to a few years, driven by consumption of the internal electrolyte and electrodes, so safety-critical products must plan for sensor replacement or an end-of-life self-test) and, on many parts, a small output current requiring a dedicated transimpedance amplifier stage rather than a ready-made digital interface — see transimpedance amplifier design for the same feedback-resistor sizing principle applied to a different sensor type. Some newer electrochemical modules integrate this analog front end and expose a digital (I2C) output directly, following the same integration trend seen in MEMS barometric pressure sensors.
Comparison
| NDIR | MOx | Electrochemical | |
|---|---|---|---|
| Measures | CO2 directly (absolute ppm) | Broad VOC/reducing-gas mix (relative index or modelled estimate) | One specific target gas (absolute concentration) |
| Typical interface | I2C or UART (integrated modules) | I2C (integrated modules) | Analog (raw) or I2C (integrated modules) |
| Warm-up after power-on | Seconds to a few minutes | Tens of seconds, after an hours-to-days initial burn-in | Manufacturer-specified, generally faster than MOx |
| Power draw | Moderate (periodic IR source pulse) | Higher (continuously heated element) | Low (no heater) |
| Operating lifetime | Long, no consumable element | Long, no consumable element | Finite — electrolyte/electrode consumption |
| Best fit | Demand-controlled ventilation, occupancy-based HVAC, true CO2 monitoring | General indoor air-quality trend indication | Safety-critical single-gas detection (CO, O2, toxic gas) |
Practical Examples
A demand-controlled ventilation system that opens a damper when a meeting room's CO2 rises above a set threshold needs an NDIR sensor — an MOx-derived eCO2 estimate is not a defensible basis for a ventilation control loop, since it can diverge from true CO2 concentration depending on what else is in the air. Reading the SCD41 over I2C at a periodic interval (commonly every few seconds to match the sensor's own internal measurement cycle) and comparing against a configured threshold is a straightforward integration.
A consumer indoor air-quality display, by contrast, is a good fit for an MOx-based sensor — the product's goal is a relative "how stuffy is this room" trend indicator, not a certified CO2 measurement, and the lower cost and smaller footprint of an integrated MOx part like the SGP41 typically outweighs the accuracy limitation for that use case.
A portable gas detector for confined-space entry work needs an electrochemical O2 sensor (to detect oxygen depletion) potentially alongside an electrochemical CO or H2S sensor, each independently selected and calibrated for its specific target gas — this class of product typically has regulatory certification requirements (for example, relevant workplace gas-detection standards) that should be confirmed against the specific application and jurisdiction before a sensor and product design are finalised.
Design Considerations
- Provide an air path to the sensor. All three technologies need the gas sample chamber or sensing element to actually exchange air with the environment being measured. A sensor mounted inside a fully sealed enclosure, or behind a dense, unvented mesh, will read whatever gas mixture is trapped inside the enclosure rather than the ambient environment.
- Budget power for the specific technology's duty cycle. An NDIR sensor's periodic infrared source pulse and a MOx sensor's continuously (or near-continuously) heated element are both meaningful current draws in a battery-powered design — check the specific part's datasheet for both active measurement current and any lower-power duty-cycled mode it supports, and plan the measurement interval around the product's battery life target.
- Design in a path to recalibration or replacement. NDIR sensors depend on periodic exposure to a known reference (see the FAQ above); MOx sensors' baseline drifts over the sensor's life and some parts benefit from periodic recalibration against a reference; electrochemical sensors have a hard end-of-life. A product with a multi-year expected lifetime should account for whichever of these applies to the chosen technology, rather than assuming a "set and forget" sensor.
- Don't conflate air-quality index with a gas-specific measurement in product claims or firmware logic. A control loop, alarm threshold, or user-facing claim that assumes a MOx-derived eCO2 or IAQ figure is a true, absolute CO2 or VOC concentration is building on an estimate, not a measurement — state the actual technology and its limitations clearly where the distinction matters to the product's function or claims.
Zeus Design's engineering team selects and integrates gas, air-quality, and environmental sensing — including analog front-end design for sensors without an integrated digital interface — as part of complete product development.
Common Mistakes
- Choosing a MOx/VOC sensor for an application that actually needs measured CO2. As covered above, this is the single most common gas-sensor selection mistake — the eCO2 figure a MOx sensor reports is a modelled estimate, not a direct CO2 measurement, and can diverge from reality in ways that matter for ventilation control or compliance claims.
- Sealing the sensor inside an enclosure with no air path. A gas sensor measures the air immediately around its sensing element — if that air can't exchange with the environment being monitored, the reading reflects a trapped microclimate, not the actual space.
- Reading the sensor before its warm-up period completes. As covered in the FAQ above, all three technologies specify a warm-up time after power-on; a reading taken before that time elapses is unreliable, and for MOx sensors specifically, the very first power-on after installation requires a much longer initial burn-in than every subsequent power-on.
- Ignoring electrochemical sensor end-of-life in a safety-critical product. Unlike NDIR and MOx sensing elements, an electrochemical cell is a consumable with a finite lifetime — a product relying on one for safety-critical gas detection needs a defined replacement interval or an active end-of-life self-test, not an assumption that the sensor will keep working indefinitely.
Frequently Asked Questions
- Can a MOx or VOC sensor give me an accurate CO2 reading?
- No, not a true one. A MOx sensor's heated element responds to the general presence of volatile organic compounds and reducing gases, not specifically to CO2 — CO2 itself is largely invisible to a typical low-cost MOx element. Parts like the Bosch BME680 and Sensirion SGP30 report an 'equivalent CO2' (eCO2) figure that is a modelled estimate derived from the measured VOC level using an algorithm calibrated against typical indoor air behaviour, not a direct gas-specific measurement. In an environment where VOC and CO2 levels don't track together — a room with a strong non-human VOC source (cleaning products, off-gassing furniture) but low occupancy, for example — the eCO2 estimate can diverge significantly from the true CO2 concentration. Any application that needs an actual, defensible CO2 ppm figure (demand-controlled ventilation, an occupancy-based HVAC control loop) should use an NDIR sensor, not a MOx-derived estimate.
- Why does my NDIR CO2 sensor read incorrectly after a few months of use?
- The most common cause is that the sensor's automatic self-calibration (ASC, or automatic baseline correction) algorithm has drifted, or was never given the conditions it needs to work correctly. Most consumer/prosumer NDIR modules assume the sensor is exposed to fresh outdoor-level air (roughly 400–420 ppm CO2) for some minimum period at least once every few days — typically once per calibration cycle, per the specific part's datasheet — and uses the lowest reading seen in that window as its new zero-reference point. A sensor permanently installed in a space that is never ventilated down to outdoor CO2 levels (a sealed enclosure, a continuously occupied room) never sees a valid low point, and the self-calibration algorithm drifts the baseline upward over time, producing readings that appear to creep higher than reality even with no change in actual air quality. Fixes are part-specific: some parts allow disabling ASC and performing a manual forced-recalibration against a known reference gas or verified outdoor exposure instead.
- Do gas sensors need a warm-up period before the first reading is valid?
- Yes, and the required time varies significantly by technology and part. NDIR sensors typically need on the order of tens of seconds to a few minutes after power-up before the first reading stabilises, driven by the infrared source and optical path reaching thermal equilibrium — check the specific datasheet's warm-up specification. MOx sensors have a much longer requirement: the heated sensing element needs a burn-in period that can extend to hours or, for full long-term baseline stability, days after first power-up, and even after that initial burn-in, most parts still specify a shorter warm-up time (commonly tens of seconds) after every subsequent power-on before readings are considered valid. Electrochemical sensors generally stabilise faster than MOx but still specify a manufacturer warm-up time, and unlike the other two technologies, have a finite operating lifetime (commonly one to a few years, driven by the electrolyte and electrode consumption) that firmware and product documentation should account for. Always duty-cycle a gas sensor's power against its specific warm-up requirement — powering down and immediately reading a fresh measurement produces a wrong result for any of these technologies.
References
Related Questions
What Is a Microcontroller (MCU)?
A microcontroller (MCU) combines a CPU, flash, RAM, and peripherals on one chip. Learn how MCUs work and how they differ from microprocessors and FPGAs.
What Is Wi-Fi?
Wi-Fi (IEEE 802.11) provides wireless internet at 2.4 GHz and 5 GHz. Learn how standards, security (WPA2/WPA3), and power modes affect embedded IoT designs.
What Is I2C (Inter-Integrated Circuit)?
I2C is a two-wire serial bus for addressing multiple peripherals over shared SDA/SCL lines. Learn how addressing, speed grades, and pull-up resistors work.
Sensor Signal Conditioning Basics
Covers signal conditioning for sensors: op-amp gain, offset, 4-20mA interface, anti-aliasing filter design, ADC input protection, and two-point calibration.
How Do You Interface a MEMS Barometric Pressure Sensor?
MEMS barometric pressure sensor interfacing: I2C/SPI digital sensors, factory calibration coefficients, temperature compensation, and altitude calculation.
How Does a Magnetic Rotary Position Sensor IC Work?
Magnetic rotary position sensor ICs (AS5600-class) measure absolute shaft angle contactlessly via a rotating magnet. Covers principle, interfaces, and use.