Smart-Lighting-ESP32

๐Ÿ’ก Smart Lighting ESP32

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.

๐Ÿ“Œ Project Overview

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.

โœจ Features

๐Ÿค– Automatic Lighting

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.

๐ŸŒž LDR Light Detection

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

๐Ÿšถ Motion Detection

An ultrasonic sensor is used to detect nearby movement.

Current configuration includes:

These values can be adjusted in the ESP32 code.

๐ŸŽค Voice Control

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.

๐ŸŒ Web Control

A modern web interface allows the user to control the light remotely.

Available controls include:

๐Ÿ“ฑ Blynk Control

The project integrates with Blynk for remote monitoring and control.

Blynk can be used for:

โ˜๏ธ Firebase Integration

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.

๐Ÿงฐ Hardware

The prototype shown in the project uses an ESP32 with sensors and an LED connected through a breadboard.

Main Components

๐Ÿ”Œ Pin Configuration

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.

๐Ÿ› ๏ธ Technologies

๐Ÿง  System Logic

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

๐Ÿ’ก LED Brightness Control

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

๐Ÿš€ Getting Started

1. Install Arduino IDE

Install the Arduino IDE and add ESP32 board support.

2. Install Required Libraries

The project uses libraries including:

WiFi
WebServer
HTTPClient
ArduinoJson
BlynkSimpleEsp32

3. Configure Wi-Fi

Update the Wi-Fi configuration in the ESP32 source code:

#define WIFI_SSID "YOUR_WIFI_NAME"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"

4. Configure Firebase

Add your Firebase Realtime Database configuration using your own credentials.

5. Configure Blynk

Add your own Blynk Template ID, Template Name, and Auth Token.

6. Connect the Hardware

Connect the ESP32 and sensors according to the pin configuration above.

7. Upload the Code

Open the main .ino file in Arduino IDE and upload it to the ESP32.

8. Access the Web Interface

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.

๐Ÿ“ Project Structure

Smart-Lighting-ESP32/
โ”‚
โ”œโ”€โ”€ SmartControl.ino
โ”œโ”€โ”€ main_py copy.ino
โ”œโ”€โ”€ SmartControl.html
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ Demo Video

๐Ÿ” Security Note

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.

๐Ÿ“š What I Learned

This project helped me practice:

๐Ÿ‘จโ€๐Ÿ’ป Author

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.