Skip to content

Instantly share code, notes, and snippets.

@Dvorson
Last active March 22, 2019 16:29
Show Gist options
  • Save Dvorson/34ac2b9bc2d7f46caba980d5afe7bae4 to your computer and use it in GitHub Desktop.
Save Dvorson/34ac2b9bc2d7f46caba980d5afe7bae4 to your computer and use it in GitHub Desktop.
#include <Arduino.h>
#include "MHZ19.h"
#include <SoftwareSerial.h> // <--- Remove if using HardwareSerial / ESP32
#define RX_PIN 7
#define TX_PIN 6
#define BAUDRATE 9600 // Native to the sensor (do not change)
MHZ19 myMHZ19;
SoftwareSerial mySerial(RX_PIN, TX_PIN);
unsigned long getDataTimer = 0;
void setup()
{
Serial.begin(115200);
mySerial.begin(BAUDRATE);
myMHZ19.begin(mySerial); // *Imporant, Pass your Stream reference here
myMHZ19.autoCalibration(false); // Turn ABC OFF
}
void loop() {
if (millis() - getDataTimer >= 2000) {
int16_t CO2Unlimited = myMHZ19.getCO2(true, true);
if(myMHZ19.errorCode != RESULT_OK) {
Serial.println("Error found in communication ");
} else {
Serial.print("CO2_PPM_Unlim: ");
Serial.println(CO2Unlimited);
}
getDataTimer = millis(); // Update interval
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment