Éclairage public adaptatif — fusion de capteurs, commande PWM, télémétrie Firebase et supervision Node-RED
Adaptive public lighting node — sensor fusion, PWM control, Firebase telemetry & remote Node-RED supervision.
IoT · Sensor Fusion · PWM · Cloud Telemetry · Realtime Dashboard · Embedded C++
A public streetlight runs at the same power at 3 AM in an empty street as it does at 9 PM during rush hour. This project addresses that with an autonomous IoT node built around an ESP32: the LED brightness adapts in real time to ambient light, human presence, and weather conditions — entirely on-device, no remote configuration required.
Sensor data drives a PWM command. The cloud and dashboard come on top, for supervision and remote override — not for the core decision loop.
| Capteurs / Sensors | LDR · PIR HC-SR501 · DHT22 (T° + humidity) |
| Actuateur / Actuator | 8-bit PWM LED — 5 brightness levels |
| Affichage local / Local display | 16×2 I²C LCD — live sensor readout |
| Cloud | Firebase Realtime Database — telemetry every 2 s |
| Supervision | Node-RED dashboard + remote LED override |
The decision runs every 500 ms in two stages.
Stage 1 — Weather override. Fog or mist conditions force the lamp to a fixed high brightness regardless of ambient light or motion. Road safety takes priority over energy savings.
| Condition | Alert | LED |
|---|---|---|
| T < 0 °C and RH > 95 % | Fog | 100 % |
| T < 2 °C and RH > 90 % | Mist | 80 % |
Stage 2 — Adaptive brightness. When no weather alert is active, the LDR reading is mapped to four regimes. A PIR detection raises power to the "with motion" level and starts a 30-second latch — the lamp holds that level for 30 s after the last detection before stepping back to idle. Without this latch, the lamp would flicker every time someone walks past and the PIR briefly drops its signal.
| Luminosité / Ambient light (LDR) | Régime / Regime | Avec mouvement / With motion | Veille / Idle |
|---|---|---|---|
| ≥ 800 | Jour / Daylight | 0 % | 0 % |
| 500 – 799 | Aube / Dawn – dusk | 60 % | 40 % |
| 200 – 499 | Crépuscule / Twilight | 80 % | 60 % |
| < 200 | Nuit / Night | 100 % | 80 % |
+------------------+ +--------------------+ Wi-Fi +----------------+
| Capteurs | | ESP32 | <-------> | Firebase RTDB |
| Sensors | -----> | | | |
| DHT22 (T + RH) | | sensor read | | /DHT22/Temp |
| LDR (light) | | PWM logic | | /DHT22/Hum |
| PIR (motion) | | LCD refresh | | /LED_Status |
+------------------+ | Firebase push | +-------+--------+
| | |
+------------------+ +---------+----------+ v
| LCD 16×2 I²C | <-------| | +----------------+
+------------------+ | | | Node-RED |
v | | dashboard |
+---------+ | +----------------+
| LED PWM | |
+---------+ |
Node-RED flow: timed HTTP requests pull T° and humidity from Firebase; a toggle switch writes back to /LED_Status for remote override.
Node-RED dashboard: live temperature (24.8 °C) and humidity (80 %), historical charts, and remote LED toggle.
| Composant / Component | Référence / Reference | Broche ESP32 / Pin |
|---|---|---|
| Microcontrôleur | ESP32 DevKit v1 | — |
| Capteur T° + HR | DHT22 | GPIO 5 |
| Capteur luminosité | LDR + 10 kΩ divider | GPIO 32 |
| Capteur mouvement | HC-SR501 PIR | GPIO 23 |
| Sortie LED | High-brightness LED | GPIO 4 |
| Afficheur local | 16×2 LCD + PCF8574 I²C (0x27) | SDA / SCL |
- Arduino IDE 2.x + ESP32 board support (Espressif)
- Libraries:
FirebaseClient(mobizt) ·DHT sensor library(Adafruit) ·LiquidCrystal_I2C
cp src/config.example.h src/config.h
# Fill in src/config.h with your own values#define WIFI_SSID "your_ssid"
#define WIFI_PASSWORD "your_password"
#define DATABASE_URL "https://your-project-default-rtdb.firebaseio.com/"
#define DATABASE_SECRET "your_firebase_secret"config.h is listed in .gitignore — it will never be committed.
Open src/pfa1.ino in Arduino IDE → select ESP32 Dev Module → Upload. Serial monitor at 115200 baud.
The same firmware runs in Wokwi without any physical hardware. Set WIFI_SSID = "Wokwi-GUEST" and WIFI_PASSWORD = "" in your local config.h. Import src/diagram.json to recreate the full circuit.
esp32-smart-lighting/
├── src/
│ ├── pfa1.ino # Firmware principal / Main firmware
│ ├── config.example.h # Template credentials
│ └── diagram.json # Wokwi circuit (optional)
├── docs/
│ └── images/ # Photos hardware + captures
├── .gitignore
├── LICENSE
└── README.md
Projet de Fin d'Année — ENSIT Tunis · Génie Électrique · 2024–2025




