Controlling home stuff with internet is fun. we can control anything from fan, light, AC or whatever that’s run on electricity with EPS8266. In this ESP8266 tutorial we will see how to control Light and Fan from anywhere using ESP8266. We will be using Blynk App server. The benefit of using Blynk is you don’t need to be on same network. You can control your home light & fan from anywhere in the world. So let’s get started.

ESP8266 control nodemcu relay anywhere from the world

Components Required:
  1. NodeMCU ESP8266 12E,
  2. Relay module,
  3. 4 AAA 1.5V Battery Case,
  4. AAA 1.5V Battery,
  5. Breadboard,
  6. Jumper Wire.
How to Power NodeMCU Relay:

If we try to supply power directly from NodeMCU ESP8266, it will not work as it supply only 3.3V and relay needs 5V. So, we will provide separate 5V battery connection for relay, as a result nodeMCU has no load of relay. I am using 4 AAA battery each 1.5V, which will provide 6V to relay. Make sure you connect NodeMCU ESP8266 ground to battery ground.

Required Library:

Before adding library, I would suggest first setup your Arduino IDE for ESP8266.

Blynk Library:

After setting up your Arduino IDE, Go to Sketches → Include libraries → manage libraries → type Blynk and then Install.

Downloading Blynk Library

Installing Blynk Library

Circuit Diagram:

nodemcu relay circuit diagram

Set up Blynk App:

Step 1: Download Blynk from PlayStore.

Step 2: Register with email ID where you will receive “Auth Token”.

Step 3: Open New Project and name the project.

Step 4: Choose device “ESP8266”. Click on create.

Creat Project in Blynk App

Step 5: After creating project you will receive email, which contain “Auth Token”.

Step 6: Copy this “Auth Token” and paste in our Arduino Code.

char auth[] = "";

Make sure before uploading code, insert your SSID and password. Also check you have selected NodeMCU board and correct port.

Create Buttons in Blynk App:

Step 1: Slide left side, You can see widget box. Click on Button.

Create Button in Blynk App

Step 2: Add buttons as many as you want. But there is limit in app you can spend only 2000 points and one button is for 200 points. Adjust & Resize buttons.

Two button Created

Step 3: Click on button you want to set for output (Fan/Bulb). Select mode you want push or switch. In our case it is switch. Define digital pin GPIO4 for Bulb. Similarly click on second button and define digital pin GPIO5 for Fan.

Select Pin Number for Button

Step 4: After setting up buttons output. click on play icon. Now you are ready to control anything from anywhere in the world. make sure you inserted your “Auth Token” in Arduino code before uploading  and insert your network credential.

Note: Auth Token- you will receive in registered email as soon as you create project. It is different every time you create new project.

click on play button

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "afrsgdffdgdgd";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Your_SSID";
char pass[] = "Password";

void setup()
// Debug console

Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

void loop()
// You can inject your own code or combine it with other sketches.
// Check other examples on how to communicate with Blynk. Remember
// to avoid delay() function!

I hope you like this ESP8266 project, Please subscribe to my YouTube channel for latest update.