From f8b53f993ac61e470bcc1ee321c16a0657cf161d Mon Sep 17 00:00:00 2001 From: Gustavoeklund01 Date: Tue, 21 Oct 2025 16:48:30 -0300 Subject: sensor luz correto --- esp/BH1750.ino | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/esp/BH1750.ino b/esp/BH1750.ino index e69de29..9d4f9c9 100644 --- a/esp/BH1750.ino +++ b/esp/BH1750.ino @@ -0,0 +1,21 @@ +#include +#include + +BH1750 lightMeter; + +void setup(){ + Serial.begin(115200); + Wire.begin(21, 22); + lightMeter.begin(); + Serial.println("Teste sensor luminosidade"); +} +void loop(){ + float lux = + lightMeter.readLightLevel(); + + Serial.print("Luminosidade: "); + Serial.print(lux); + Serial.println(" lux"); + + delay(1000); +} \ No newline at end of file -- cgit v1.2.3 From 4008253dfd2005da102f6da06389268ecef152f6 Mon Sep 17 00:00:00 2001 From: Gustavoeklund01 Date: Mon, 27 Oct 2025 19:15:23 -0300 Subject: conciliação dos sensores do esp32 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp/AS5600.ino | 47 ------------------------------------------- esp/BH1750.ino | 21 ------------------- esp/BMP280.ino | 29 -------------------------- esp/DHT11.ino | 26 ------------------------ esp/LM393.ino | 42 -------------------------------------- esp/include/as5600.h | 0 esp/include/bh1750.h | 0 esp/include/bmp280.h | 0 esp/include/dht11.h | 0 esp/include/lm393.h | 0 esp/src/as5600.cpp | 0 esp/src/bh1750.cpp | 0 esp/src/bmp280.cpp | 0 esp/src/dht11.cpp | 0 esp/src/estacao_principal.ino | 39 +++++++++++++++++++++++++++++++++++ esp/src/lm393.cpp | 0 16 files changed, 39 insertions(+), 165 deletions(-) delete mode 100644 esp/AS5600.ino delete mode 100644 esp/BH1750.ino delete mode 100644 esp/BMP280.ino delete mode 100644 esp/DHT11.ino delete mode 100644 esp/LM393.ino create mode 100644 esp/include/as5600.h create mode 100644 esp/include/bh1750.h create mode 100644 esp/include/bmp280.h create mode 100644 esp/include/dht11.h create mode 100644 esp/include/lm393.h create mode 100644 esp/src/as5600.cpp create mode 100644 esp/src/bh1750.cpp create mode 100644 esp/src/bmp280.cpp create mode 100644 esp/src/dht11.cpp create mode 100644 esp/src/estacao_principal.ino create mode 100644 esp/src/lm393.cpp diff --git a/esp/AS5600.ino b/esp/AS5600.ino deleted file mode 100644 index 233aa13..0000000 --- a/esp/AS5600.ino +++ /dev/null @@ -1,47 +0,0 @@ -#include - -#define AS5600_ADDR 0x36 // endereço I2C do AS5600 -#define RAW_ANGLE_REG 0x0C - -unsigned long lastTime = 0; - -String direcaoCardinal(float angulo) { - if (angulo >= 337.5 || angulo < 22.5) return "Norte"; - else if (angulo < 67.5) return "Nordeste"; - else if (angulo < 112.5) return "Leste"; - else if (angulo < 157.5) return "Sudeste"; - else if (angulo < 202.5) return "Sul"; - else if (angulo < 247.5) return "Sudoeste"; - else if (angulo < 292.5) return "Oeste"; - else return "Noroeste"; -} - -uint16_t readRawAngle() { - Wire.beginTransmission(AS5600_ADDR); - Wire.write(RAW_ANGLE_REG); - Wire.endTransmission(); - Wire.requestFrom(AS5600_ADDR, 2); - uint16_t high = Wire.read(); - uint16_t low = Wire.read(); - return (high << 8) | low; -} - -void setup() { - Serial.begin(115200); - Wire.begin(); // SDA e SCL padrão do ESP32 (21 e 22) - Serial.println("Leitura do AS5600 - Direcao do Vento"); -} - -void loop() { - uint16_t raw = readRawAngle(); - // O AS5600 fornece 12 bits (0–4095) para 0–360° - float angulo = (raw & 0x0FFF) * 360.0 / 4096.0; - - if (millis() - lastTime >= 1000) { - Serial.print("Angulo: "); - Serial.print(angulo, 2); - Serial.print("° | Direcao: "); - Serial.println(direcaoCardinal(angulo)); - lastTime = millis(); - } -} diff --git a/esp/BH1750.ino b/esp/BH1750.ino deleted file mode 100644 index 9d4f9c9..0000000 --- a/esp/BH1750.ino +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -BH1750 lightMeter; - -void setup(){ - Serial.begin(115200); - Wire.begin(21, 22); - lightMeter.begin(); - Serial.println("Teste sensor luminosidade"); -} -void loop(){ - float lux = - lightMeter.readLightLevel(); - - Serial.print("Luminosidade: "); - Serial.print(lux); - Serial.println(" lux"); - - delay(1000); -} \ No newline at end of file diff --git a/esp/BMP280.ino b/esp/BMP280.ino deleted file mode 100644 index 417edb1..0000000 --- a/esp/BMP280.ino +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -Adafruit_BMP280 bmp; // cria o objeto do sensor - -void setup() { - Serial.begin(115200); - Wire.begin(21, 22); // SDA e SCL - Serial.println("Teste do Sensor BMP280 - Pressão e Temperatura"); - - if (!bmp.begin(0x76)) { // endereço I2C padrão - Serial.println("Erro: BMP280 não encontrado!"); - while (1); - } -} - -void loop() { - float temp = bmp.readTemperature(); - float press = bmp.readPressure() / 100.0F; // converte Pa para hPa - - Serial.print("Temperatura: "); - Serial.print(temp); - Serial.print(" °C | Pressão: "); - Serial.print(press); - Serial.println(" hPa"); - - delay(2000); // leitura a cada 2 segundos -} \ No newline at end of file diff --git a/esp/DHT11.ino b/esp/DHT11.ino deleted file mode 100644 index e0f0342..0000000 --- a/esp/DHT11.ino +++ /dev/null @@ -1,26 +0,0 @@ -#include "DHT.h" -#define DHTPIN 32 -#define DHTTYPE DHT11 - -DHT dht(DHTPIN, DHTTYPE); - -void setup() { - Serial.begin(115200); - dht.begin(); - Serial.println("Teste sensor DHT11 Temperatura e humidade"); -} -void loop(){ - float h = dht.readHumidity(); - float t = dht.readTemperature(); - - if (isnan(h) || isnan(t)){ - Serial.println("ERRO de leitura"); - return; - } - Serial.print("Humidade: "); - Serial.print(h); - Serial.print("% | Temperatura:"); - Serial.print(t); - Serial.println(" °C"); - delay(2000); -} \ No newline at end of file diff --git a/esp/LM393.ino b/esp/LM393.ino deleted file mode 100644 index 6e6a5d5..0000000 --- a/esp/LM393.ino +++ /dev/null @@ -1,42 +0,0 @@ -#define SENSOR_PIN 35 // pino de sinal (DO) - -unsigned long lastTime = 0; -unsigned int pulsos = 0; -int estadoAnterior = HIGH; // começa em HIGH (sem interrupção) - -// Configurações do sensor -const int PULSOS_POR_VOLTA = 10; // 10 furos = 10 pulsos por volta -const float FATOR_KMH = 2.4; // km/h por rotação por segundo (ajuste conforme calibração) - -void setup() { - Serial.begin(115200); - pinMode(SENSOR_PIN, INPUT); - Serial.println("Anemômetro LM393 - Velocidade do vento"); -} - -void loop() { - int estadoAtual = digitalRead(SENSOR_PIN); - - // Detecta borda de descida: HIGH → LOW - if (estadoAnterior == HIGH && estadoAtual == LOW) { - pulsos++; - } - - estadoAnterior = estadoAtual; // atualiza para próxima leitura - - // A cada 1 segundo calcula RPM e velocidade - if (millis() - lastTime >= 1000) { - float rps = (float)pulsos / PULSOS_POR_VOLTA; - float rpm = rps * 60.0; - float velocidade = rps * FATOR_KMH; - - Serial.print("RPM: "); - Serial.print(rpm); - Serial.print(" | Velocidade: "); - Serial.print(velocidade); - Serial.println(" km/h"); - - pulsos = 0; - lastTime = millis(); - } -} \ No newline at end of file diff --git a/esp/include/as5600.h b/esp/include/as5600.h new file mode 100644 index 0000000..e69de29 diff --git a/esp/include/bh1750.h b/esp/include/bh1750.h new file mode 100644 index 0000000..e69de29 diff --git a/esp/include/bmp280.h b/esp/include/bmp280.h new file mode 100644 index 0000000..e69de29 diff --git a/esp/include/dht11.h b/esp/include/dht11.h new file mode 100644 index 0000000..e69de29 diff --git a/esp/include/lm393.h b/esp/include/lm393.h new file mode 100644 index 0000000..e69de29 diff --git a/esp/src/as5600.cpp b/esp/src/as5600.cpp new file mode 100644 index 0000000..e69de29 diff --git a/esp/src/bh1750.cpp b/esp/src/bh1750.cpp new file mode 100644 index 0000000..e69de29 diff --git a/esp/src/bmp280.cpp b/esp/src/bmp280.cpp new file mode 100644 index 0000000..e69de29 diff --git a/esp/src/dht11.cpp b/esp/src/dht11.cpp new file mode 100644 index 0000000..e69de29 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 +#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..e69de29 -- cgit v1.2.3 From 7ccab61c22fafb3bb9fa5470ff8cb46217111fe4 Mon Sep 17 00:00:00 2001 From: Gustavoeklund01 Date: Mon, 27 Oct 2025 20:28:29 -0300 Subject: outros códigos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp/include/as5600.h | 3 +++ esp/include/bh1750.h | 3 +++ esp/include/bmp280.h | 4 ++++ esp/include/dht11.h | 4 ++++ esp/include/lm393.h | 3 +++ esp/src/as5600.cpp | 13 +++++++++++++ esp/src/bh1750.cpp | 13 +++++++++++++ esp/src/bmp280.cpp | 20 ++++++++++++++++++++ esp/src/dht11.cpp | 18 ++++++++++++++++++ esp/src/lm393.cpp | 26 ++++++++++++++++++++++++++ 10 files changed, 107 insertions(+) diff --git a/esp/include/as5600.h b/esp/include/as5600.h index e69de29..059ae01 100644 --- a/esp/include/as5600.h +++ 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 index e69de29..289d82a 100644 --- a/esp/include/bh1750.h +++ 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 index e69de29..43ae83e 100644 --- a/esp/include/bmp280.h +++ 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 index e69de29..84af67f 100644 --- a/esp/include/dht11.h +++ 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 index e69de29..2b8d983 100644 --- a/esp/include/lm393.h +++ 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 index e69de29..1dfdb71 100644 --- a/esp/src/as5600.cpp +++ b/esp/src/as5600.cpp @@ -0,0 +1,13 @@ +#include +#include +#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 index e69de29..196705c 100644 --- a/esp/src/bh1750.cpp +++ b/esp/src/bh1750.cpp @@ -0,0 +1,13 @@ +#include +#include +#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 index e69de29..0ba749a 100644 --- a/esp/src/bmp280.cpp +++ b/esp/src/bmp280.cpp @@ -0,0 +1,20 @@ +#include +#include +#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 index e69de29..9900363 100644 --- a/esp/src/dht11.cpp +++ 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/lm393.cpp b/esp/src/lm393.cpp index e69de29..5eb4bdf 100644 --- a/esp/src/lm393.cpp +++ b/esp/src/lm393.cpp @@ -0,0 +1,26 @@ +#include +#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; +} -- cgit v1.2.3