MEVIHUB

Home Automation Using ESP8266 and Blynk

Overview

In this NodeMCU ESP8266 project, I demonstrated how to build a home automation system using the NodeMCU app and Blynk. With this IoT project, you can control four home appliances from a smartphone. If WiFi is not available, you can control the lighting manually.

Required Hardware Components

Hardware

Software:

Bill of Materials

S.NoCOMPONENTSDESCRIPTIONQUANTITYlink
1ESP8266-12E BoardESP8266-12E Board1https://www.amazon.com/Arduino-A000066-ARDUINO-UNO-R3/dp/B008GRTSV6
2Relay
5V Relay
4ader-em18-board-with-serial-ttl-interfacing-125-khz-through-a-rs232-converter-to-pc/?src=google&kwd=&adgroup={adgroup}&devicec&campaign={campaign}&adgroup={adgroup}&keyword=&matchtype=&gclid=CjwKCAjw49qKBhAoEiwAHQVTo-i85TwixHnJAFNHLfwUknLhBVYloMe3ECBLmMFtUFrk8qGBxO0vzhoCIAQQAvD_BwE
6Jumper WiresJumper Wires40https://www.flipkart.com/arduino-female-male-dupont-20cm-jumper-wire-40pcs-interconnect-electronic-hobby-kit/p/itmf8e5ezvkequ3h?pid=EHKF8DVBG9BXZHHH&lid=LSTEHKF8DVBG9BXZHHHUGSG9J&marketplace=FLIPKART&cmpid=content_electronic-hobby-kit_14498130132_u_8965229628_gmc_pla&tgi=sem,1,G,11214002,u,,,543116155366,,,,c,,,,,,,&ef_id=CjwKCAjwndCKBhAkEiwAgSDKQYwKr3euuMpKCLDJnf-

What is NodeMcu8266

NodeMcu8266 is a development board based on the esp8266 wifi module. NodeMcu8266 is an open-source device that is primarily used to manufacture IoT devices.

It can be programmed using the Arduino IDE and the coding structure is still similar to Arduino, but the ArduinoIDE does not come with ESP compatible boards pre-installed, so you need to add/import the board’s attachments to the IDE before programming and its very easy to do ESP series boards were not initially developed for compatibility with the Arduino IDE, so in the Arduino IDE, each pin on the NodeMCU corresponds to a different IDE’s GPIO pin. Here is the pin mapping for the NodeMCU GPIO pins. In Coding, you can directly write the NodeMCu digital pins as D1, D2, D3… or the corresponding GPIO PIN.

Steps to import ESP panel libraries:

Specification:

ESP8266 based development kit includes GPIO, PWM, IIC, 1-Wire and ADC on one board. Boost your development in the fastest way in combination with NodeMCU firmware

Shortcode

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Click on the Ok button.

Go to ‘Tools and Board’, from the drop-down menu select ‘ Board Manager’.



Circuit Diagram & Connection

A circuit diagram for Blynk controlled home automation using ESP8266 is given below. With this circuit diagram, you can assemble the circuit on a breadboard using a 4 channel relay and a NodeMCU board.

Setting up Blynk Application

Now let’s get to know the Blynk app. In this project, all the controls are implemented by the Blynk application. Blynk is a platform with IOS and Android applications to control Arduino, Raspberry Pi and the like through the Internet. It is a digital control panel where you can create a graphical interface for your project by simply dragging and dropping tools.

Download Blynk App on your smartphone through Play Store. Create an account and then click New Project.

You can download the Blynk app from the Playstore if you are an Android user. You can also install the Blynk app on IOS from the App Store.

Now let’s set up the Blynk app for an IoT home automation project. First, open the app and create a new account with your email ID. Then click “New Project”.

Now you can follow the images below for a complete setup guide.

You can download the Blynk app from the Playstore if you are an Android user. You can also install the Blynk app on IOS from the App Store.

Now let’s set up the Blynk app for an IoT home automation project. First, open the app and create a new account with your email ID. Then click “New Project”.

Now you can follow the images below for a complete setup guide.

Create a project in Blynk App

Now, add 4 buttons from the Widget box as we are using 4 channel relay



From the top, when you click “Email Everyone”, an authentication code will be sent to your email address. This code is very important because it is required in the program/code. So open your email id and check the token.

Click on button -> change its name -> change PIN to digital pin say D3 depending upon your connection. Repeat process for 4 relays. I am using D1 for relay 1, D2 for relay 2, D3 for relay 3 and D4 for relay 4.

Source Code/Program

Here is the Blynk based home automation code, you can copy and paste the code into your Arduino IDE. But before that, you need to add the Blynk library to the Arduino IDE.

Download Blynk Library

https://github.com/blynkkk/blynk-library

Final Code

#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[] = "c5lRcTsZ2GwLyRtQ098wzuVdFz__sbXx";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = Devilal;
char pass[] = Home@123;
 
  int Fan_1         = 12;  // D6 pin 
  int Light_1       = 14;  // D2 pin 
  int Bed_Light_1   = 4;   // D1 pin 
  int TV_1          = 5;   // D5 pin 
 
void setup()
{
  // Debug console
  Serial.begin(115200);
 
  pinMode(Fan_1,OUTPUT);
  pinMode(Light_1,OUTPUT);
  pinMode(Bed_Light_1,OUTPUT);
  pinMode(TV_1,OUTPUT);
 
  digitalWrite(Fan_1, HIGH);
  digitalWrite(Light_1, HIGH);
  digitalWrite(Bed_Light_1, HIGH);
  digitalWrite(TV_1, HIGH);
 
  Blynk.begin(auth, ssid, pass);

}
 
void loop()
{
  Blynk.run();
}

Output Images

1 / 9

Exit mobile version