As with many smart home ideas, I started with a problem. If I come home late at night and my hands are full (e.g., groceries), it can be tedious to try to turn on the light. Given that I already had a LIFX smart bulb, I looked for LIFX libraries and found lifx-switch-esp32. Having found something plausible, I ordered a PIR sensor and a plastic container from Aliexpress and then waited. Patiently.
A passive infrared (PIR) sensor detects general movement in its range by measuring ambient infrared light radiation. It is commonly seen in motion detectors. Of course, I could have just bought a wireless motion sensor for virtually the same cost but what's the fun in that? In fact, looking through the current offering of smart home devices such as door sensors gave me some interesting project ideas.
The components used and source code can be found on my Github.
The Build
I originally had a LED light connected to the output to check everything is working as intended. Afterwards, it was a pretty straightforward conversion to have the PIR sensor connect back to the ESP32 as an input. I had to connect the LED (-) to any pin and set it as input.
The bulk of my time was spent on rewriting the code from the lifx-switch-esp32 repository to be compilable on the Arduino IDE and some simplification & clean-up.
The case fit the components just fine but it turns out that using a drill on plastic is not the best idea. A dremel would definitely be cleaner.
The default 35 second on-time of the PIR sensor worked well for my purposes so I chose not to do any additional coding. In the future, I could look to implement logic based on time of day to control power or light intensity.