There are quite a lot of CO2 sensors: MG811(~40$), MH-Z14 WINSEN(~40$), MH-Z19 WINSEN(~30$), K-30(~85$), VERNIER CO2-BTA(~330$). NDIR (nondispersive infrared) CO2 sensor is the most common type of sensor used to measure CO2, which has good precision and low power consumption. Prices are very various. MH-Z19 sensor has good characteristics and great price, so I decided to buy this one.
有相當多的CO2傳感器:MG811(約40 $),MH-Z14 WINSEN(約40 $),MH-Z19 WINSEN(約30 $),K-30(約85 $),VERNIER CO2-BTA 〜330 $)。 NDIR(非分散紅外)CO 2傳感器是用於測量CO 2的最常見類型的傳感器,其具有良好的精度和低功耗。 價格非常多樣。 MH-Z19傳感器具有良好的性能和價格,所以我決定買這個。
There are two variants of this sensor with different measuring range:
0 ~ 2000ppm
0 ~ 5000ppm
I choose the first one because more than 2000ppm CO2 level isn't appropriate for leaving.
我有一個MH-Z19 CO2傳感器,根據數據表,我可以通過UART和PWM獲得PPM值。 兩種方法之間的區別是CO2濃度的限制,其中UART I應該具有在0-5000ppm之間的讀數,並且通過PWM I應當具有在0-2000ppm之間的讀數。
簡易程式(MH-Z14 CO2 Sensor)
https://gist.github.com/bembu/580f3f0b8e9e5f783993
#include <SoftwareSerial.h>
#define CO2_TX 3
#define CO2_RX 2
SoftwareSerial SerialCO2(CO2_RX, CO2_TX); // RX, TX
const uint8_t cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
int getCO2() {
uint8_t response[9];
for (int i=0; i<9; i++) {
SerialCO2.write(cmd[i]);
}
if (SerialCO2.available()) {
for(int i=0; i < 9; i++) {
response[i] = SerialCO2.read();
}
}
int responseHigh = (int) response[2];
int responseLow = (int) response[3];
int ppm = (responseHigh << 8) + responseLow;
return ppm;
}
void setup() {
Serial.begin(9600);
SerialCO2.begin(9600);
Serial.println("Initialized.");
}
void loop() {
Serial.println(getCO2());
delay(200);
}