/* Inclusão das Bibliotecas */
#include "BluetoothSerial.h" // Biblioteca do bluetooth
#include <Bonezegei_DHT11.h> // Biblioteca da DHT11
#include <WiFi.h> // Biblioteca do WIFI
#include <Wire.h> // Biblioteca para envio e recebimentos em interface I2C
#include <LiquidCrystal_I2C.h> // Biblioteca do LCD
#include <ToneESP32.h> // Biblioteca do BUZZER
/* CONSTANTES */
#define I2C_ADDR 0x27 // Endereço da LCD
#define LCD_COLUMNS 16 // Numeros de Colunas
#define LCD_ROWS 2 // Numeros de Linhas
#define NTP_SERVER "a.ntp.br" // SERVIDOR de NTP
#define BUZZER_PIN 15 // Pino usado pelo Buzzer
const char* ssid = "ADEGA MALBEC - HOME";
const char* password = "Wifi737Ecm@";
/* Verificando se o Bluetooth está atiavdo */
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
/* Verificando se o Bluetooth esta disponivel no ESP32*/
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif
const char *pin = "784512"; // PIN do bluetooth
Bonezegei_DHT11 dht(23); // Pino do ESP32 Responsável pela leitura
BluetoothSerial SerialBT; // Iniciando o Serial do Bluetooth
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(I2C_ADDR, LCD_COLUMNS, LCD_ROWS); // Endereçamento no display LCD
String device_name = "ESP32-EDUARDO"; // Nome do bluetooth
String msgH = "Horario atual";
String msgT = "A Temperatura atual é de ";
String msgU = "Umidade relativa do ar é de ";
void setup() {
Serial.begin(115200); // Inicia a comunicação via serial para debug
SerialBT.begin(device_name); // Inicia o Bluetooth
dht.begin(); // Inicia o Sensor DHT11
lcd.begin(LCD_COLUMNS, LCD_ROWS); // Inicia o Display com suas constantes
lcd.init(); // Inicia o Display
lcd.backlight(); // Ativa o backlight
lcd.clear(); // Limpa a tela do Display
lcd.setCursor(0, 0); // Coloca o Cursor na posição inicial
lcd.print("Iniciando...."); // Mostra na tela
delay(6000); // Espera 6 Segundos
tone(BUZZER_PIN, 2000); // Bipa o Buzzer
delay(500); // Espera 500ms
noTone(BUZZER_PIN); // Desliga o Buzzer
lcd.setCursor(0,1); // Display na Linha de Baixo
lcd.print("ESP32 & LCD1602"); // Mostra na tela
delay(6000); // Espera 6 Segundos
lcd.clear();
lcd.print("Conectando-se a");
lcd.setCursor(0, 1);
lcd.print(ssid);
delay(6000);
}
void loop() {
if (dht.getData()) {
float temp = dht.getTemperature(); // Retorna a temperatura
int umi = dht.getHumidity(); // Retona a munidade
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(msgH);
lcd.setCursor(0, 1);
lcd.print("21:45");
String txt_temp = "Temperatura atual é de ";
String txt_umi = "Umidade atual é de ";
txt_temp += temp;
txt_temp += "°C";
txt_umi += umi;
txt_umi += "%";
// lcd.clear();
//lcd.setCursor(0, 0);
//lcd.print(txt_temp);
//lcd.setCursor(0, 1);
//lcd.print(txt_umi);
//SerialBT.println(txt_temp);
//SerialBT.println(txt_umi);
//SerialBT.println("--------");
}
delay(10000);
}