Compare commits
1 commit
main
...
feature/fu
Author | SHA1 | Date | |
---|---|---|---|
![]() |
94020b57d2 |
2 changed files with 31 additions and 127 deletions
|
@ -13,6 +13,5 @@ platform = atmelavr
|
||||||
board = nanoatmega328new
|
board = nanoatmega328new
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
; adafruit/Adafruit BME280 Library @ ^2.1.2
|
adafruit/Adafruit BME280 Library @ ^2.1.2
|
||||||
; miguel5612/MQUnifiedsensor @ ^2.0.1
|
; miguel5612/MQUnifiedsensor @ ^2.0.1
|
||||||
sparkfun/SparkFun HTU21D Humidity and Temperature Sensor Breakout @ ^1.1.3
|
|
||||||
|
|
153
src/main.cpp
153
src/main.cpp
|
@ -1,6 +1,6 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <MQ135.h>
|
#include <MQ135.h>
|
||||||
#include <SparkFunHTU21D.h>
|
#include <Adafruit_BME280.h>
|
||||||
|
|
||||||
#define PIN_MQ135 A7
|
#define PIN_MQ135 A7
|
||||||
#define PIN_NOISE 2
|
#define PIN_NOISE 2
|
||||||
|
@ -11,22 +11,13 @@
|
||||||
#define PIN_LED_RED 7
|
#define PIN_LED_RED 7
|
||||||
#define PIN_LED_RED2 8
|
#define PIN_LED_RED2 8
|
||||||
|
|
||||||
void printValues(float ppm, float temp, float humidity);
|
void printValues();
|
||||||
|
|
||||||
const int maxCount = 10;
|
float ppm;
|
||||||
int count = 0;
|
bool noiseActive;
|
||||||
|
|
||||||
bool noise = false;
|
|
||||||
bool noiseActive = false;
|
|
||||||
|
|
||||||
// loading
|
|
||||||
bool loading = true;
|
|
||||||
int firstRead;
|
|
||||||
const int loadingDelay = 200;
|
|
||||||
int loadingCount = 30000 / loadingDelay;
|
|
||||||
|
|
||||||
MQ135 co2_sensor(PIN_MQ135);
|
MQ135 co2_sensor(PIN_MQ135);
|
||||||
HTU21D envSensor;
|
Adafruit_BME280 bme;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(PIN_LED_GREEN, OUTPUT);
|
pinMode(PIN_LED_GREEN, OUTPUT);
|
||||||
|
@ -37,135 +28,49 @@ void setup() {
|
||||||
pinMode(PIN_LED_RED2, OUTPUT);
|
pinMode(PIN_LED_RED2, OUTPUT);
|
||||||
pinMode(PIN_NOISE, OUTPUT);
|
pinMode(PIN_NOISE, OUTPUT);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
co2_sensor.setR0(200);
|
co2_sensor.setR0(300);
|
||||||
|
|
||||||
// if (!bme.begin(0x76)) {
|
// if (!bme.begin(0x76)) {
|
||||||
// Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
// Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
||||||
// }
|
// }
|
||||||
envSensor.begin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (loading) {
|
// float temp = bme.readTemperature();
|
||||||
if (loadingCount <= 0) {
|
// float humidity = bme.readHumidity();
|
||||||
loading = false;
|
ppm = co2_sensor.getCO2();
|
||||||
count = -1;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int temp = analogRead(PIN_MQ135);
|
digitalWrite(PIN_LED_GREEN, 1);
|
||||||
if (temp > firstRead) {
|
digitalWrite(PIN_LED_GREEN2, 1);
|
||||||
firstRead = temp;
|
digitalWrite(PIN_LED_YELLOW, 1);
|
||||||
}
|
digitalWrite(PIN_LED_YELLOW2, 1);
|
||||||
else if (temp < (firstRead - 100) && loadingCount > 10) {
|
digitalWrite(PIN_LED_RED, 1);
|
||||||
loadingCount = 10;
|
digitalWrite(PIN_LED_RED2, 1);
|
||||||
}
|
|
||||||
|
|
||||||
digitalWrite(PIN_LED_GREEN, 0);
|
printValues();
|
||||||
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);
|
|
||||||
|
|
||||||
switch (count)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
digitalWrite(PIN_LED_RED2, 1);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
digitalWrite(PIN_LED_RED, 1);
|
|
||||||
digitalWrite(PIN_LED_RED2, 1);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
digitalWrite(PIN_LED_RED, 1);
|
|
||||||
digitalWrite(PIN_LED_YELLOW2, 1);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
digitalWrite(PIN_LED_YELLOW2, 1);
|
|
||||||
digitalWrite(PIN_LED_YELLOW, 1);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
digitalWrite(PIN_LED_YELLOW, 1);
|
|
||||||
digitalWrite(PIN_LED_GREEN2, 1);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
digitalWrite(PIN_LED_GREEN2, 1);
|
|
||||||
digitalWrite(PIN_LED_GREEN, 1);
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
digitalWrite(PIN_LED_GREEN, 1);
|
|
||||||
break;
|
|
||||||
case 10:
|
|
||||||
count = 0;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
loadingCount--;
|
|
||||||
count++;
|
|
||||||
delay(loadingDelay);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count >= maxCount || count < 0) {
|
|
||||||
float temp = envSensor.readTemperature();
|
|
||||||
float humidity = envSensor.readHumidity();
|
|
||||||
float 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);
|
|
||||||
|
|
||||||
if (ppm < 900) {
|
|
||||||
digitalWrite(PIN_LED_GREEN, 1);
|
|
||||||
}
|
|
||||||
if (ppm > 750 && ppm < 1100) {
|
|
||||||
digitalWrite(PIN_LED_GREEN2, 1);
|
|
||||||
}
|
|
||||||
if (ppm > 900 && ppm < 1900) {
|
|
||||||
digitalWrite(PIN_LED_YELLOW, 1);
|
|
||||||
}
|
|
||||||
if (ppm > 1500 && ppm < 2200) {
|
|
||||||
digitalWrite(PIN_LED_YELLOW2, 1);
|
|
||||||
}
|
|
||||||
if (ppm > 2000 && ppm < 2800) {
|
|
||||||
digitalWrite(PIN_LED_RED, 1);
|
|
||||||
}
|
|
||||||
if (ppm > 2500) {
|
|
||||||
digitalWrite(PIN_LED_RED2, 1);
|
|
||||||
}
|
|
||||||
if (ppm > 3000) {
|
|
||||||
noiseActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
printValues(ppm, temp, humidity);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (noiseActive) {
|
if (noiseActive) {
|
||||||
noise = !noise;
|
digitalWrite(PIN_NOISE, 1);
|
||||||
digitalWrite(PIN_NOISE, noise);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
digitalWrite(PIN_NOISE, 0);
|
digitalWrite(PIN_NOISE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(100);
|
delay(100);
|
||||||
count++;
|
// noiseActive = !noiseActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printValues(float ppm, float temp, float humidity) {
|
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.print("ppm: ");
|
||||||
Serial.println(ppm);
|
Serial.println(ppm);
|
||||||
Serial.print("Temperature: ");
|
// Serial.print("Temperature: ");
|
||||||
Serial.println(temp);
|
// Serial.println(temp);
|
||||||
Serial.print("Humidity: ");
|
// Serial.print("Humidity: ");
|
||||||
Serial.println(humidity);
|
// Serial.println(humidity);
|
||||||
|
// Serial.print("corrected ppm: ");
|
||||||
|
// Serial.println(cppm);
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue