Last active
March 22, 2019 16:29
-
-
Save Dvorson/34ac2b9bc2d7f46caba980d5afe7bae4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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