#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
// Définition des broches
const int motionSensorPin = 15;
const int lightRelayPin = 16;
const int lightSensorPin = 34;
// Définition des variables
int lightValue = 0;
int motionValue = 0;
// Définition des informations de connexion WiFi et Blynk
char auth[] = "4MNAKp7Ixqo6_VckXOMrK4NA0jSSvOHC";
char ssid[] = "hani";
char pass[] = " 1111";
// Initialisation de Blynk
void setup()
{
Serial.begin(9600);
pinMode(motionSensorPin, INPUT);
pinMode(lightRelayPin, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
// Fonction pour lire la valeur de la luminosité
int readLightSensor()
{
int lightValue = analogRead(lightSensorPin);
return lightValue;
}
// Fonction pour lire la valeur du capteur de mouvement
int readMotionSensor()
{
int motionValue = digitalRead(motionSensorPin);
return motionValue;
}
// Fonction pour contrôler l'éclairage de rue
void controlStreetLight()
{
int lightValue = readLightSensor();
int motionValue = readMotionSensor();
if (lightValue < 500 && motionValue == HIGH) {
digitalWrite(lightRelayPin, HIGH);
Serial.println("Street light ON");
}
else {
digitalWrite(lightRelayPin, LOW);
Serial.println("Street light OFF");
}
}
// Boucle principale
void loop()
{
Blynk.run();
controlStreetLight();
delay(1000);
}