My journey into the Cloud (5); Control that lamp
Now with what I admit is an unashamedly quick and dirty hack, I rigged up a wireless switch to control my desk lamp. I bought a standard off-the-shelf remote controller with three switched socket outlets from the corner store. Back in the lab Roy, who always makes a much neater job than I ever could, took apart the controller and wired two leads in parallel to one of the ‘on’ push buttons and another two leads in parallel to the corresponding ‘off’ button. One of the two cable pairs were then connected across the contact of relay 0 and the other across the contact of relay 1 on the expansion board. When I send the sequence ‘R 0 1 + [CR]’ followed by ‘R 0 1 – [CR]’ to the SAM board it switches the relay on and off to emulate pressing and releasing the ‘on’ button on the remote controller while the sequence ‘R 0 0 + [CR]’ followed by ‘R 0 0 – [CR]’ does the same for the ‘off’ button.
I programmed the MQTT test Client so that it automatically appends a carriage return character [CR] to the message that comes in. Apart from that it’s necessary to set a baud rate of 9600 on the virtual COM port and activate the DTR signal. You can check out from the source code (see download below) how this has been achieved in C#. Now I can control the lamp in my study from anywhere in the world. However, so could anyone else if they guess the control character sequence (and correct Topic name)! For that reason, once the tests had been successfully carried out I dismantled the test setup.
Why not try out my test Client with electronic switching for yourself? As I mentioned above, there’s no reason why you couldn’t use an Arduino for the job. A Sketch to receive and interpret the character string and switch an output should not be too difficult to implement.
So far we’ve needed a PC and keyboard to enter commands, that of course needs to be changed but more on that next time!
Subscribe
Tag alert: Subscribe to the tag IoT and you will receive an e-mail as soon as a new item about it is published on our website! I programmed the MQTT test Client so that it automatically appends a carriage return character [CR] to the message that comes in. Apart from that it’s necessary to set a baud rate of 9600 on the virtual COM port and activate the DTR signal. You can check out from the source code (see download below) how this has been achieved in C#. Now I can control the lamp in my study from anywhere in the world. However, so could anyone else if they guess the control character sequence (and correct Topic name)! For that reason, once the tests had been successfully carried out I dismantled the test setup.
Why not try out my test Client with electronic switching for yourself? As I mentioned above, there’s no reason why you couldn’t use an Arduino for the job. A Sketch to receive and interpret the character string and switch an output should not be too difficult to implement.
So far we’ve needed a PC and keyboard to enter commands, that of course needs to be changed but more on that next time!
Read full article
Hide full article
Discussion (0 comments)