You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.7 KiB

#include <Arduino.h>
#include "MHZ19.h"
#define RX_PIN 0 // Rx pin which the MHZ19 Tx pin is attached to
#define TX_PIN 1 // Tx pin which the MHZ19 Rx pin is attached to
#define BAUDRATE 9600 // Device to MH-Z19 Serial baudrate (should not be changed)
MHZ19 myMHZ19; // Constructor for library
unsigned long getDataTimer = 0;
void setup()
Serial.begin(9600); // Device to serial monitor feedback
Serial1.begin(BAUDRATE); // (Uno example) device to MH-Z19 serial start
// myMHZ19.printCommunication(false, true);
myMHZ19.begin(Serial1); // *Serial(Stream) refence must be passed to library begin().
myMHZ19.autoCalibration(); // Turn auto calibration ON (OFF autoCalibration(false))
void loop()
if (millis() - getDataTimer >= 2000)
int CO2;
/* note: getCO2() default is command "CO2 Unlimited". This returns the correct CO2 reading even
if below background CO2 levels or above range (useful to validate sensor). You can use the
usual documented command with getCO2(false) */
CO2 = myMHZ19.getCO2(); // Request CO2 (as ppm)
Serial.print("CO2 (ppm): ");
int8_t Temp;
Temp = myMHZ19.getTemperature(); // Request Temperature (as Celsius)
Serial.print("Temperature (C): ");
getDataTimer = millis();