diff options
| -rw-r--r-- | esp/estacao_principal/estacao_principal.ino | 135 | ||||
| -rw-r--r-- | esp/include/as5600.h | 3 | ||||
| -rw-r--r-- | esp/include/bh1750.h | 3 | ||||
| -rw-r--r-- | esp/include/bmp280.h | 4 | ||||
| -rw-r--r-- | esp/include/dht11.h | 4 | ||||
| -rw-r--r-- | esp/include/lm393.h | 3 | ||||
| -rw-r--r-- | esp/src/as5600.cpp | 13 | ||||
| -rw-r--r-- | esp/src/bh1750.cpp | 13 | ||||
| -rw-r--r-- | esp/src/bmp280.cpp | 20 | ||||
| -rw-r--r-- | esp/src/dht11.cpp | 18 | ||||
| -rw-r--r-- | esp/src/estacao_principal.ino | 39 | ||||
| -rw-r--r-- | esp/src/lm393.cpp | 26 |
12 files changed, 135 insertions, 146 deletions
diff --git a/esp/estacao_principal/estacao_principal.ino b/esp/estacao_principal/estacao_principal.ino new file mode 100644 index 0000000..cfc5470 --- /dev/null +++ b/esp/estacao_principal/estacao_principal.ino @@ -0,0 +1,135 @@ +#include <Wire.h> +#include <Adafruit_BMP280.h> +#include <BH1750.h> +#include <DHT.h> + +// LM393 +#define LM393_INTERVAL 1000 +#define LM393_PIN 35 // ou 35 se preferir + +volatile unsigned long contagem_lm393 = 0; + +volatile bool prevLm393State = LOW; +void isr_lm393() { + bool state = digitalRead(LM393_PIN); + + if (prevLm393State != state) { + contagem_lm393++; + } + + prevLm393State = state; +} + +unsigned long lastTime_lm393 = 0; +/////////////////////////////////////////////////////////////////////////// + +// BH1750 +#define BH1750_INTERVAL 2000 + +BH1750 lightMeter; + +unsigned long lastTime_bh1750 = 0; +/////////////////////////////////////////////////////////////////////////// + +// DHT11 +#define DHT_PIN 32 +#define DHTTYPE DHT11 +DHT dht(DHT_PIN, DHTTYPE); + +#define DHT11_HUM_INTERVAL 4000 + +unsigned long lastTime_dht11_hum = 0; + +/////////////////////////////////// + +// BMP280 +Adafruit_BMP280 bmp; +#define BMP280_PRESSURE_INTERVAL 5000 +#define BMP280_TEMPERATURE_INTERVAL 3000 + +unsigned long lastTime_bmp280_press = 0; +unsigned long lastTime_bmp280_temp = 0; +///////////////////////////////////// + +void setup() { + Serial.begin(115200); + Wire.begin(21, 22); + + // LM393 + pinMode(LM393_PIN, INPUT); + attachInterrupt(digitalPinToInterrupt(LM393_PIN), isr_lm393, CHANGE); + + // BH1750 + lightMeter.begin(); + + // DHT11 + dht.begin(); + + // BMP280 + bmp.begin(0x76); + + Serial.println("Estacao iniciada"); +} + + +void loop() { + + unsigned long now = millis(); + + // LM393 + if (now - lastTime_lm393 >= LM393_INTERVAL) { + int pulsos; + + const float FATOR_KHM = 2.4; + + noInterrupts(); + pulsos = contagem_lm393; + contagem_lm393 = 0; + interrupts(); + + int giros = pulsos / 10; + + float rps = ((float)pulsos/10.0f) / (LM393_INTERVAL / 1000.0f); + float velocidade = rps * FATOR_KHM; + + Serial.print("Velocidade do tempo: "); + Serial.print(velocidade); + Serial.println(" km/h"); + lastTime_lm393 = now; + } + + // BH1750 + if (now - lastTime_bh1750 >= BH1750_INTERVAL) { + Serial.print("Luz: "); + Serial.print(lightMeter.readLightLevel()); + Serial.println(" lux"); + + lastTime_bh1750 = now; + } + + // DHT11 - Umidade + if (now - lastTime_dht11_hum >= DHT11_HUM_INTERVAL) { + Serial.print("Umidade: "); + Serial.print(dht.readHumidity()); + Serial.println(" %"); + lastTime_dht11_hum = now; + } + + // BMP280 - AIR PRESSURE + if (now - lastTime_bmp280_press >= BMP280_PRESSURE_INTERVAL) { + Serial.print("Pressao: "); + Serial.print(bmp.readPressure() / 100.0f); + Serial.println(" hPa"); + + lastTime_bmp280_press = now; + } + + // BMP280 - TEMPERATURE + if (now - lastTime_bmp280_temp >= BMP280_TEMPERATURE_INTERVAL) { + Serial.print("Temperatura: "); + Serial.print(bmp.readTemperature()); + Serial.println(" C"); + + lastTime_bmp280_temp = now; + } +} diff --git a/esp/include/as5600.h b/esp/include/as5600.h deleted file mode 100644 index 059ae01..0000000 --- a/esp/include/as5600.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -void setupAS5600(); -float lerAS5600(); diff --git a/esp/include/bh1750.h b/esp/include/bh1750.h deleted file mode 100644 index 289d82a..0000000 --- a/esp/include/bh1750.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -void setupBH1750(); -float lerBH1750(); diff --git a/esp/include/bmp280.h b/esp/include/bmp280.h deleted file mode 100644 index 43ae83e..0000000 --- a/esp/include/bmp280.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -void setupBMP280(); -float lerTemperaturaBMP280(); -float lerPressaoBMP280(); diff --git a/esp/include/dht11.h b/esp/include/dht11.h deleted file mode 100644 index 84af67f..0000000 --- a/esp/include/dht11.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -void setupDHT11(); -float lerTemperaturaDHT11(); -float lerUmidadeDHT11(); diff --git a/esp/include/lm393.h b/esp/include/lm393.h deleted file mode 100644 index 2b8d983..0000000 --- a/esp/include/lm393.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once -void setupLM393(); -int lerLM393(); diff --git a/esp/src/as5600.cpp b/esp/src/as5600.cpp deleted file mode 100644 index 1dfdb71..0000000 --- a/esp/src/as5600.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include <Wire.h> -#include <AS5600.h> -#include "as5600.h" - -AS5600 as5600; - -void setupAS5600() { - as5600.begin(21, 22); -} - -float lerAS5600() { - return as5600.readAngle(); -} diff --git a/esp/src/bh1750.cpp b/esp/src/bh1750.cpp deleted file mode 100644 index 196705c..0000000 --- a/esp/src/bh1750.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include <Wire.h> -#include <BH1750.h> -#include "bh1750.h" - -BH1750 lightMeter; - -void setupBH1750() { - lightMeter.begin(); -} - -float lerBH1750() { - return lightMeter.readLightLevel(); -} diff --git a/esp/src/bmp280.cpp b/esp/src/bmp280.cpp deleted file mode 100644 index 0ba749a..0000000 --- a/esp/src/bmp280.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include <Wire.h> -#include <Adafruit_BMP280.h> -#include "bmp280.h" - -Adafruit_BMP280 bmp; - -void setupBMP280() { - if (!bmp.begin(0x76)) { - Serial.println("BMP280 nao achado"); - while (1); - } -} - -float lerTemperaturaBMP280() { - return bmp.readTemperature(); -} - -float lerPressaoBMP280() { - return bmp.readPressure() / 100.0F; -} diff --git a/esp/src/dht11.cpp b/esp/src/dht11.cpp deleted file mode 100644 index 9900363..0000000 --- a/esp/src/dht11.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "DHT.h" -#include "dht11.h" - -#define DHTPIN 32 -#define DHTTYPE DHT11 -DHT dht(DHTPIN, DHTTYPE); - -void setupDHT11() { - dht.begin(); -} - -float lerTemperaturaDHT11() { - return dht.readTemperature(); -} - -float lerUmidadeDHT11() { - return dht.readHumidity(); -} diff --git a/esp/src/estacao_principal.ino b/esp/src/estacao_principal.ino deleted file mode 100644 index 65f155c..0000000 --- a/esp/src/estacao_principal.ino +++ /dev/null @@ -1,39 +0,0 @@ -#include <Wire.h> -#include "dht11.h" -#include "bh1750.h" -#include "bmp280.h" -#include "lm393.h" -#include "as5600.h" - -void setup() { - Serial.begin(115200); - Wire.begin(21, 22); // SDA, SCL - - setupDHT11(); - setupBH1750(); - setupBMP280(); - setupLM393(); - setupAS5600(); - - Serial.println("Estacao iniciada"); -} - -void loop() { - float tempDHT = lerTemperaturaDHT11(); - float umid = lerUmidadeDHT11(); - float lux = lerBH1750(); - float tempBMP = lerTemperaturaBMP280(); - float press = lerPressaoBMP280(); - int pulsos = lerLM393(); - float angulo = lerAS5600(); - - Serial.println("----"); - Serial.print("Umid: "); Serial.print(umid); Serial.println(" %"); - Serial.print("Temp DHT: "); Serial.print(tempDHT); Serial.println(" C"); - Serial.print("Temp BMP: "); Serial.print(tempBMP); Serial.println(" C"); - Serial.print("Pressao: "); Serial.print(press); Serial.println(" hPa"); - Serial.print("Lux: "); Serial.print(lux); Serial.println(" lx"); - Serial.print("Pulsos: "); Serial.println(pulsos); - Serial.print("Angulo: "); Serial.println(angulo); - delay(30000); -} diff --git a/esp/src/lm393.cpp b/esp/src/lm393.cpp deleted file mode 100644 index 5eb4bdf..0000000 --- a/esp/src/lm393.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include <Arduino.h> -#include "lm393.h" - -#define SENSOR_PIN 32 // ou 35 se preferir - -void setupLM393() { - pinMode(SENSOR_PIN, INPUT); -} - -int lerLM393() { - static int contagem = 0; - static unsigned long lastTime = 0; - - if (digitalRead(SENSOR_PIN) == LOW) { - contagem++; - delay(10); - } - - if (millis() - lastTime >= 1000) { - int pulsos = contagem; - contagem = 0; - lastTime = millis(); - return pulsos; - } - return 0; -} |
