Skip to content

Nour3000/esp32-smart-lighting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESP32 Smart Street Lighting

É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.


ESP32 Arduino Firebase Node-RED


IoT · Sensor Fusion · PWM · Cloud Telemetry · Realtime Dashboard · Embedded C++


Prototype en plein jour — LEDs éteintes Prototype la nuit avec mouvement — LEDs à 100%
Left: daytime — LEDs off (LDR ≥ 800). Right: night with motion detected — LEDs at full brightness.

En bref / At a glance

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

Démonstration / Demo

Simulation Wokwi — crépuscule, LED à 80%
Wokwi simulation: twilight conditions (LDR = 69 lx), no motion → LED at 80%.

Nuit sans mouvement — LED1 à 40%
Night, no motion detected: LED1 at 40% idle level, LED2 off.

Logique d'éclairage / Lighting logic

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 %

Architecture

+------------------+        +--------------------+   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 |    |
                        +---------+    |
Flow Node-RED
Node-RED flow: timed HTTP requests pull T° and humidity from Firebase; a toggle switch writes back to /LED_Status for remote override.

Dashboard Node-RED — T: 24.8°C, H: 80%, LED switch
Node-RED dashboard: live temperature (24.8 °C) and humidity (80 %), historical charts, and remote LED toggle.

Firebase Realtime Database
Firebase Realtime Database: temperature and humidity pushed every 2 s by the ESP32.

Matériel / Hardware

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

Démarrage / Getting started

Prérequis / Prerequisites

  • Arduino IDE 2.x + ESP32 board support (Espressif)
  • Libraries: FirebaseClient (mobizt) · DHT sensor library (Adafruit) · LiquidCrystal_I2C

Credentials

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.

Flash

Open src/pfa1.ino in Arduino IDE → select ESP32 Dev ModuleUpload. Serial monitor at 115200 baud.

Simulation / Wokwi

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.


Structure / Repository

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

Références / References


Projet de Fin d'Année — ENSIT Tunis · Génie Électrique · 2024–2025

About

Adaptive ESP32 street-lighting node — LDR/PIR/DHT22 sensor fusion, PWM control, Firebase Realtime telemetry and Node-RED remote supervision.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors