An IoT-based Smart Lighting System built with ESP32, combining automatic lighting, motion detection, ambient light sensing, voice control, and remote monitoring.
The system can automatically control an LED based on motion and surrounding light conditions, while also providing manual control through a web interface and Blynk.
This project is designed to provide an automated and remotely controlled lighting system using an ESP32 microcontroller.
It combines multiple control methods:
The system supports both automatic and manual operation.
The ESP32 continuously monitors:
When motion is detected and the environment is dark, the LED can automatically turn on.
The system also supports automatic shut-off after a configurable period.
The LDR sensor measures the surrounding light level.
A configurable threshold determines whether the environment is considered bright or dark.
LDR Reading
โ
โโโ Bright โ Light OFF
โ
โโโ Dark
โ
โโโ Motion detected โ Light ON
An ultrasonic sensor is used to detect nearby movement.
Current configuration includes:
These values can be adjusted in the ESP32 code.
The system supports voice/sound-based control using a microphone module.
Voice activity can be detected locally, while voice commands can also be integrated through Firebase.
The system includes timing and signal thresholds to reduce accidental triggers.
A modern web interface allows the user to control the light remotely.
Available controls include:
The project integrates with Blynk for remote monitoring and control.
Blynk can be used for:
Firebase Realtime Database is used to synchronize system information and commands.
The ESP32 can send information such as:
Firebase can also be used to receive voice-control commands generated by an external application.
The prototype shown in the project uses an ESP32 with sensors and an LED connected through a breadboard.
| Component | ESP32 Pin |
|---|---|
| Ultrasonic TRIG | GPIO 5 |
| Ultrasonic ECHO | GPIO 18 |
| LDR | GPIO 36 |
| LED | GPIO 33 |
| Voice Sensor DO | GPIO 19 |
| Voice Sensor AO | GPIO 34 |
Pin assignments can be changed in the source code if your hardware wiring is different.
The lighting logic prioritizes different control sources:
โโโโโโโโโโโโโโโโโโโ
โ ESP32 โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โ โ โ
Ultrasonic LDR Voice Sensor
โ โ โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โ
Lighting Logic
โ
โโโโโโโโโโโโโโดโโโโโโโโโโโโโ
โ โ
Automatic Mode Manual Mode
โ โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
LED + PWM
โ
โโโโโโโโโโโโดโโโโโโโโโโโ
โ โ
Web Control Blynk App
โ โ
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
Firebase
The LED brightness is controlled using PWM with an 8-bit resolution, providing values from:
0 โโโโโโโโโโโโโโโ 255
OFF 100%
Example brightness levels used by the web interface:
| Level | PWM |
|---|---|
| OFF | 0 |
| 30% | 77 |
| 50% | 128 |
| 100% | 255 |
Install the Arduino IDE and add ESP32 board support.
The project uses libraries including:
WiFi
WebServer
HTTPClient
ArduinoJson
BlynkSimpleEsp32
Update the Wi-Fi configuration in the ESP32 source code:
#define WIFI_SSID "YOUR_WIFI_NAME"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
Add your Firebase Realtime Database configuration using your own credentials.
Add your own Blynk Template ID, Template Name, and Auth Token.
Connect the ESP32 and sensors according to the pin configuration above.
Open the main .ino file in Arduino IDE and upload it to the ESP32.
After connecting to Wi-Fi, check the ESP32 IP address through the Serial Monitor.
Open the IP address in a browser:
http://ESP32_IP_ADDRESS
The Smart Control interface will then be available.
Smart-Lighting-ESP32/
โ
โโโ SmartControl.ino
โโโ main_py copy.ino
โโโ SmartControl.html
โโโ README.md
โโโ Demo Video
Do not upload real Wi-Fi passwords, Blynk authentication tokens, or Firebase credentials to a public GitHub repository.
Before publishing this project, replace credentials with placeholders such as:
#define WIFI_SSID "YOUR_WIFI_NAME"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
#define BLYNK_AUTH_TOKEN "YOUR_BLYNK_TOKEN"
#define FIREBASE_HOST "YOUR_FIREBASE_HOST"
If real credentials have already been committed to GitHub, they should be revoked/rotated before making the repository public.
This project helped me practice:
Ziad Sayed Ahmed (Zico)
Junior Data Scientist / Software & IoT Project Developer
Skills: Python ยท SQL ยท Power BI ยท Machine Learning ยท C++ ยท ESP32 ยท IoT
โญ A practical ESP32 IoT project combining sensors, automation, web control, and cloud connectivity.