Edge Collective

DIY CO2 Monitoring


14 OCT 2020

Table of contents

Feather Hookup Guide for K30


Below is a development notebook for constructing a DIY CO2 monitor.

Click here to jump to the latest remote CO2 node + gateway setup.


Online description of K30

K30 Datasheet

Needs 5V power minimum (actually, looks like it's best run at 6-9V); meanwhile, Logic levels for the UART are at 3.3V.

Useful info on logic levels / etc from the datasheet:

Table 1 from the K30 datasheet.

Meanwhile, though -- good advice on connecting to signals that run at higher voltage from JeeLab, here. Punchline -- can add a 1K resistor in series with signal as protection.

Figure 2 from the K30 datasheet.

Datasheet says: should avoid connecting analog and digital ground pins externally in order to avoid ground loops

Analog outputs.

Connecting to an Arduino

Via I2C

Connecting a K30 to an Arduino via I2C

This suggests using 6 to 9V input. (Might be good to upgrade the spec on the MCP1702 voltage reg so we can take > 6V input on the Mothbot). Needs to be able to provide 500mA. So: direct from battery power is likely best.

Notes on using a Feather

Schematic of the Feather M0 Lora.

Datasheet for the AP2112-3.3 voltage regulator used on the feather is here.

From the AP2112K datasheet -- 6V max allowed on Feather:

UART connection.


Note: Logic levels for the UART are at 3.3V.

Connecting a K30 to an Arduino via UART

UART connection.
First readings.
Blowing on the sensor and then letting it recover.

Edge Collective copy of the library for UART connection is here (replica of that provided by CO2 Monitor here).

SSD1306 Display

Guide here for hookup to Arduino UNO.

UART + SSD1306 Display

Example code here.

Remote LoRa CO2 Node and Heltec Gateway sending to FarmOS

Using a Mothbot to connect to the K30 sensor over UART and send via LoRa to a Heltec Wifi-LoRa gateway, posting to FarmOS.

Code for remote and gateway is here.

Mothbot remote node connected to K30 CO2 sensor.
Closeup of Mothbot.
Closeup of K30 CO2 sensor.
Heltec Wifi-LoRa gateway
Graphing on FarmOS


Would be nice to develop useful ways of connecting to some standard hardware (e.g. Feathers, etc).

CO2 and Greenhouses

Article on measuring CO2 in greenhouses:

Until recently, the vast majority of growers in the U.S. did not measure CO2 or use it to enrich their greenhouses. However, during the winter, CO2 levels can quickly become limiting in unventilated greenhouses full of plants on cold and sunny days. Over the past 10 years, we have also seen greenhouse growers seal up their greenhouses in an effort to control their heating bills during the winter. Other growers, especially in northern latitudes, have invested in supplemental lighting because of the numerous benefits, from improved quality and yields to reduced production time. An apparent result of tightly sealing the greenhouse is increased humidity and condensation. A not-so-apparent result of reducing air infiltration is a reduction of CO2 levels within the greenhouse below ambient levels found outdoors.

Ongoing work / research

Oct 9 2020:

Maybe a good configuraiton is to have the sensor powered via a 7.4V rechargeable lith-ion, while the micro attached has its separate battery voltage?

oct 13 2020:

Recreating the prototype but using a Feather M0 instead ...

now we want to use Hardware Serial instead of Software Serial ...

We noticed a Twitter thread by Linsey Marr on Oct 8 2020 that references using a CO2 monitor to assess activity in a space re: COVID-19; they use the HOBO CO2 monitor pictured in Fig C below.

Fig C. HOBO CO2 Logger used to assess activity level / air turnover in a college gym.

Note: some power options (if plugging into the wall): use a 9V power wall wart, and drop down voltage to 5V; or use a 5V wall wart (more commong), and boost up to 9V.

If the latter, probably need to check on current (mA) requirements of the K30.

Offhand, seems like drop down is easier; boosting to 6V / 9V is a bit odd.

Feather Hookup Guide for K30

Fig A2. Feather M0 connected to a K30 sensor.

Feather firmware is here.

Wiring for test:

Fig A. UART connection on the K30. When connecting to the Feather, connect TXD (K30) to RX0 (Feather) and RXD (K30) to TX1 (Feather).
Fig B. Data from Feather, plotted in Arduino plotter utility. Data shows breathing on sensor at a particular time and and watching decay. Time interval unit is 2 seconds.

UPDATE: looks like the K30 can be powered by up to 14V. So a 12V boost, or power supply, could be an option.

Started by closing door, sitting next to sensor. At 150 time mark, opened door and left room. Then At 250 time mark, reentered room and closed door. At 280 time mark, started a conversation.

Cf. 'room_test.png'.

'room_test_later.png' -- had a phone call

'room_test_later_2.png' -- left room for a bit with door open, then emilie came back and worked with the door open.

Reference for typical / expected CO2 values

Nice discussion here, thanks to Laura P.

Other CO2 Sensors


Specifically mentions NDIR.

For sale on Banggood. Another option


Mentions infrared. This is the one that Craig used / that I have in my possession now.

For sale on Banggood for $20.

Goal as of 13 OCT 2020: get this up and running in parallel to the K30 and see how they compare with the 'ambient' test.

Nice article on testing out the Z19 on a Raspberry Pi.

Update 15 OCT 2020: Just found a fairly official-looking Arduino library for the MH-Z19 here by WifWaf.

In that repo they have some nice notes about calibration. The Z19 allows us to turn autocalibration off (which seems useful -- otherwise it is using the lowest reading in a 24 hour period as '400 ppm'). Would be good to experiment with this.

Also, here's another library for the MH-19 -- looks a bit older. Going to try the WifWaf one above for now.

Note that the WifWaf github MH-Z19 lib is already in the Arduino online Lib repo, can just install via Library Manager in IDE.

Update 15 OCT 2020: was able to get the WifWaf lib running on the MothbotV3. Radiohead + the library ends up generating a 'low memory' warning. This is fine; we'll likely end up using the Feather; also, we can pare down the full library to just generate raw values, likely.

Programming the Heltec Gateway

Guide to using ESP32 in Arduino IDE

Another guide from Sparkfun

Add this to Boards Manager:


Select 'Heltec Wifi Lora (v2)'

Programming with Feather

Add this to Boards Manager:


CO2 with K30 to FarmOS

Oct 14 2020

Posting CO2 PPM data from a K30 to FarmOS, measuring overnight from 14 OCT to 15 OCT 2020.

Turning off autocalibration in K30

This article mentions a technique, using their library.

CO2 with custom server

(TODO: set up using chappy-server as a model?)

Ongoing Work Log

As Of 15 OCT 2020 10:42 AM -- K30 is autocalibrating, Z19 is not.

Ah -- looks like the K30 also can give temp, and RH! Cf the example here.

How to read the K30 via I2c app note here.

Ahhh here is a library for multiple params by CO2meter for the K30 -- boom.

need to modify their library so that it doesn't rely on SoftwareSerial (necessarily)

-- but first check whether we can even disable autocalibration?

Reading the K30 datasheet

Useful CO2meter guide to K30 ABC here.

i2c communication guide to K series sensors

-- looks like it can be disabled in EEPROM via I2C, at least ...

Nice reference on connecting a Teensy to a K30 here

Reference to a key application note re: K-Series eeprom setup here

-- need to email them, UART command lib is missing ...

15 OCT 14:00 -- Interesting link to the Yoctopuce V2, which uses a 'better sensor' than the K30, they claim ...

The K30-based yoctopuce-c02 is here

More about the yp-co2-v2 is here

Yp-co2 (K30) user's guide

K30 via i2c

this is the serious guide, here

simple i2c example here


The yocto uses the SCD30 -- listed for $54 on digikey

Here's the SCD30 datasheet

Arduino library here

And on github

annnnd the Sparkfun library has a 'disable calibration' settting here

Summary as of 15 OCt 2020 15:00

K30 seems outdated; won't trust it until we figure out how to turn off the autocalibration ... waiting to hear back from CO2 meter

MH-Z19 is also a bit older; can at least control the autocal ...

The calibration assumption with these meters seems to be that they use the lowest ppm value over some period and consider it to be 400 ppm -- assumes that all spaces end up getting 'fresh air' at some point in that period. For the K30, this is et to 7 days. Not sure for the other sensors.

Also: readings for NDIR are temp, humidity, and pressure dependent. My sense is that all the sensors measure these variables and compensate; the SCD30 also allows for feeding it the current ambient pressure and using it for calibration.

My current thought is the SCD30 would be a good one to get, along with an ambient pressure sensor.

OCT 16 2020

Example of an electrochemical CO2 sensor.

Really nice collection of references from co2meter.com

OCT 21 2020

Looks like the SCD30 can run off 3.3V, requiring max current of 80mA -- that's well within range of Feather LDO I believe!

SCD30 datasheet has the following table:

SCD30 handling and assembly guide

Electrical characeristics of SCD30.

Listing for th SCD30 on Amazon, here.

And on Digikey, here.

Note: should likely pair with a precision pressure sensor like the BME280 or better.

OCT 22 2020

CO2Meter note on calibration here

Calibration for the SCD30 sensor document here p. 7 / 10.

Calibration of the SCD30, via this document

Upshot: seems as though with the ABC algorithm, sensor needs to see at least 1 hour of fresh air daily. With the 'manual' mode, can run it for 2 minutes outdoors and press button saying 'calibrate' and set it to '400ppm'.
Seems like this latter mode would work best.

Assembly of SCD30

Assembly of SCD30 PCB, via this doc

OCT 23 2020

SCD30 Field Calibration

Field calibration guide for SCD30

Manual Field Calibration

Effect of 'forced recalibration' (FRC) of SCD30 as described in the SCD30 ield calibration guide
Automatic Field Calibration
Effect of automatic self-calibration (ASC) algorithm used in SCD30 as described in the SCD30 ield calibration guide.

OCT 24 2020

Might consider adding a high-precision pressure sensor to any SCD30 breakout board; the SCD30 can compensate for pressure if sent values directly. E.g. the BMP388 breakout from Adafruit.