Build a Smart Lighting System
Smart lighting systems automatically control lights based on occupancy, ambient light levels, schedules or smartphone commands. They improve convenience, reduce electricity consumption and form an essential part of modern smart homes and smart buildings. This project demonstrates how to build a Wi-Fi-enabled lighting controller using an ESP32 microcontroller, light sensors, motion detectors and relay modules.
Project Overview
The controller continuously monitors ambient light using an LDR or digital light sensor while simultaneously detecting movement using a PIR sensor.
When the surrounding area becomes dark and motion is detected, the system automatically switches on the lights. After a preset period with no movement, the lights switch off to save energy.
An ESP32 can also provide remote monitoring and control through a web page, mobile application or home automation platform.
Project Difficulty
| Item | Value |
|---|---|
| Difficulty | ⭐⭐⭐ Intermediate |
| Build Time | 4–8 Hours |
| Supply Voltage | 5 V or 12 V DC |
| Controller | ESP32 or Arduino |
| Communication | Wi-Fi / Bluetooth (Optional) |
Main Sections
| Section | Function |
|---|---|
| ESP32 Microcontroller | Controls the entire system. |
| Light Sensor | Measures ambient brightness. |
| PIR Motion Sensor | Detects human movement. |
| Relay Module | Switches lighting circuits. |
| Manual Override Switch | Allows manual operation. |
| Wi-Fi Interface | Provides remote monitoring and control. |
Typical Components
| Quantity | Component |
|---|---|
| 1 | ESP32 Development Board |
| 1 | PIR Motion Sensor (HC-SR501) |
| 1 | LDR Module or BH1750 Light Sensor |
| 1–8 | Relay Module |
| 1 | 5 V Power Supply |
| 1 | Push Button (Manual Override) |
| Several | Status LEDs |
| 1 | Project Enclosure |
How the System Works
The light sensor continuously measures the ambient illumination.
When the measured light level falls below a user-defined threshold, the system becomes ready to activate the lighting.
If the PIR sensor detects movement, the ESP32 energises the relay to switch on the lights.
A timer starts immediately. If no additional movement is detected before the timer expires, the lights are switched off automatically.
Optional Wi-Fi connectivity allows lighting schedules, remote control and energy monitoring through a web interface or smartphone application.
Typical Features
| Feature | Description |
|---|---|
| Automatic ON/OFF | Lights respond to motion and darkness. |
| Manual Override | Allows conventional switch operation. |
| Brightness Threshold | Adjustable activation level. |
| Delay Timer | Adjustable switch-off delay. |
| Wi-Fi Control | Operate lights remotely. |
| Scheduling | Automatic operation at preset times. |
Applications
- Smart homes.
- Hallways and staircases.
- Garages.
- Outdoor security lighting.
- Warehouses.
- Office buildings.
- Schools.
- Energy-saving automation systems.
Testing
- Verify the power supply voltage.
- Check communication with the ESP32.
- Cover the light sensor to simulate darkness.
- Walk in front of the PIR sensor.
- Verify that the relay activates.
- Observe the automatic switch-off delay.
- Test manual override.
- Verify Wi-Fi operation if implemented.
Troubleshooting
| Problem | Possible Cause |
|---|---|
| Lights never switch on | Incorrect sensor wiring or relay fault. |
| Lights stay on continuously | PIR sensitivity too high or timer setting incorrect. |
| False triggering | Heat sources or sensor positioned incorrectly. |
| Wi-Fi unavailable | Network configuration problem. |
| Relay chatters | Unstable power supply or software issue. |
Project Improvements
- Add dimming using PWM LED drivers.
- Integrate with Home Assistant or MQTT.
- Support voice assistants such as Google Assistant or Amazon Alexa.
- Add sunrise and sunset automation.
- Monitor power consumption.
- Include occupancy statistics.
- Add Bluetooth commissioning.
- Control multiple lighting zones independently.
Skills Learned
- Motion sensing.
- Ambient light measurement.
- Relay control.
- ESP32 programming.
- Wi-Fi networking.
- Home automation.
Safety Notes
- Disconnect mains power before wiring relay outputs.
- Use relay modules rated for the connected load.
- Keep mains wiring separate from low-voltage electronics.
- Install suitable fuses or circuit breakers.
- Use insulated enclosures for all mains-voltage connections.
Key Points
- Smart lighting automatically controls lights based on environmental conditions.
- PIR sensors detect occupancy while light sensors prevent unnecessary daytime operation.
- ESP32 adds Wi-Fi connectivity for remote monitoring and automation.
- Automatic lighting improves convenience, security and energy efficiency.
- Smart lighting systems are among the easiest and most practical IoT home automation projects.