Light controller with PIR sensor

Controller installed on a ceiling light

This is an IoT ceiling light controller which includes an HC-SR501 PIR motion sensor. It is built around a Wemos D1 mini (ESP8266 breakout board), which controls a homemade TRIAC breakout board. TRIACs provide the advantage of switching devices on and off silently, as opposed to a mechanical relay.

The system is powered from the same AC lines as the lights, thanks to an embedded AC-DC converter. This removes the need for an additional power supply.

Please note that handling mains electricity is extremely dangerous. Not only is there a high risk of electrocution, but also porrly designed devices can easily catch fire due to the high electric power involved. Attempt prjects like this one at your own risk.

Due to the configuration of my lights, I had no access to wires that I could easily feed into the system. To circumvent this issue, I hacked a LED lightbulb so as to use its socket to get powr lines out while the output of the controller feeds back int the remaining of the bulb.

The hacked LED bulb

Although Lights triggered by a motion sensor can be bought for cheap, their motion sensor is entirely deidcated to turning the light on and off. Thus, they cannot be used for other applications such as intrusion detctors. With this project, the motion sensor output can not only be used to turn the light on or off but also trigger any action available in my home automation system. Upon detection of movement, an MQTT message is published, which can be listened to by any device subscribed to the corresponding topic.


Main board


The details of the custom TRIAC breakout board are given hereunder.

Parts used:

The firmware running on the ESP8266 is available on GitHub. Its dependencies are as follows: