#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
// Paramètres du réseau WiFi
const char* ssid = "Votre_SSID";
const char* password = "Votre_Mot_de_Passe";
// Paramètres de l'afficheur LCD I2C
LiquidCrystal_I2C lcd(0x27, 16, 2, D0, D1); // Adresse I2C et dimensions de l'afficheur
// Broche du capteur de mouvement
const int pirPin = 2;
// Serveur web asynchrone
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
// Initialisation de l'afficheur LCD
lcd.begin(16, 2);
lcd.print("Initialisation...");
// Connexion au réseau WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connexion au WiFi en cours...");
}
Serial.println("Connecté au WiFi!");
// Configuration des routes du serveur web
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
String html = "<html><body>";
html += "<h1>État du capteur de mouvement</h1>";
if (digitalRead(pirPin) == HIGH) {
html += "<p>Mouvement détecté!</p>";
} else {
html += "<p>Aucun mouvement</p>";
}
html += "</body></html>";
request->send(200, "text/html", html);
});
// Démarrage du serveur web
server.begin();
}
void loop() {
if (digitalRead(pirPin) == HIGH) {
Serial.println("Mouvement détecté !");
envoyerNotification();
delay(1000); // Attente pour éviter la répétition rapide des notifications
}
}
void envoyerNotification() {
lcd.clear();
lcd.print("Mouvement Détecté!");
// Vous pouvez ajouter ici le code pour envoyer une notification sur le réseau, par exemple avec HTTPClient
delay(5000); // Afficher le message pendant 5 secondes
lcd.clear();
lcd.print("WiFi Connecté");
}