After a hard day of work, it is finally time to relax. You sit on your couch with your Nintendo Switch controller to play your favorite video game, and you get comfortable. However, within a few seconds, you realize that the TV remote control is out of your reach, and you have to find it. If this has happened to you and you are as lazy as we are, you will like this project.
Systems for music, video, lights, climate, and security have become more intelligent, enabling us to easily operate them from a smartphone or voice assistants. Smart home technology adds convenience, comfort, and peace of mind, and it's cool too! However, many of the commercial systems currently in use exploit our personal information in a concerning manner, giving rise to a range of privacy concerns related to how our personal information is handled.
In this project, we have created a small system to automatically turn on the TV without relying on voice data or cameras. To achieve this, we used the S2GO RADAR BGT60LTR11 as a sensor to detect the presence of people. We have also used an infrared LED transmitter to send control commands to the TV.
The next figure shows the layout of the room, with the couch approximately 2.5 meters away from the television. The idea is to place the radar pointing towards the front, while the infrared LED points towards the TV. Both sensors will be connected to the XMC1300 board, and it will be powered through a USB port on the television itself.
The infrared LED only needs one terminal to be controlled, while the BGT60 radar needs two, PD and TD, since the latter is working in automatic mode. For more information on how to connect and configure the radar see BGT60LTR11 Radar Shield2Go - Hackster.io.
We only need three terminals of the XMC1300 to drive both devices. We used the Arduino IDE for programming the XMC1300, but controlling the terminals of this kit from this IDE can be a little confusing since the nomenclature differs from traditional Arduino boards. You can find the association between the terminal numbers used by the IDE functions and the physical terminals of the board in the 'pins_arduino.h' file.
To make this process a little easier, we have created a graphical reference shown in the figure below.
Our connection between the BGT60 radar, the IR LED and the board is as follows:
The code has to perform the following actions:
- When the radar detects a change in movement, which means a transition from no movement to movement in the departing direction (toward the couch), the IR emits the command to power on the TV.
- When the radar detects a change in the movement, which means a transition from no movement and movement in the approaching direction (from the couch), the IR emits the command to power off the TV.
To manage the infrared LED we use the IRremote library. This library is not compatible at the time of making this project with the XMC architecture. But we can use a subset if it, for this simply include the "TinyIRSender.hpp" header in the code and use the sendNEC function (our TV supports the NEC format).
The official BTG60 library provides the function getDirection(), that returns one value from three:
enum Direction_t
{
NO_DIR = 0, /**< No direction due to no motion */
APPROACHING = 1, /**< Target approaching */
DEPARTING = 2 /**< Target departing */
};
So, if we use these functions and check between the previous read and the current read, we can detect changes in movement. This seems like something that can be reused in multiple sketches. So, why not apply the old 'Don't Repeat Yourself' (DRY) principle and convert that code into a library?
The libraryThe library we created is called BGT60RadarUtils and provides the aforementioned functionality. It helps reduce some of the boilerplate code when using this sensor.
The library has the following public functions and properties:
void checkStatus();
Bgt60::Direction_t getCurrentDirection();
Bgt60::Direction_t getPreviousDirection();
FunctionPtr StatusFunctions[3][3];
- checkStatus is the function that performs the check to determine if there is a change in the movement's state, which means there is a difference between the current reading and the previous value.
- getCurrentDirection and getPreviousDirection are utility functions that return the previous and current readings.
- StatusFunctions is a matrix property that holds a reference to the methods that will be executed when a state change is detected. By default, it holds a reference to an empty function, so if no function is provided, nothing happens.
The library works by checking any time the checkStatus function is executed. If this is the case, it executes the corresponding function in the status matrix.
To specify the functions that will be called when a change of status occurs, we need to provide the callback functions. For that purpose, we can use the following reference matrix.
For example, if we want to do something when the state change from no movement to approaching or departing states we can perform the following:
radar.StatusFunctions[Bgt60::NO_DIR][Bgt60::DEPARTING] = &Fun1;
radar.StatusFunctions[Bgt60::NO_DIR][Bgt60::APPROACHING] = &Fun2;
And then declare the callback functions:
void Fun1(){Serial.println("From no movement to departing");}
void Fun2(){Serial.println("From no movement to approaching");}
The library is open source and freely available at the following link: BGT60RadarUtils.
ResultsThe final device is shown in the following figure.
The following video shows a demonstration of the device in operation.
We hope you enjoy this project and do not forget to leave your comments and feedback!
Comments