I initiated this project because I frequently forgot to turn off the kitchen lights, which led to complaints from my housemate. To create a more harmonious living environment, I wanted a system that could automatically detect when lights were left on unnecessarily and switch them off on my behalf.
Technical ImplementationTo keep the implementation straightforward using components I already had, I designed the system without external sensors. The CORE S3's built-in camera handles both light detection and motion sensing, while the compact and energy-efficient M5Capsule manages the switching functionality.
Unlike commercial switching products that use adhesive tape or obstruct the switch making it difficult to use manually, I created a custom solution to avoid further complaints. I 3D modeled a complete switch cover attachment that houses both the motor and M5Capsule.
Additionally, since the CORE S3 camera angle is crucial for proper detection, I designed a specialized TiltStand that allows for easy adjustment of the camera direction.
The light detection system employs several sophisticated techniques to ensure reliable operation. I implemented a Region of Interest (ROI) based approach where only a specific area of the camera frame is analyzed for brightness changes. This ROI can be adjusted through the GUI to precisely target the light source.
The motion detection system uses a segment-based approach that divides the camera frame into a grid of 8×6 segments (48 total). Each segment's luminance is calculated independently, and changes between consecutive frames are analyzed to detect motion. This segmentation allows the system to identify localized movements even when the overall frame average might not show significant changes.
The system employs two key thresholds: a per-segment luminance difference threshold that determines if motion occurred in a specific segment, and a segment count threshold that requires multiple segments to detect motion simultaneously before triggering. This dual-threshold approach effectively filters out small, isolated movements (like insects) while remaining sensitive to human presence.
One of the firmware aspects I'm particularly proud of is the GUI implementation on the CORE S3, which allows for convenient adjustment of detection thresholds and other parameters through a settings screen. Have a look at the attached repo for the firmware.
Since the M5Capsule operates on battery power, I carefully optimized the power management to extend battery life. I estimate it should run for about a month between charges, although I haven't had the opportunity to fully verify this due to time constraints.
ResultsThanks to this project, I no longer get scolded for forgetting to turn off lights. However, I did receive a stern lecture for modifying the light switch cover—so proceed with caution if you attempt similar modifications!
Comments