Compare commits
1 commit
main
...
feature/fu
Author | SHA1 | Date | |
---|---|---|---|
![]() |
94020b57d2 |
1 changed files with 27 additions and 56 deletions
83
src/main.cpp
83
src/main.cpp
|
@ -13,12 +13,8 @@
|
|||
|
||||
void printValues();
|
||||
|
||||
const int maxCount = 10;
|
||||
int count = 0;
|
||||
bool noise = false;
|
||||
bool noiseActive = false;
|
||||
|
||||
float ppm;
|
||||
bool noiseActive;
|
||||
|
||||
MQ135 co2_sensor(PIN_MQ135);
|
||||
Adafruit_BME280 bme;
|
||||
|
@ -34,72 +30,47 @@ void setup() {
|
|||
Serial.begin(9600);
|
||||
co2_sensor.setR0(300);
|
||||
|
||||
if (!bme.begin(0x76)) {
|
||||
Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
||||
}
|
||||
// if (!bme.begin(0x76)) {
|
||||
// Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
||||
// }
|
||||
}
|
||||
|
||||
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 = bme.readTemperature();
|
||||
// float humidity = bme.readHumidity();
|
||||
ppm = co2_sensor.getCO2();
|
||||
|
||||
digitalWrite(PIN_LED_GREEN, 1);
|
||||
digitalWrite(PIN_LED_GREEN2, 1);
|
||||
digitalWrite(PIN_LED_YELLOW, 1);
|
||||
digitalWrite(PIN_LED_YELLOW2, 1);
|
||||
digitalWrite(PIN_LED_RED, 1);
|
||||
digitalWrite(PIN_LED_RED2, 1);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
printValues();
|
||||
}
|
||||
printValues();
|
||||
|
||||
if (noiseActive) {
|
||||
noise = !noise;
|
||||
// digitalWrite(PIN_NOISE, noise);
|
||||
digitalWrite(PIN_NOISE, 1);
|
||||
}
|
||||
else {
|
||||
// digitalWrite(PIN_NOISE, 0);
|
||||
digitalWrite(PIN_NOISE, 0);
|
||||
}
|
||||
|
||||
delay(100);
|
||||
count++;
|
||||
// noiseActive = !noiseActive;
|
||||
}
|
||||
|
||||
void printValues() {
|
||||
float temp = bme.readTemperature();
|
||||
float humidity = bme.readHumidity();
|
||||
// float temp = bme.readTemperature();
|
||||
// float humidity = bme.readHumidity();
|
||||
float ppm = co2_sensor.getCO2();
|
||||
float cppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||
// float cppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||
Serial.print("ppm: ");
|
||||
Serial.println(ppm);
|
||||
Serial.print("Temperature: ");
|
||||
Serial.println(temp);
|
||||
Serial.print("Humidity: ");
|
||||
Serial.println(humidity);
|
||||
Serial.print("corrected ppm: ");
|
||||
Serial.println(cppm);
|
||||
// Serial.print("Temperature: ");
|
||||
// Serial.println(temp);
|
||||
// Serial.print("Humidity: ");
|
||||
// Serial.println(humidity);
|
||||
// Serial.print("corrected ppm: ");
|
||||
// Serial.println(cppm);
|
||||
}
|
Loading…
Add table
Reference in a new issue