Low Cost 4 channel Wifi switch

Hello everyone, I am going to share my project of wifi switch.

My requirements:

It should incur low cost as far as hardware is concerned.
The device should be reliable as I would be using it to control lights at my home while I am on a vacation.
I should get an update on my mobile once the switch changes state.
Opted Solution:
For the hardware I chose ESP 8266-01 as the wifi and control module from Aliexpress with few other discreet low cost components.
A four channel relay board from NSK electronics India.
A 12-0-12, 500 milliamps transformer that was lying around with me.
For 3.3 volt supply required for the module I used a LM317 three terminal regulator.
The setup:
In this project I am going to use pins GPIO0, GPIO1 (RX pin), GPIO2, GPIO3 (TX pin) pins to control a four channel relay board.
Problems Faced:
During power up if the pins of the ESP8266-01 remain connected to relay board the module hangs and becomes useless, photo coupler on the IO pins even failed to be fruitful but if the unit is powered on without the relay module initially connected everything works nice as expected.
To overcome this situation I used a strange but effective low cost idea. A small analogue delay circuit using 555 timer IC was used to power up the relay module that puts a 10-15 second delay so that the wifi module gets access to network before the relay board gets powered on.

Flashing the ESP is really easy just copy the code from the attachment and open in Arduino (I used version 1.6.8) have the necessary files copied in the libraries folder, select upload speed as 115200 and program the ESP. Regarding procedure to program the module there are lots of tutorials on the internet.

1 Like

@proteek if I’m not mistaken by using the if and else statements in loop() you are repeatedly sending lcd.print() statements to the server i.e. pins 0, 1,2 and 3 will always be HIGH or LOW.

In this sense “repeatedly” means thousands of times a second, if the hardware can work that fast. Unfortunately the server can’t and will lead to an unstable system.

Personally I wouldn’t use if and else in a Blynk loop() but if you feel you must it would be wise to set a flag to ensure the lcd.print() statements are only sent when there is a change of state (High to Low or Low to High).


Yes, I agree that there might be some errors in the code as I am by no means an expert in coding, I am thankful to you for sharing your input, shall try after doing the necessary correction, but as of now I am not facing any problem as far as hardware operation is concerned. Thanks once again for the input.

@Costas can you just help me to implement a flag to send lcd.print() statement only during state change, or just site an example.

@proteek take a look at the sketch in this thread Blynk for Beginners and help with your project

The global variable I use for the flag is:

bool ONstatus = false;

Look through the if statements to see how the ONstatus flag is used to ensure events only happen once etc.

Shout if you need further assistance when you have looked through the sketch.

1 Like

@Costas thanks to you for your support, I was getting intermittently device offline error which got resolved after modifying the code as per your instructions.