Hi there everyone, I'm new this this forum and fairly new to Arduino.
I'm having and issue getting my MH-Z19B CO2 sensor to read in my serial monitor. I've tried looking at
many different examples of code that others have posted in their success stories. When I open my serial
monitor, all I see is that the sensor is preheating. Nothing after that. The sensor needs about 3 minutes
to heat up, and I've waiting for 20 minutes to no avail.
Serial Monitor looks like this:
MHZ 19B
Preheating...
But I don't get anything after that. I just keep seeing more ............... the longer I wait.
I hope that I am not doomed to fail! Please if you can help, with gentle language for simple folk
The MH-Z19B has the following connected to the Arduino Nano:
MH-Z19B Arduino Nano
Vin <=======================> 5V
GND <=======================> GND
PWM <=======================> D10
RX <=======================> TX1
TX <=======================> RX0
Below is the code that I am using.
#include <SoftwareSerial.h>
#include <MHZ.h>
// pin for pwm reading
#define CO2_IN 10
// pin for uart reading
#define MH_Z19_RX 1
#define MH_Z19_TX 0
MHZ co2(MH_Z19_RX, MH_Z19_TX, CO2_IN, MHZ19B);
void setup() {
Serial.begin(9600);
pinMode(CO2_IN, INPUT);
delay(100);
Serial.println("MHZ 19B");
// enable debug to get addition information
//co2.setDebug(true);
if (co2.isPreHeating()) {
Serial.print("Preheating");
while (co2.isPreHeating()) {
Serial.print(".");
delay(5000);
}
Serial.println();
}
}
void loop() {
Serial.print("\n----- Time from start: ");
Serial.print(millis() / 1000);
Serial.println(" s");
int ppm_uart = co2.readCO2UART();
Serial.print("PPMuart: ");
if (ppm_uart > 0) {
Serial.print(ppm_uart);
} else {
Serial.print("n/a");
}
int ppm_pwm = co2.readCO2PWM();
Serial.print(", PPMpwm: ");
Serial.print(ppm_pwm);
int temperature = co2.getLastTemperature();
Serial.print(", Temperature: ");
if (temperature > 0) {
Serial.println(temperature);
} else {
Serial.println("n/a");
}
Serial.println("\n------------------------------");
delay(5000);
}
MH-Z19B.txt (1.2 KB)