Monday, January 6, 2014

CO2 meter using NDIR infrared MH-Z14 sensor library for AVR ATmega



MH-Z14 NDIR Infrared gas module is a common type, small size sensor, using non-dispersive infrared (NDIR) principle to detect the existence of CO2 in the air, with good selectivity, non-oxygen dependant and long life.


MH-Z14 has a PWM output, with a sensitivity range of 0ppm to 2000ppm CO2, an accurancy of ±200ppm.
The cycle is 1004ms±5%, given the duty cicle Th (pulse high), Tl is 1004-Th, we can convert it to CO2 value using the formula:
CO2ppm = 2000 * (Th - 2ms) /(Th + Tl - 4ms)

This library read PWM output, and convert it to CO2ppm.

This library was developed on Eclipse, built with avr-gcc on Atmega8 @ 8MHz


Code


Notes
  • read risk disclaimer
  • excuse my bad english

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hello Davide, I like ur blog :D, well I have a question for mh z14, how I calibrate this sensor for 0 to 5000 ppm? Thanks for read This :)

    ReplyDelete
    Replies
    1. Hello, and thank you for your feedback. By datasheet this sensor has a resolution ratio of 5ppm between 0̚ and 2000ppm, 10ppm between 2000̚ and 5000ppm, 20ppm between 5000̚ and 10000ppm. If you would like to check the resolution ration, or to improve the calibration, you have to correlate this sensor to a accurate sensor. Basically you get data from your prof sensor against this sensor, then you take out a correlation curve. Once you get this curve, you can corretale any value you get from this sensor the the correlated value, imposing an offset or a gain correlation factor.

      Delete