Intermediate IoT Project

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.

Smart Lighting System

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

ItemValue
Difficulty⭐⭐⭐ Intermediate
Build Time4–8 Hours
Supply Voltage5 V or 12 V DC
ControllerESP32 or Arduino
CommunicationWi-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

QuantityComponent
1ESP32 Development Board
1PIR Motion Sensor (HC-SR501)
1LDR Module or BH1750 Light Sensor
1–8Relay Module
15 V Power Supply
1Push Button (Manual Override)
SeveralStatus LEDs
1Project 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

  1. Verify the power supply voltage.
  2. Check communication with the ESP32.
  3. Cover the light sensor to simulate darkness.
  4. Walk in front of the PIR sensor.
  5. Verify that the relay activates.
  6. Observe the automatic switch-off delay.
  7. Test manual override.
  8. 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.

Next Project

Continue by building a Smart Home Security System, combining motion sensors, door contacts, cameras and Wi-Fi notifications to protect your home in real time.

Next Project → Smart Home Security System