Thursday 13 August 2020

A CO2 Sensor for ESPHome

With so many people spending so much time indoors lately, Greg from Greg’s Tinker Town wanted to develop a board that could interface an ESP32 to an MH-Z19B CO2 sensor – and so that’s exactly what he did!

The MH-Z19B is a pretty neat sensor. It uses non-dispersive infrared to detect the concentration of CO2 in the air. This makes it pretty immune to the percentage of oxygen in the air, and with no moving parts or chemical sensor elements it should have a fairly long lifespan. It can detect concentrations up to 5000 ppm, at which point most humans are unable to focus well, complain of “stuffy, stale air” and may also start to get sleepy and slightly nauseous – ie, get the heck out of there! This sensor resolution is good enough to tell you the general quality of air on a day to day basis but a dedicated CO/CO2 detector should still be installed if you need a calibrated alarm.

The sensor does have calibration routines, although you do need some equipment to calibrate it properly. You need to be able to produce an environment with 400ppm CO2 for 20 minutes. However, it does also have an automatic baseline calibration routine that will automatically calibrate itself over time, which is more than good enough for readings in most environments.

Interfacing with it is also interesting. You can either have it send you a PWM signal, where the duty cycle relates directly to the CO2 concentration, or you can have it send you data over a UART at 9600 baud. Either of these options is a piece of cake for the ESP32 module.

The firmware is based on the ESPHome project, which helps create firmware specifically for integration with home assistants and cloud data collection. This is an excellent choice, as the end user can easily modify the firmware to add more sensors or other functionality, while also having a working setup out of the box. Note that the board does not include the MH-Z19B sensor, but you can pick them up for under $20 online. Compared to the cheap MQ type sensors, you can expect much more accurate and stable measurements, especially over a long timeframe.

This board is a great way to get accurate and easy-to-use CO2 readings for your home or office. The same store also sells an easy to use ESP32 Flasher which can be used to program any ESP32 module. As a fellow Canadian, I also like to support Tindie stores from Canadian hackers, and Greg’s store has a bunch of other cool stuff to check out!



source https://blog.tindie.com/2020/08/a-co2-sensor-for-esphome/

No comments:

Post a Comment