As a result of moving back home from campus due to COVID-19, the light dimming slider idea will be postponed until Fall, as the light switch I have at home does not have dimming capabilities. Instead, I will begin implementing other functionalities using logic gates and MOSFETs, such as:
Adding more IR sensors and using OR gates to combine the outputs together and increase sensor up-time (the IR sensors I am using have a minimum 5 seconds of inactivity after sending the high pulse), as well as improving movement detection.
Implementing a system controlled ON switches using MOSFETs to reduce power consumption in idle states.
At state 0, power to the entire system can be shut off, excluding the STM32 itself and the Bluetooth module.
At state 1, power to the light sensor needs to be enabled. In addition, due to the rather long setup time of the IR sensors (~1 minute), they will also need to remain enabled for the entirety of states 1 through 3, in order to detect movement as fast as possible.
At state 2, power to the light sensor can be disabled. Upon finding movement, power to the servo can be temporarily enabled to flip the light switch, then disabled.
At state 3, power to the ultrasonic sensor should be enabled. Upon finding movement, power to the servo can be temporarily enabled to flip the light switch, then disabled.
The project has been completed up to the base functionalities (See project demo video: youtu.be/YYclaDwrQq0). The state diagram has been updated to match the current model used in the code, and some pictures of the final product has been added.
In the coming months, I may come back to this project and add or change functionalities, such as changing the method of tracking people within the room to GPS using a GPS module, rather than relying on the combination of the ultrasonic and IR sensors. This would mean that visitors would not be considered, making it less useful for common areas like the living room, but for a private space like a bedroom, it would likely be more convenient. I will keep adding updates whenever I work on the project.
Finished soldering light sensor pins, as well as extending the wires for all of the components that needed extensions. I also finished all of the coding for the initialization of the GPIO pins, as well as for the RTC clock. I will need to check which clock I will be using for the system clock, but I will likely end up using the default.
While beginning to translate my main function pseudocode into actual code, new potential problems arose, such as the possibility of a person flipping the light switch manually. I decided to fix this issues by combining the "lightlv" variable with the "light" variable (see state machine from previous update), and making the light sensor check if enough light is in the room whenever movement is found by the IR sensor.
Another issue I thought of, was if the RTC clock became off from the real time (due to power outage, or pressing the reset switch on the STM32, etc.). I fixed this temporarily by removing the RTC clock display, changing the clock to a purely internal clock that only uses the time as a reference, as well as setting the time upon the reset button being pressed to 6 PM. I chose 6 PM as the reset time, because only time you would notice that the RTC was off would be if the room became dark after sunset, and the light never turned on, upon which you could now press the reset switch, and the project would begin checking for sunset 2 hours before the room gets too dark starting the next day. For a longer term solution, however, I would like to implement a time correction/editing system using the bluetooth connection.
I finished configuring initialization for the GPIO pins in the code. Attempted to test servo functionality again, but realized the servo I wanted to use was attempting to pull too much current while it was powered on, so I will need to procure an external power source, likely using batteries. Will need to solder on the pins for the light sensor, but other than that, the wiring for the project is finished temporarily (ready to be tested). The wiring will need to be redone for the final product to clean it up and extend the wire length for certain sensors. While a bit difficult to tell from the image, each of the GPIO pins have been mapped to the specific functions as follows :
PE8 - TIM1_CH1N (servo motor control PWM signal)
PA0 - TIM5_CH1 (ultrasonic sensor echo input capture)
PA5 - TIM8_CH1N (ultrasonic sensor trigger PWM signal)
PA1 - GPIO Input (IR sensor output receiver)
PA2 - USART2_TX (bluetooth module TX pin)
PA3 - USART2_RX (bluetooth module RX pin)
PB6 - I2C1_SCL (light sensor SCL line)
PB7 - I2C1_SDA (light sensor SDA line)
Outside of this, all of the components have been wired to share the same ground, as well as receiving output from the 5V output of the STM32 board. However, since the board was indicating current overflow error, I will power some of the components (primarily the servo motor) using an external battery. In addition, I will likely end up adding extra IR sensors later on after testing the project in full using the single sensor for now.
I finished creating and updating a state machine that describes what the project will be doing on a daily basis as it runs. I decided to include the STM32's RTC clock as a method of power saving, making the reset state into a "do nothing, low power" state until the clock reads 4PM. I also added another type of sensor, the IR sensor, in order to help detect people inside the room, rather than relying purely on the opening and closing of doors to account for the possibility of more people in the room. After the completion of the state machine, I began translating it into line by line pseudocode for the main function.
I received the light sensor and the servo motor I ordered, then began testing sending PWM signals to the servo. In addition, I bought a part that could potentially work as the physical button pressing lever after some modifications. I started thinking about what pins I should be using for what function, as well as the initialization sequence for the entire project.