Compare commits
4 commits
main
...
feature/ca
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ed2778fa65 | ||
![]() |
5a16fccbad | ||
![]() |
93a5336344 | ||
![]() |
a189f430ec |
2 changed files with 39 additions and 80 deletions
|
@ -8,10 +8,12 @@
|
|||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
; nanoatmega328new
|
||||
|
||||
[env:arduino]
|
||||
platform = atmelavr
|
||||
board = nanoatmega328new
|
||||
board = uno
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
adafruit/Adafruit BME280 Library @ ^2.1.2
|
||||
; miguel5612/MQUnifiedsensor @ ^2.0.1
|
||||
; adafruit/Adafruit BME280 Library @ ^2.1.2
|
||||
sparkfun/SparkFun HTU21D Humidity and Temperature Sensor Breakout @ ^1.1.3
|
||||
|
|
111
src/main.cpp
111
src/main.cpp
|
@ -1,8 +1,8 @@
|
|||
#include <Arduino.h>
|
||||
#include <MQ135.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <SparkFunHTU21D.h>
|
||||
|
||||
#define PIN_MQ135 A7
|
||||
#define PIN_MQ135 A0
|
||||
#define PIN_NOISE 2
|
||||
#define PIN_LED_GREEN 3
|
||||
#define PIN_LED_GREEN2 4
|
||||
|
@ -11,95 +11,52 @@
|
|||
#define PIN_LED_RED 7
|
||||
#define PIN_LED_RED2 8
|
||||
|
||||
void printValues();
|
||||
|
||||
const int maxCount = 10;
|
||||
int count = 0;
|
||||
bool noise = false;
|
||||
bool noiseActive = false;
|
||||
|
||||
float ppm;
|
||||
|
||||
MQ135 co2_sensor(PIN_MQ135);
|
||||
Adafruit_BME280 bme;
|
||||
HTU21D envSensor;
|
||||
|
||||
void setup() {
|
||||
pinMode(PIN_LED_GREEN, OUTPUT);
|
||||
pinMode(PIN_LED_GREEN2, OUTPUT);
|
||||
pinMode(PIN_LED_YELLOW, OUTPUT);
|
||||
pinMode(PIN_LED_YELLOW2, OUTPUT);
|
||||
pinMode(PIN_LED_RED, OUTPUT);
|
||||
pinMode(PIN_LED_RED2, OUTPUT);
|
||||
pinMode(PIN_NOISE, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
co2_sensor.setR0(300);
|
||||
|
||||
if (!bme.begin(0x76)) {
|
||||
Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
||||
}
|
||||
co2_sensor.setR0(200);
|
||||
|
||||
envSensor.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (count >= maxCount || count < 0) {
|
||||
float temp = bme.readTemperature();
|
||||
float humidity = bme.readHumidity();
|
||||
ppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||
|
||||
count = 0;
|
||||
noiseActive = false;
|
||||
digitalWrite(PIN_LED_GREEN, 0);
|
||||
digitalWrite(PIN_LED_GREEN2, 0);
|
||||
digitalWrite(PIN_LED_YELLOW, 0);
|
||||
digitalWrite(PIN_LED_YELLOW2, 0);
|
||||
digitalWrite(PIN_LED_RED, 0);
|
||||
digitalWrite(PIN_LED_RED2, 0);
|
||||
float temp = envSensor.readTemperature();
|
||||
float humidity = envSensor.readHumidity();
|
||||
|
||||
if (ppm < 1000) {
|
||||
digitalWrite(PIN_LED_GREEN, 1);
|
||||
if (ppm > 750) {
|
||||
digitalWrite(PIN_LED_GREEN2, 1);
|
||||
}
|
||||
}
|
||||
if (ppm > 1000 && ppm <= 2000) {
|
||||
digitalWrite(PIN_LED_YELLOW, 1);
|
||||
if (ppm > 1500) {
|
||||
digitalWrite(PIN_LED_YELLOW2, 1);
|
||||
}
|
||||
}
|
||||
if (ppm > 2000) {
|
||||
digitalWrite(PIN_LED_RED, 1);
|
||||
if (ppm > 2500) {
|
||||
noiseActive = true;
|
||||
digitalWrite(PIN_LED_RED2, 1);
|
||||
}
|
||||
}
|
||||
float r0c = co2_sensor.getCorrectedR0(temp, humidity);
|
||||
float in = analogRead(PIN_MQ135);
|
||||
double v = co2_sensor.getVoltage();
|
||||
double r = co2_sensor.getResistance();
|
||||
float r0 = co2_sensor.getR0();
|
||||
|
||||
printValues();
|
||||
}
|
||||
double co2 = co2_sensor.getCO2();
|
||||
double co2c = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||
|
||||
if (noiseActive) {
|
||||
noise = !noise;
|
||||
// digitalWrite(PIN_NOISE, noise);
|
||||
}
|
||||
else {
|
||||
// digitalWrite(PIN_NOISE, 0);
|
||||
}
|
||||
Serial.print("Analog Read: ");
|
||||
Serial.println(in);
|
||||
Serial.print("Voltage: ");
|
||||
Serial.println(v);
|
||||
Serial.print("Resistance: ");
|
||||
Serial.println(r);
|
||||
|
||||
delay(100);
|
||||
count++;
|
||||
}
|
||||
|
||||
void printValues() {
|
||||
float temp = bme.readTemperature();
|
||||
float humidity = bme.readHumidity();
|
||||
float ppm = co2_sensor.getCO2();
|
||||
float cppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||
Serial.print("ppm: ");
|
||||
Serial.println(ppm);
|
||||
Serial.print("R0: ");
|
||||
Serial.println(r0);
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(temp);
|
||||
Serial.print("Humidity: ");
|
||||
Serial.println(humidity);
|
||||
Serial.print("corrected ppm: ");
|
||||
Serial.println(cppm);
|
||||
Serial.print("R0 Corrected: ");
|
||||
Serial.println(r0c);
|
||||
|
||||
Serial.print("CO2: ");
|
||||
Serial.println(co2);
|
||||
Serial.print("CO2 Corrected: ");
|
||||
Serial.println(co2c);
|
||||
|
||||
Serial.println("-----------------------------");
|
||||
|
||||
delay(1000);
|
||||
}
|
Loading…
Add table
Reference in a new issue