Measuring high concentrations of CO2

Measuring high concentrations of CO2

The Yocto-CO2-V2 can measure concentrations up to 40000ppm or 4%, but we're sometimes asked if there isn't a model capable of measuring higher concentrations. The answer is no, but on the other hand, it's easy enough to use Yoctopuce modules to interface other CO2 sensors, such as the K33 ICB-F from Senseair, which can measure CO2 concentrations of up to 10%.

The Senseair K33 ICB-F (we've already soldered a connector)
The Senseair K33 ICB-F (we've already soldered a connector)


The sensor takes the form of a 6x5cm green rectangle, with two small tubes for the inlet and outlet of the gas to be measured. In fact, this sensor isn't really optimized for measuring ambient air, since a concentration of 10% CO2 in the air can easily kill you. The K33 can be interfaced via I2C or serial. We chose the latter to interface it with a Yocto-Serial because the I2C version requires CRC computations.

Configuration

Reading the K33 documentation, we determine that its serial interface communicates in MODBUS RTU. The serial port operates at 9600 baud, 8 data bits, no parity bit, one stop bit. The K33 must be supplied with 5 volts, but its communication logic operates on 3.3V. The Yocto-Serial must be configured accordingly.

Configuring the Yocto-Serial
Configuring the Yocto-Serial


Connection

The connection between the K33 and the Yocto-Serial is relatively simple, involving just four wires. Just don't forget to cross the TX/RX wires.

Connection between the K33 and the Yocto-Serial
Connection between the K33 and the Yocto-Serial


As soon as it is powered up, the K33 starts taking measures, approximately once every two seconds.

Programmed reading

To query the sensor, you need to know two parameters:

  • the sensor's MODBUS address
  • the register where the measured value is stored


SenseAir seems to have forgotten to mention the MODBUS address of the K33 sensor, and their examples simply use the broadcast address 254. However, our little ModbusTool application enabled us to determine that our sensor's address is 104 (0x68). As for the measured concentration, the documentation mentions that it's stored in input register 3 (aka 30004), in the form of a 16-bit integer corresponding to the CO2 concentration divided by 10.

The code needed to query the K33 sensor via the Yocto-Serial is therefore relatively trivial. Here's the Python version, the principle is identical for other programming languages:

import os, sys
from yocto_api import *
from yocto_serialport import *

errmsg = YRefParam()
if YAPI.RegisterHub("usb", errmsg) != YAPI.SUCCESS:
   sys.exit("init error" + errmsg.value)

serialPort = YSerialPort.FirstSerialPort()
if serialPort is None:
   sys.exit('No module connected (check cable)')

while serialPort.isOnline():
   data = serialPort.modbusReadInputRegisters(104,3,1)
   print("CO2 = "+str(data[0]*10)+"ppm")
   YAPI.Sleep(2000,errmsg)

YAPI.FreeAPI()



Job-based reading

Rather than writing sensor-specific code, we can use the Yocto-Serial internal job system to automatically poll the sensor. Simply create a periodic job (2000ms) which reads from the sensor's input register 30004 (aka 3), whose MODBUS address is 104 (0x68). Then multiply the result by ten and assign it to GenericSensor1

writeMODBUS "680400030001" expect "680402($measure:WORD).*" compute "$1=$measure*10"



With this job, the Yocto-Serial then behaves like a standard Yoctopuce sensor, with all the advantages that this implies: unique name, data logger, callbacks, and so on. You can download the ready-made job here.

Once the job has run, we can use Yocto-Visualization to visualize our measures. The picture below illustrates a short experiment. We started by blowing into the inlet tube, then took CO2 from a soda bottle and injected it into the sensor using a syringe, which of course sent the sensor to end position. This was an opportunity to note that, although it sells for 10%, this sensor is apparently capable of measuring up to 12% (120,000ppm). Finally, we used the same syringe to ventilate the sensor and lower the CO2 level.

Short experiment
Short experiment



Conclusion

The Yocto-CO2 is limited in terms of measurable concentration, but if required, a Yocto-Serial can be used to interrogate a SenseAir K33 ICB-F sensor, or even a K33 ICB 30% SENSOR sensor, thus measuring CO2 concentrations of up to 10% and 30% respectively. This operation is greatly facilitated by the fact that the Yocto-Serial is capable of handling MODBUS communications on a serial link all by itself.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.