Wi-Fi Wireless Power Switch
Like many of the projects that we put together, this one came about because someone asked ‘can you make an Arduino do this?’ In this case, we had a request for a combination of the RTC Power Point Timer and the Wi-Fi Environmental Datalogger. We figured it sounds handy, and since everything is better with Wi-Fi, we got it working. The Arduino serves up a basic webpage which can be viewed on a computer or phone, and clicking links on the page triggers the Arduino to send a signal like the remote from the wireless remote.
WIFI Wireless Power Switch.zip Project Folder
The hardest part of the build here is assembling the 433MHz Transmitter module onto the Prototyping Shield. We started by soldering the 433MHz Module in place, and gently bending it over so it would fit under the Wi-Fi Shield.
Then we made the wire connections. The loose end of the fourth wire should be insulated and let hang free. We threaded it through one of the mounting holes in the shield to stop it flexing too much. Note that because of the antenna, three wires go to pins on the Proto Shield, but four wires go to the 433MHz Module. The 17cm length gives a basic quarter wave antenna for 433MHz, but you might find a longer antenna works better.
Here are the connections:
|Proto Shield||433 MHz Module||Function|
|No Connection||ANT||Attach a 17cm length of wire here.|
The final step is to assemble the Proto Shield onto the Leonardo, then attach the Wi-Fi shield to the top of the Proto Shield. Ensure that the two white switches in the blue housing a both in the ‘ON’ position.
Sketch and Use:
The code is designed to work with the Leonardo board- the separate hardware and USB serial ports make debugging the Wi-Fi shield easier. We wouldn’t recommend trying to port it to the Uno. There are no external libraries to install. The code will need to be customised to suit your Wi-Fi network by changing these parameters:
#define SSIDNAME "SSIDNAME"
#define SSIDPWD "SSIDPASSWORD"
The SSID (Wi-Fi network name) and password should be set to those of the Wi-Fi network you will use. After this change, select the Leonardo board and correct serial port, and upload the sketch. Open the serial monitor, and watch the debug information that is displayed.
The above shows a successful initialization. There might be a few 0’s instead of 1’s, but as long as there are mostly 1’s and the ‘STAIP’ parameter is a valid IP address on the network you are using, then it is configured correctly.
Now try to access the IP address from a browser; the page should look like this:
The status line at the bottom might show different values, and the links will probably be blue as they are ‘unclicked’. Try clicking on a link to test that the individual buttons work. You should also see in the serial monitor debug information about the link being clicked.
The next step is to program the Mains Outlet to respond to these signals. The links on the webpage correspond to the buttons on the remote, so you can follow the instructions for pairing, except by using the webpage links.
Unplug the Mains Outlet, wait a few seconds, then plug it back in and while its LED is flashing, press the ‘ON’ switch of the number you want it to be. Note that the Arduino and the remote will have different pairing codes, so the remote will need to be paired separately (each Mains Outlet can be paired with up to three remotes, and they are not erased until told to do so). If you consider that the webpage is just another remote, then the instructions for the Mains Outlet can be applied to add and remove remotes.
Alternatively, the RTC Power Point Timer project has information about reading the code from the remote (some soldering required!) If you need to change the code to either avoid interference or match an existing remote, it can be changed in this line of the code:
const unsigned long address=0x12340;
This should work with any 5 nybble hex value (but we haven’t tested them all).
This is a simple tool as built, but can of course be extended. The PROGMEM character array defined by the lines following:
const char PROGMEM pg=
Defines the content of the webpage that is delivered by the Arduino. The first line is the HTTP header and should not be changed, but the rest is just a standard html document. If you are comfortable editing html, you can change this, just remember that the links have the ‘?A’ – ‘?J’ query parameter to activate the commands. Also check that the data doesn’t get too long, as the Wi-Fi Shield can’t send more than 2048 bytes per command.
As you might imagine, if an Arduino can serve up webpages, it should have no trouble fetching webpages, and then you can use another Arduino to control the Wi-Fi Wireless Power Switch. While this might look like overkill, you could operate a Mains Outlet from much further than Wi-Fi range by linking into a wired network.
Given that the commands are issued by query parameter, there is no reason extra commands cannot be added. For example, a delayed turn-off like a sleep timer would be quite useful, or even a pre-programmed sequence could be activated to operate something like Christmas lights.
The code is quite long, so is included in the project zip file.