MH-Z-CO2-Sensors/examples/MH-Z19B/MH-Z19B.ino
Andreas Horn 253f8ae7d1 implements various small fixes and improvements
* the preheating time is now a constant variable too
* it is no possible to initialize the senor without PWM xor without (Soft-)Serial
*
2019-06-08 13:37:21 +02:00

62 lines
1.2 KiB
C++

#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <MHZ.h>
// pin for pwm reading
#define CO2_IN 10
// pin for uart reading
#define MH_Z19_RX D4 // D7
#define MH_Z19_TX D0 // D6
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);
}