Tiny Wi-Fi Switch for $3




prtotype




Out of curiosity, I ordered the tiny ESP8266 relay switch from aliexpress.com but never knew it could be so embarrassing to find the right way to operate. The vendor said that the switching program is inbuilt and I only have to use some android phone to operate it. But despite several attempts with several Chinese and English android apps, nothing happened The device gets connected with the WiFi of my PC or laptop as a server, it also allows the dynamic IP address as well but nothing happens after that. No server page etc. opens anywhere!

This frustrated me one day and I decided to install my own program into it!

Target

I reprogrammed the switch to connect to my wifi router with a fixed IP address and a fixed port eg: 192.168.1.99 and 8083 port. Once connected it will behave as a webserver at http://192.168.1.99:8083 The switch will be visible on the browser output. Press the ON or OFF button and it will act. For simplicity, I’ve added a refresh counter and a relay status such that one can know the state of the relay [ON or OFF]

Way forward

Next, in my DSL router, I made a port forward of this 8083 port to the 8083 port of 192.168.1.99 computer [the relay board] when gets connected to it. So now you have reached a state where once you know the external IP address of your router, you can connect it from the other side of the universe! So easy! But the question comes how to know the external IP address of your router? Simple, you ask your son, daughter or your spouse [if not your pet dog !] to open the router admin page, go to the status tab and know the IP address of the router – a common feature of any common DSL router modem.
Like when your laptop, desktop, the mobile phone gets connected to your WiFi, it gets an IP address as the identity of that device on the WiFi network. So is your DSL router when gets connected to the Internet, gets an IP address and that’s the IP address you have to know.

READ  Touch-less Switch

But there is no dearth of the next problems in Bera’s world of electronics! The external IP address of any router changes quite often – 10 times a day is very common! So you need a ‘standing Luisen’ near the modem to tell you 10 times in a day. Soon everybody in your home will run away for sure including your aged parents! You wish you could train your pet to do this work now!

But where there is problem, there is solution! At least in the world of Electronics this is so true. When you can simplify a problem statement – you are actually pushing towards the solution. Fortunately, most common DSL modem has an inbuilt DDNS facility – Dynamic DNS tracking facility. You just supply the DNS host server’s name, DNS name and the remaining authorization details and the Modem will track the changes of external address on its own. You just need to remember the DNS name you have registered with the DNS host server’s site and the port you are forwarding in the modem – in my case, it’s berapi.ddns.net:8083 from noip.com

Now it’s time to call your run away family back to a peaceful sweet dwelling place of yours.

Construction

The basic ESP8266, also called ESP-01 is having 8 pins coming out of the chip board. But if you look carefully, the chip has a total 32 pins. That means for simplicity, on this board the other pins are discarded by the manufacturer. The 5-volt relay is connected to GPIO0 pin through a switching transistor such that when the GPIO0 becomes ‘LOW’ the relay actuates and the relay deactivates when the GPIO0 becomes ‘HIGH’. The board has a common C1117 – 3.3-volt regulator chip on its side. Therefore it can take comfortably up to 7 ~ 9 volt on its Vcc pin.

READ  Connecting Anduino to IFTTT

Programmer

This is really the easiest part of this project. You just need a programmer to program this tiny little wonder! The programmer is nothing but just an way to transfer the Arduino sketch from computer usb port to the ESP8266 chip’s dumb head. FTDI CP2102 board is available at aliexpress for $1.2 only. In case you have an working Arduino UNO board available around, you can use that board still to upload your sketch to the little wonder. The connection for both the types are shown below. In fact, when you short-circuit the Arduino reset pin to the ground – you are just making the Arduino UNO board as an USB to serial uploader like the FTDI CP2120 board !

We have provided a push-to-on switch in both the case, which needs to be pushed for 10 seconds while uploading the sketch and after this 10 seconds it needs to be released and the sketch will upload in another 60 seconds. All the lights on the FTDI chip will blink while the sketch is uploading.

Schematic

Program output

The program sketch is attached herewith. Replace the WiFi ID and password with your WiFi ID and password and then upload the sketch by pressing the ‘upload’ command of the Arduino IDE. [Goto, Sketch → upload ]

Program output

That’s the output of this little wonder, when the sketch gets uploaded and the DDNS & port forwarding is done properly. From anywhere of the world by calling this url in any browser window be it on an android or Apple phone, the relay will behave as per the button press !

READ  Tiny boost regulators deliver up to 10 W

Bill of Materials & Price [aliexpress]

FTDI USB to Serial CD2120 – $1.02 [optional ]
WiFi ESP8266 Relay – $1.85
————————————————–
Total: <$3 [ 5Volt power supply cost is separate ]

Aftermath

The only thing left now is making the connection protected. Otherwise, anyone with the knowledge of this URL will be able to operate the relay, contrary to your choices !

I know you will explore that now! Best of luck.

Download Source Folder




Leave a Comment

*
= 4 + 7

(Spamcheck Enabled)

Read previous post:
NXP’s MMA8451QR1 Accelerometer
NXP’s MMA8451QR1 Accelerometer

Process computer designs usually start out with an accelerometer. As reliability problems creep in, making the switch to a more...

Close
Scroll to top