BLYNK Application Based Home Automation Using ESP

Introduction

This project focuses on creating a Home Automation system using Arduino UNO, an ESP8266-01 module, and the Blynk mobile application. It’s a popular project among hobbyists, students, and DIY enthusiasts. Home automation in this context means remotely controlling household appliances via the internet through the Blynk mobile app. One of the standout features of this project is its dual functionality. Users can control home appliances both manually, using physical switches, and remotely via the Blynk mobile app. This versatility provides convenience and flexibility in managing home devices from anywhere with internet access.

The project demonstrates the control of four bulbs as examples, but it can be expanded to manage any appliance that operates on the standard household voltage of 220/240V AC at 50Hz, which covers most home appliances.

This project not only showcases remote control capabilities but also shows the integration of traditional manual controls with modern IoT (Internet of Things) technology, offering users a smooth experience in managing their home environment.

You can check our projects on Home Automation before you want to build this project.

In this setup, an Arduino UNO is paired with an ESP8266-01 module to enable internet connectivity. Additionally, a relay driver is interfaced with the Arduino UNO board. This relay driver allows the Arduino UNO to control devices based on commands received from the Blynk application, which facilitates remote control over the internet.

Hardware Requirements

Notice: There might be affiliate links to Amazon on this page. which implies that I may receive a tiny commission from the sale. This may be your way of indirectly assisting me. Regards
  • Arduino UNO (HERE)
  • ESP8266-01 Module (HERE)
  • 4-Channel Relay Driver (HERE)
  • Connecting Wires (HERE)
  • Breadboard (HERE)
  • AC bulb holder
  • AC bulb
  • Connecting wire for AC lines

Software Requirements

  • Arduino IDE (Download HERE)
  • Blynk Mobile app (Download HERE)

Circuit Diagram

Circuit Explanation

  • Arduino UNO
  • Power Supply
  • WIFI Module ESP8266-01
  • Relay and relay drivers

Arduino UNO

At the heart of the system, the Arduino UNO board serves as the central decision-making unit. It interfaces with an ESP8266-01 module and a relay system via relay drivers. The ESP8266-01 module plays a crucial role in enabling internet connectivity and data exchange within the circuit.

Connection Details:

ESP8266-01 Module to Arduino UNO:

  • Rx (ESP8266-01) connects to Pin 11 (Tx) on the Arduino UNO for transmitting data.
  • Tx (ESP8266-01) connects to Pin 12 (Rx) on the Arduino UNO for receiving data.
  • CH_PD and Vcc of the ESP8266-01 are connected to a 3.3V power source.
  • GND of the ESP8266-01 module is connected to the GND of the Arduino UNO to complete the power circuit.

Functionality:

The ESP8266-01 module facilitates communication over Wi-Fi, allowing the Arduino UNO to send and receive commands from external sources such as the Blynk application over the internet. This setup enables remote control and monitoring of connected devices via the relay drivers controlled by the Arduino UNO.

Blynk Home Automation Setup

Source Code

config.h file

#ifndef _configFile_H    // Put these two lines at the top of your file.
#define _configFile_H    // (Use a suitable name, usually based on the file name.)

// Place your main header code here.
#define AUTH "Divi0SDgTHGK2Z8bBKHPLPqodaADEBSgH"                 // You should get Auth Token in the Blynk App.  
#define WIFI_SSID "JioFiber2"             //Enter Wifi Name
#define WIFI_PASS "Projects4u@123"           //Enter wifi Password
#endif // _configFile_H    // Put this line at the end of your file.

BLYNK_ESP01_HomeAutomation.ino

#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include "configFile.h"

// You should get Auth Token in the Blynk App.
char auth[] = AUTH;
char ssid[] = WIFI_SSID;
char pass[] = WIFI_PASS;

/*char auth[] = "####################################";
char ssid[] = "##############";
char pass[] = "################";*/

// Software Serial
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(11, 12); // RX, TX

// Your ESP8266 baud rate: SDK version:1.5.4(baaeaebb)
#define ESP8266_BAUD 9600 //115200

#define VPIN_1    V1 
#define VPIN_2    V2
#define VPIN_3    V3 
#define VPIN_4    V4

// define the GPIO connected with Relays of Arduino UNO
#define relay1 7       //D7
#define relay2 6     //D6
#define relay3 5    //D5
#define relay4 4   //D4

// define the GPIO connected with Relays of Arduino UNO
#define sw1 A0       //A0
#define sw2 A1     //A1
#define sw3 A2    //A2
#define sw4 A3   //A3

int swState1 = 0, swState2 = 0, swState3 = 0, swState4 = 0;

ESP8266 wifi(&EspSerial);


  // Request the latest state from the server
  BLYNK_CONNECTED() {
    Blynk.syncVirtual(VPIN_1);
    Blynk.syncVirtual(VPIN_2);
    Blynk.syncVirtual(VPIN_3);
    Blynk.syncVirtual(VPIN_4);
  }

  BLYNK_WRITE(VPIN_1) {
    int val = param.asInt();
    Serial.println("Value1 : " + String(val));
    digitalWrite(relay1, val);
  }
  
  BLYNK_WRITE(VPIN_2) {
    int val = param.asInt();
    Serial.println("Value2 : " + String(val));
    digitalWrite(relay2, val);
  }
  
  BLYNK_WRITE(VPIN_3) {
    int val = param.asInt();
    Serial.println("Value3 : " + String(val));
    digitalWrite(relay3, val);
  }
  
  BLYNK_WRITE(VPIN_4) {
    int val = param.asInt();
    Serial.println("Value4 : " + String(val));
    digitalWrite(relay4, val);
  }


void setup()
{
  // Debug console
  Serial.begin(9600);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  digitalWrite(relay1, HIGH);
  digitalWrite(relay2, HIGH);
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
 
  pinMode(sw1, INPUT);
  pinMode(sw2, INPUT);
  pinMode(sw3, INPUT);
  pinMode(sw4, INPUT);
  
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);
  Blynk.begin(auth, wifi, ssid, pass);
  
}

void loop()
{
  Blynk.run();
  switchControlled();
}
void switchControlled(){
  if(digitalRead(sw1) == HIGH && swState1 == 0){
       digitalWrite(relay1, HIGH);
       Blynk.virtualWrite(VPIN_1, 1);
       swState1 = 1;
    }
  if(digitalRead(sw1) == LOW && swState1 == 1){
       digitalWrite(relay1, LOW);
       Blynk.virtualWrite(VPIN_1, 0);
       swState1 = 0;
    }
  if(digitalRead(sw2) == HIGH && swState2 == 0){
       digitalWrite(relay2, HIGH);
       Blynk.virtualWrite(VPIN_2, 1);
       swState2 = 1;
    }
  if(digitalRead(sw2) == LOW && swState2 == 1){
       digitalWrite(relay2, LOW);
       Blynk.virtualWrite(VPIN_2, 0);
       swState2 = 0;
    }
  if(digitalRead(sw3) == HIGH && swState3 == 0){
       digitalWrite(relay3, HIGH);
       Blynk.virtualWrite(VPIN_3, 1);
       swState3 = 1;
    }
  if(digitalRead(sw3) == LOW && swState3 == 1){
       digitalWrite(relay3, LOW);
       Blynk.virtualWrite(VPIN_3, 0);
       swState3 = 0;
    }
  if(digitalRead(sw4) == HIGH && swState4 == 0){
       digitalWrite(relay4, HIGH);
       Blynk.virtualWrite(VPIN_4, 1);
       swState4 = 1;
    }
  if(digitalRead(sw4) == LOW && swState4 == 1){
       digitalWrite(relay4, LOW);
       Blynk.virtualWrite(VPIN_4, 0);
       swState4 = 0;
    }
}

4 thoughts on “BLYNK Application Based Home Automation Using ESP”

  1. Pingback: How to Interface Membrane Matrix Keypad Using Arduino Uno with Example Project - Projects4u

  2. Pingback: How to Interface Thermal Printer with Arduino UNO - Projects4u

  3. Pingback: Home Automation Project Using Raspberry Pi Pico Bluetooth - Projects4u

  4. Pingback: Smart Digital Notice Board with NodeMCU ESP8266 - Projects4u

Leave a Comment

Your email address will not be published. Required fields are marked *