Introduction: WiFi Relay Outlet-DIY
Nowadays, most popular IoT experimenter kits comes as modules that just plug together rather than individual components. Electronic newbies, practicing engineers, and experienced hands alike are sure to find that these inexpensive modules interesting. In this guide, I show you how to take an ordinary wall outlet and add intelligence using a bunch of readily available and easy to use pre-wired modules. As I have designed this project in a sort of a modular fashion, you can try to build the whole project as it is or parts of it or even extend this project with more functionality. Well, get ready to add enhanced accessibility, intelligence, and connectivity to your ordinary wall outlet.
Step 1: Key Hardware
ESP8266 WiFi (5V/1 Channel) Relay Module x1
Hi-Link HLK-PM01 (5V/3W) SMPS Module x1
The first thing – WiFi Relay Module is infact a stark blend of an ESP8266 (ESP-01) WiFi SoC, an onboard 3.3V regulator IC (AMS1117-3.3), an STC15F104 microcontroller, and a 5V SPDT (1C/O) relay. The ESP8266 WiFi SoC is a plug-in type card with an 8-pin header, and the 4-pin header at the edge of the Wifi Relay Module works as a simple interface to setup/configure the WiFi Relay Module with the help of your PC. The second thing is a compact AC-DC power supply module offers stabilized 5V/600mA dc output from the usual AC230V household mains supply input. This sealed power supply module (conforms to UL, CE requirements) is particularly devised for IoT devices/projects.
Step 2: Device Hardware Setup
As can seen from the wiring diagram shown below, the hardware setup is extremely simple and requires only little solder work. Beware, as soon as L / N (~ 230V) is connected and mains voltage is applied, do not touch the naked device!
Please keep in mind that without a proper enclosure, any mains-connected device is unsafe to use as there’s a chance of accidental fatal electric shock. It is therefore highly recommended to mount the assembled hardware inside a shock-proof ABS/Grounded Metal enclosure, ofcourse with enough vent-holes.
Step 3: Debugging Software
Before first use, the WiFi Relay module should be configured with the help of a ‘3.3V Level USB to TTL adapter’ and the ‘USR-TCP232-Test-V1.3’ proprietary serial debugging software. For this, connect TX-RX-GND pins of the USB to TTL adapter to RX-TX-GND pins of the 4-pin header (see next figure). Also remember to power up the device, and to establish a baud rate of 9600. Next, open the Serial Debugging software (USR-TCP232-Test-V1.3) on the PC to send all requisite AT commands listed below.
If it not returns OK and just return what command you’ve sent, then press ENTER key first before sending AT commands (for example AT+RST > ENTER > SEND). Take note, the module need to reconfigure if restart i.e. you need to refresh the module through serial debugging software by sending certain serial commands. In short, the CIPMUX and CIPSERVER must be applied again!
Step 4: The Android App
For remote control using an Android smartphone, you need to download and install the free ‚EasyTCP (v4.4)‛ Android app on your smart phone
Next, open the app, click ‚Connect‛ and enter the ‚IP address‛ (192.168.4.1) and ‚Port‛ (8080). Press and hold a switch button to enter the name and content of the serial command in hex format (A00101A2 relay_on, A00100A1 relay_off). Finally you can send serial commands from the app for relay control using the pre-defined button switch. Here, the maximum signal coverage of the system working in AP (access point) mode is fairly close to 400 metres in open environment.
Step 5: Addendum
Something I do not Like: When I saw the Wi-Fi Relay module (LC-WM-Relay-8266-5V) on eBay first, I was rather surprised by its simplicity/footprint and hence ordered a couple of them in a rush. However, after some experiments I was quite disappointed by an exasperating issue. Since TCP server will not save into flash, it needs reconfiguration of AT commands after each and every power cycling/ reset/restart. So I abandoned the idea of building a successful end-user product for my lovely neighbor, as that calls for an yearlong uninterrupted power supply system. Else I must take steps to replace the stock firmware of the STC15F104 microcontroller (http://www.stcmcu.com/datasheet/stc/STC-AD-PDF/STC15F101E-series-english.pdf) with another program to send that commands from the uC on each start up (a harsh penalty). Hope somebody will think over this and let me know if there is any workable solution.
For jail breaking the Wi-Fi Relay Module, you will need an STC programmer, and the STC ISP or the alternate stcgal. Here’s the link of a similar idea: In addition, I purchased some MCU STC15F104W Development Boards from a Chinese vendor very recently. Just another little surprise is in the wings (wait for it)!