#include <Arduino.h>
#include "DHT.h"
#include "MHZCO2.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
MHZ19B MHZ19B;
int getRandom(int lower, int upper) {
return (rand() % (upper - lower + 1)) + lower;
}
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
dht.begin();
MHZ19B.begin(&Serial1);
Serial.println(F("Starting ..."));
}
void loop() {
delay(2000);
MHZ19B.measure();
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
float co2 = 500 + getRandom(1, 10) / 10;
float s02 = 10 + getRandom(1, 10) / 10;
Serial.print(F(" CO2 (in ppm): "));
Serial.print(co2);
Serial.print(F(" SO2 (in ppm): "));
Serial.print(s02);
if (isnan(h) || isnan(t) || isnan(f) || isnan(co2) || isnan(s02)) {
Serial.println(F(" Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F(" Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}