Measure the CO2 with CozIR-LP sensor and ESP32
- April 17 2020
- ESP32, ESP8266, NodeMCU, Wemos ...
- 16208 Reads
- 0 Comments
Nowadays we can develop a device which will measure all parameters of air - temperature, humidity and also we can buy CO2 sensor and measure the quality of air.
The value of CO2 sensor is really important for us, because the increased concentration of CO2 can cause fatigue, drowsiness and higher concentration can endanger your health.
I used CozIR-LP sensor and the data is sending to tmep.eu where is the vizualition of data.
I got the CO2 sensor CozIR-LP (LP as low-profile) by GSS (Gas Sensing Solutions) before a few months.
We can split the sensor to two parts - the sensor and board with STM32 microcontroller.
The micrcontroller is responsible for data processing, data filtering and communication with host device through UART bus.
As I mentioned, the communication of host device with sensor is made by UART commands. Thank to commands, you can set the filtration, proceed the calibration, read the value etc. More info you can find in this GSS Sensor User Guide, here.
The range of sensor is following
0-2000 ppm
0-5000 ppm
0-1%
The power consumption in run mode is 3mW - what is really low.
I used this sensor with my board ESP32 MiniKit LP (in czech language), where the power consumption is lower than 5uA.
The firmware for ESP32 is written in Wiring (Arduino IDE). I wanted to write my own control library, but I found this Cozir CO2 Sensor Arduino Library .
The programmer used the Software UART/Serial port, but ESP32 contains more than one hardware UART/Serial ports. So I decided to use this library, but I modified it for Hardware UART/Serial port.
So, I used Serial2 (RX pin - GPIO16; Tx pin - GPIO17).
The modified library with using of hardware port is available in this link.
The using of the library is really easy
Defined the hardware UART port
COZIR czr(Serial2);
Set the communication mode - Polling - sending of value based on request, Streaming - the values are sending twice per second [default settings].
czr.SetOperatingMode(CZR_POLLING);
and read the data
int c = czr.CO2();
My firmware is sending the data to TMEP.EU (for czech version I'm using TMEP.CZ).
The example code for ESP32 and CozIR-LP sensor you can find here.
You need to specify four parts in the firmware:
/* Wi-Fi settings */
const char* ssid = "XXXX";
const char* password = "XXXX";
/* TMEP.eu(cz) hostname */
const char* host = "XXXX.tmep.eu";
and fill the GUID on the row 80 (the same of sensor name in tmep.eu)
url += "?CO2=";
The chart of CO2 concentration may look like this.
And what is the power consumption of device?
Running mode
MAX: 145mA
AVERAGE: 63mA
Sleep mode
AVERAGE: 900uA
MIN: 65uA
MAX: 5960uA
AVERAGE without CozIR-LP: 4.99uA
Update:
The CO2 sensor can be calibrated by "fresh air". It means, the reference value is set to 400ppm.
So, if you get the value lower than 400ppm, it is nonsense value and the sensor has to be re-calibrated again.
If you want to calibrate the CO2 sensor, you have go to natura because outside of your home is the concentration of CO2 around 400pm.
My firmware for ESP32 MiniKit LP contains the calibration by "fresh air".
After the power up, the LED is on for 0.5s, during this time, the user has to press the button which is connected to IO0 and leaves it after the LED is off.
When the LED is off and button was pressed, the ESP32 measures 10 samples.
The values from sample 7 - 9 are averaged and compared with sample 10.
If the deviation is +-10ppm from average value, the calibration is correct.
The user recognizes the correct calibration in Serial terminal (9600Bd/8N1/no parity) and also by LED
Short LED on (200ms) - the deviation is bigger than +-10ppm, the user should repeat the calibration
Long LED on (1000ms) - correctly calibrated