Automatic and Remote Controlled Light Switch

By SeungJun Cho

Overview:

This project will turn a manual light switch into an automatic one, which will turn on the light upon entry to the room if the room is too dark, as well as having remote control functionality through Bluetooth to remotely turn on and off the light. To accomplish this, I will use the STM32L476 board with a combination of an ultrasonic sensor to detect the door opening, a light sensor to detect the light levels inside the room, a Bluetooth module to remotely connect to a phone, and a servo to press the physical light switch. As time permits, I will add a light dimming functionality to the remote, using another servo and a 3D printed part that will allow the servo to move the slider on the light switch up and down.

Code Github Repository:

https://github.com/scho01/Automatic-and-Remote-Controlled-Light-Switch

Block Diagram:

State Machine:

Project Demo:

Project Demo Explanation:

0:00 ~ 0:19 - State 0: Demonstration of the use of RTC, light sensor does nothing before the clock hits 4 PM.

0:19 ~ 0:21 - State 1: After 4 PM, I turned off the lamp I was using as a substitute for sunlight, triggering the signal indicating that the sun has set.

0:21 ~ 0:26 - State 2: Upon receiving this signal, the IR sensor began checking for movement within the room and found my waving hand behind the camera. Following this, PWM signals were sent to the servo, which flipped the physical light switch.

0:26 ~ 0:38 - State 3: The ultrasonic sensor (mounted at the top of the door frame) begins checking for large changes in position. When the change is found, after a ~10 second delay (for opening, closing, and leaving the door) the ultrasonic sensor enables the IR sensor again for around 3 seconds. If movement is not found again during this time period, the light sensor is checked whether there is light within the room. If light is found, the light switch is turned off, and the light switch is left alone if it was already off.

0:38 ~ 0:52 - State 3 (Alternate Version): Same as the previous part, except this time movement is found. The light sensor this time checks whether there is sufficient light within the room. If light is not found, the light switch is flipped, and if light is already in the room, the light switch is left alone.

0:52 ~ 1:00 - Grabbing laptop for Bluetooth communication.

1:00 ~ 1:06 - Bluetooth Interrupt "OFF": Sending the character 'b' to the STM32 resets the entire system except for the RTC clock. The light switch is turned off if it isn't already, and the system does nothing until the next time the clock hits 4:00 PM.

1:06 ~ 1:10 - Bluetooth Interrupt "ON": Sending the character 'a' to the STM32 turns on the light switch if it isn't already, then the system jumps to State 3, regardless of what state it was in before.