Introduction: [Home Automation] Control Relays From Everywhere Using ESP8266 + Blynk

About: My hobby is make microcontroller projects.

There are many ways to made a home automation, Some are complicated, Some are easy, This instructable I will show how to make a simple relays control using ESP-12E with Blynk. For convenient the design was single side PCB So you can make by your self at home or even send the gerber file to PCB manufacturer to make it for you.

Step 1: PCB Design

PCB design step is the most important step because if we mistake something in this step the project will not working properly.

As the topic of this instructable, We will use the ESP8266 (ESP-12E) module to drive relays ON/OFF. So we need to understand the ESP8266 specification. If we look in the Electrical Characteristics section in the ESP8266 datasheet we found that

- Supply voltage is 3.3V

- Maximum GPIOs high voltage is 3.3V

- Maximum GPIOs current is 12mA

We will use 5V relays, The supply will be 5V but ESP8266 need only 3.3V So we need some regulator from 5V to 3.3V. For drive 5V relays using 3.3V we need some transistor to gain current and voltage, for minimum numbers of parts I recommend to use transistor array ULN2803. With ULN2803 we can drive upto 8 relays and it has internal flyback diodes for prevent voltage spike when switch OFF inductive load.

Finally I select 1117-3.3 for voltage regulator, ULN2803A for drive relays

Next, ESP8266 Boot mode and Flash mode

From datasheet page 8 to make ESP8266 boot normally you have to apply logic on the pin as below


- LOW on GPIO15

To flash firmware to the ESP8266 you have to apply logic on the pin as below


- LOW on GPIO15, GPIO0

So, I use 10k resistor to pull up and pull down on each pin as described and use push button as RESET and FLASH to allows you to enter each mode easily.

Step 2: Make a PCB

If possible you can send gerber file to PCB manufacturer, but If not we will make it by ourself.

I use heat transfer to make the PCB the steps are:

- Print bottom layer on photo paper.

- Cut plain PCB with the same size with our designed.

- Use iron to transfer the ink from paper to PCB.

- After remove paper dip the PCB into PCB acid etching.

- Cleaning PCB with Thinner to remove ink.

- Drilling PCB

- Etching the PCB

Step 3: PCB Assembly

In the PCB Assembly step, Please carefully about Soldering iron.

In this step I recommend to soldering small device first. If you make PCB by yourself use multimeter to check some narrow track space to prevent electric short.

Step 4: Coding and Flashing

First, On your mobile phone install "Blynk" application, register and login to the application.

After logged in to the application tap "New Project".

Enter project name, select ESP8266 as a device then tap "Create Project".

The application will show message "Auth Token was sent to:".

Tab anywhere on project design, widget box will appears.

Select button then enter LED1 as the button name, Select "GP16" as output from ESP8266(See schematic), Minimun value "0", Maximum value "1", Mode "Switch", Enter ON/OFF labels as you need and tab "OK" button on the top right of the screen to finish settings for the button.

Do the same as above for LED2, LED3 and LED4

Drag the button to everywhere you want.

Tap "Triangle" or "Play" button on the top right of the screen to run the project.

You will notice that your board is offline.

Now let's go to program on the ESP8266 side.

Connect the USB to RS-232 to ESP8266 PCB, Beware the TTL level of USB to RS-232 module, The TTL level must not over 3.6 volts.

To enter flash mode, Push reset button and flash button after that release reset button and then release flash button respectively. If the board is in flash mode the LED1 will "ON".

Go to Blynk website, Download Blynk library and install on your PC.

On Arduino IDE goto File->Examples->Blynk->Boards_Wifi->ESP8266_Standalone.

Change string "YourAuthToken" to your receive token from email.

Change your home ssid and password.

Select the "NodeMCU 1.0" as board.

Select USB to RS-232 module port.

Upload code to board wait until upload complete( LED1 will turn OFF).

Now is ready to control relays from your mobile phone.

Back to the phone the status of the board become "ONLINE".

Tap on each button then the relays will switch ON/OFF as display on you phone.

Good luck.

Step 5:

PCB Contest

Participated in the
PCB Contest