fix loading + htu21 sensor
This commit is contained in:
parent
beb41310c1
commit
0fa26e334d
2 changed files with 84 additions and 70 deletions
|
@ -13,5 +13,6 @@ platform = atmelavr
|
|||
board = nanoatmega328new
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
adafruit/Adafruit BME280 Library @ ^2.1.2
|
||||
; adafruit/Adafruit BME280 Library @ ^2.1.2
|
||||
; miguel5612/MQUnifiedsensor @ ^2.0.1
|
||||
sparkfun/SparkFun HTU21D Humidity and Temperature Sensor Breakout @ ^1.1.3
|
||||
|
|
151
src/main.cpp
151
src/main.cpp
|
@ -1,6 +1,6 @@
|
|||
#include <Arduino.h>
|
||||
#include <MQ135.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <SparkFunHTU21D.h>
|
||||
|
||||
#define PIN_MQ135 A7
|
||||
#define PIN_NOISE 2
|
||||
|
@ -11,18 +11,22 @@
|
|||
#define PIN_LED_RED 7
|
||||
#define PIN_LED_RED2 8
|
||||
|
||||
void printValues();
|
||||
void printValues(float ppm, float temp, float humidity);
|
||||
|
||||
const int maxCount = 10;
|
||||
int count = 0;
|
||||
|
||||
bool noise = false;
|
||||
bool noiseActive = false;
|
||||
bool loading = false;
|
||||
|
||||
float ppm;
|
||||
// loading
|
||||
bool loading = true;
|
||||
int firstRead;
|
||||
const int loadingDelay = 200;
|
||||
int loadingCount = 30000 / loadingDelay;
|
||||
|
||||
MQ135 co2_sensor(PIN_MQ135);
|
||||
Adafruit_BME280 bme;
|
||||
HTU21D envSensor;
|
||||
|
||||
void setup() {
|
||||
pinMode(PIN_LED_GREEN, OUTPUT);
|
||||
|
@ -33,68 +37,83 @@ void setup() {
|
|||
pinMode(PIN_LED_RED2, OUTPUT);
|
||||
pinMode(PIN_NOISE, OUTPUT);
|
||||
Serial.begin(9600);
|
||||
co2_sensor.setR0(130);
|
||||
co2_sensor.setR0(200);
|
||||
|
||||
// if (!bme.begin(0x76)) {
|
||||
// Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
||||
// }
|
||||
envSensor.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if (loading) {
|
||||
// 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 (loading) {
|
||||
if (loadingCount <= 0) {
|
||||
loading = false;
|
||||
count = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
// 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;
|
||||
int temp = analogRead(PIN_MQ135);
|
||||
if (temp > firstRead) {
|
||||
firstRead = temp;
|
||||
}
|
||||
else if (temp < (firstRead - 100) && loadingCount > 10) {
|
||||
loadingCount = 10;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
// }
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// count++;
|
||||
// delay(200);
|
||||
// return;
|
||||
// }
|
||||
loadingCount--;
|
||||
count++;
|
||||
delay(loadingDelay);
|
||||
return;
|
||||
}
|
||||
|
||||
if (count >= maxCount || count < 0) {
|
||||
// float temp = bme.readTemperature();
|
||||
// float humidity = bme.readHumidity();
|
||||
// ppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||
ppm = co2_sensor.getCO2();
|
||||
float temp = envSensor.readTemperature();
|
||||
float humidity = envSensor.readHumidity();
|
||||
float ppm = co2_sensor.getCorrectedCO2(temp, humidity);
|
||||
|
||||
count = 0;
|
||||
noiseActive = false;
|
||||
|
@ -127,32 +146,26 @@ void loop() {
|
|||
noiseActive = true;
|
||||
}
|
||||
|
||||
printValues();
|
||||
printValues(ppm, temp, humidity);
|
||||
}
|
||||
|
||||
if (noiseActive) {
|
||||
noise = !noise;
|
||||
// digitalWrite(PIN_NOISE, noise);
|
||||
digitalWrite(PIN_NOISE, noise);
|
||||
}
|
||||
else {
|
||||
// digitalWrite(PIN_NOISE, 0);
|
||||
digitalWrite(PIN_NOISE, 0);
|
||||
}
|
||||
|
||||
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);
|
||||
void printValues(float ppm, float temp, float 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);
|
||||
}
|
Loading…
Add table
Reference in a new issue