What I want to achieve
Use a CO2 sensor module MH-Z19C to detect CO2 in the room using UART with Arduino Nano.
Issue
The sensor gave an unreasonable value 0 ppm. Generally speaking, CO2 in the air is at least around 400 ppm.
Environment
- Windows 10
- Arduino IDE 2.1.1
- Arduino Nano
Schematic
Code
//
// FILE: MHZCO2_sw_serial.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: demo
// DATE: 2020-09-01
// https://github.com/RobTillaart/MHZCO2/blob/master/examples/MHZCO2_sw_serial/.arduino-ci.yml
#include "SoftwareSerial.h"
#include "MHZCO2.h"
const int RX = 3;
const int TX = 2;
SoftwareSerial ss(TX, RX);
MHZ19B MHZ19B;
void setup()
{
Serial.begin(9600);
Serial.println(__FILE__);
MHZ19B.begin(&ss);
ss.begin(9600);
}
void loop()
{
MHZ19B.measure();
Serial.println("------------------");
Serial.print("CO2: ");
Serial.println(MHZ19B.getCO2());
Serial.print("MCO2: ");
Serial.println(MHZ19B.getMinCO2());
Serial.print("Temp: ");
Serial.println(MHZ19B.getTemperature());
Serial.print("Accu: ");
Serial.println(MHZ19B.getAccuracy());
delay(1000);
}
Output on Serial Monitor
CO2: 0
MCO2: 0
Temp: 0
Accu: 0
What I tried so far
I searched "MH-Z19C not working" and found several pages but none of them seemed to be useful. I also looked into the datasheet but this didn't help me out.
https://akizukidenshi.com/download/ds/winsen/MH-Z19C_20210518.pdf
I made sure there was 5.0-5.02 volts between Vin and GND on MH-Z19C.
Any help would be appreciated. Thanks in advance.