2018-06-23 12:32:55 +00:00
|
|
|
#include <ESP8266WiFi.h>
|
2018-07-07 10:59:32 +00:00
|
|
|
#include <SoftwareSerial.h>
|
2019-06-08 10:46:57 +00:00
|
|
|
#include <MHZ.h>
|
2018-06-23 12:32:55 +00:00
|
|
|
|
2019-06-08 08:59:57 +00:00
|
|
|
// pin for pwm reading
|
2018-09-04 22:00:31 +00:00
|
|
|
#define CO2_IN 10
|
2018-06-23 10:35:27 +00:00
|
|
|
|
2019-06-08 08:59:57 +00:00
|
|
|
// pin for uart reading
|
2018-09-04 22:00:31 +00:00
|
|
|
#define MH_Z19_RX D4 // D7
|
|
|
|
#define MH_Z19_TX D0 // D6
|
2018-04-22 09:36:51 +00:00
|
|
|
|
2018-06-23 12:32:55 +00:00
|
|
|
MHZ co2(MH_Z19_RX, MH_Z19_TX, CO2_IN, MHZ19B);
|
2018-06-23 10:35:27 +00:00
|
|
|
|
2018-04-22 09:36:51 +00:00
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
2018-06-23 10:35:27 +00:00
|
|
|
pinMode(CO2_IN, INPUT);
|
2018-06-23 12:32:55 +00:00
|
|
|
delay(100);
|
|
|
|
Serial.println("MHZ 19B");
|
2018-06-24 10:22:50 +00:00
|
|
|
|
2018-09-04 22:00:31 +00:00
|
|
|
// enable debug to get addition information
|
|
|
|
// co2.setDebug(true);
|
|
|
|
|
|
|
|
if (co2.isPreHeating()) {
|
|
|
|
Serial.print("Preheating");
|
|
|
|
while (co2.isPreHeating()) {
|
|
|
|
Serial.print(".");
|
|
|
|
delay(5000);
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
}
|
2018-04-22 09:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2018-09-04 22:00:31 +00:00
|
|
|
Serial.print("\n----- Time from start: ");
|
|
|
|
Serial.print(millis() / 1000);
|
|
|
|
Serial.println(" s");
|
2018-06-24 12:38:42 +00:00
|
|
|
|
2018-06-23 12:32:55 +00:00
|
|
|
int ppm_uart = co2.readCO2UART();
|
2019-06-08 11:37:21 +00:00
|
|
|
Serial.print("PPMuart: ");
|
|
|
|
|
2018-06-24 12:38:42 +00:00
|
|
|
if (ppm_uart > 0) {
|
|
|
|
Serial.print(ppm_uart);
|
2019-06-08 11:37:21 +00:00
|
|
|
} else {
|
|
|
|
Serial.print("n/a");
|
2018-06-24 12:38:42 +00:00
|
|
|
}
|
|
|
|
|
2018-09-04 22:00:31 +00:00
|
|
|
int ppm_pwm = co2.readCO2PWM();
|
|
|
|
Serial.print(", PPMpwm: ");
|
|
|
|
Serial.print(ppm_pwm);
|
2018-06-24 12:38:42 +00:00
|
|
|
|
|
|
|
int temperature = co2.getLastTemperature();
|
2019-06-08 11:37:21 +00:00
|
|
|
Serial.print(", Temperature: ");
|
|
|
|
|
2018-06-24 12:38:42 +00:00
|
|
|
if (temperature > 0) {
|
|
|
|
Serial.println(temperature);
|
2019-06-08 11:37:21 +00:00
|
|
|
} else {
|
|
|
|
Serial.println("n/a");
|
2018-06-24 12:38:42 +00:00
|
|
|
}
|
2018-06-24 10:22:50 +00:00
|
|
|
|
2018-09-04 22:00:31 +00:00
|
|
|
Serial.println("\n------------------------------");
|
|
|
|
delay(5000);
|
2018-04-22 09:36:51 +00:00
|
|
|
}
|