summaryrefslogtreecommitdiff
path: root/esp
diff options
context:
space:
mode:
Diffstat (limited to 'esp')
-rw-r--r--esp/include/as5600.h3
-rw-r--r--esp/include/bh1750.h3
-rw-r--r--esp/include/bmp280.h4
-rw-r--r--esp/include/dht11.h4
-rw-r--r--esp/include/lm393.h3
-rw-r--r--esp/src/as5600.cpp13
-rw-r--r--esp/src/bh1750.cpp13
-rw-r--r--esp/src/bmp280.cpp20
-rw-r--r--esp/src/dht11.cpp18
-rw-r--r--esp/src/estacao_principal.ino39
-rw-r--r--esp/src/lm393.cpp26
11 files changed, 146 insertions, 0 deletions
diff --git a/esp/include/as5600.h b/esp/include/as5600.h
new file mode 100644
index 0000000..059ae01
--- /dev/null
+++ b/esp/include/as5600.h
@@ -0,0 +1,3 @@
+#pragma once
+void setupAS5600();
+float lerAS5600();
diff --git a/esp/include/bh1750.h b/esp/include/bh1750.h
new file mode 100644
index 0000000..289d82a
--- /dev/null
+++ b/esp/include/bh1750.h
@@ -0,0 +1,3 @@
+#pragma once
+void setupBH1750();
+float lerBH1750();
diff --git a/esp/include/bmp280.h b/esp/include/bmp280.h
new file mode 100644
index 0000000..43ae83e
--- /dev/null
+++ b/esp/include/bmp280.h
@@ -0,0 +1,4 @@
+#pragma once
+void setupBMP280();
+float lerTemperaturaBMP280();
+float lerPressaoBMP280();
diff --git a/esp/include/dht11.h b/esp/include/dht11.h
new file mode 100644
index 0000000..84af67f
--- /dev/null
+++ b/esp/include/dht11.h
@@ -0,0 +1,4 @@
+#pragma once
+void setupDHT11();
+float lerTemperaturaDHT11();
+float lerUmidadeDHT11();
diff --git a/esp/include/lm393.h b/esp/include/lm393.h
new file mode 100644
index 0000000..2b8d983
--- /dev/null
+++ b/esp/include/lm393.h
@@ -0,0 +1,3 @@
+#pragma once
+void setupLM393();
+int lerLM393();
diff --git a/esp/src/as5600.cpp b/esp/src/as5600.cpp
new file mode 100644
index 0000000..1dfdb71
--- /dev/null
+++ b/esp/src/as5600.cpp
@@ -0,0 +1,13 @@
+#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
new file mode 100644
index 0000000..196705c
--- /dev/null
+++ b/esp/src/bh1750.cpp
@@ -0,0 +1,13 @@
+#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
new file mode 100644
index 0000000..0ba749a
--- /dev/null
+++ b/esp/src/bmp280.cpp
@@ -0,0 +1,20 @@
+#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
new file mode 100644
index 0000000..9900363
--- /dev/null
+++ b/esp/src/dht11.cpp
@@ -0,0 +1,18 @@
+#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
new file mode 100644
index 0000000..65f155c
--- /dev/null
+++ b/esp/src/estacao_principal.ino
@@ -0,0 +1,39 @@
+#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
new file mode 100644
index 0000000..5eb4bdf
--- /dev/null
+++ b/esp/src/lm393.cpp
@@ -0,0 +1,26 @@
+#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;
+}