My Brain Cells

Easiest (and best) learning materials for anyone with a curiosity for machine learning and artificial intelligence, Deep learning, Programming, and other fun life hacks.

Home Automation Using ESP8266


Home Automation using ESP8266 with Blynk and IFTTT applications

Introduction:

Smart Home is an automated mechanism which helps in monitoring and controlling the devices. This project helps in improving the energy efficiency of the devices and time saving as it doesn’t need any man power. It is a combination of software and hardware to manage the home appliances. These devices are connected to the Internet, which allows them to be controlled remotely. With the help of Google voice assistant and Blynk app we can operate the applicances.


Components Used:

1) NodeMcu (ESP8266/ESP32S)

2) Relay Module (5V)

3) LED/Fan/Motor etc.

4) Breadboard

5) Connecting Wires


Software:

1) Arduino IDE

2) Blynk Application


Connections:

1) Connect Vin of ESP8266 to Vcc of Relay Module.
2) Connect GND of ESP8266 to GND of Relay Module.
3) Connect D1 pin to R1 of Relay Module.
4) Connect D2 pin to R2 of Relay Module.
5) Connect D3 pin to R3 of Relay Module.
6) Connect D4 pin to R4 of Relay Module.

Circuit Diagram:

Software Installation:

Arduino IDE:

1) Install and Launch Arduino IDE 1.8.15
2) Open your IDE and click on File->Preferences
    Enter the below URL in the additional boards manager URLs field:
    http://arduino.esp8266.com/stable/package_esp8266com_index.json
3) Go to Tools->Board->Boards Manager 
    Search for esp8266 board and install it.
4) Go to Sketch->Include Library->Manage libraries
    Install the blynk library as a .zip file without extracting the files
5) Select suitable Port in the Tools field.


Blynk App:

1) Install Blynk application in your mobile from playstore.
2) Click on New Project enter your preferred project name.
3) Select the device as NodeMcu/Esp8266 -> Connection type- WIFI -> Click on create
4) After creating the project you will receive an email to registered Email ID, mail consists of AUTH TOKEN (this is used to merge your blynk project with the Arduino IDE).
5) Create button and name it, after naming select the pins(make sure the pin numbers match the pins mentioned in the Connections field).

IFTTT:

1) Create an account in IFTTT and create an applet. 
2) After creating applet, click on the ‘+’ symbol and choose google assiatant as service. 
3) Choose and create a trigger by clicking on ‘Say a simple phrase’. 4) Fill the trigger fields and create trigger. 
5) Next select ‘+’ symbol before THAT and select service as ‘Webhooks’. 
6) Click on ‘Make a web request’ and fill the fields as mentioned below: ->
URL- http://blynk-cloud-ip/auth-token/update/pin-number 
(Ex: http://188.166.206.43/3qn3uFjWquLeiFD_rmfBx/update/D2) 
->Method- “PUT” 
->Content Type- application/json 
-> Body- [“0”] for switch on | [“1”] for switch off 
7) In the similar way create another applet for switch off by following the above steps. In the last field of the Webhooks i.e Body enter [“1”]. 
8) Now your applets are created and you can operate your devices using google assistant with the mail previously used for IFTTT.

Code:

#define BLYNK_PRINT Serial ESP8266 // helps generate the firmware running on your ESP8266

#include <ESP8266WiFi.h> // library for connecting WIFI to ESP board

#include <BlynkSimpleEsp8266.h> //establishing connection b/w Blynk and ESP8266


char auth[] = “YourAuthToken”; //AUTH TOKEN delivered to your mail


char ssid[] = “YourNetworkName”; //Wifi name

char pass[] = “YourPassword”; //Wifi password

void setup()

{  

  Serial.begin(9600);         //It initializes the serial communication with baud rate of 9600

  Blynk.begin(auth, ssid, pass);                 //It begins connection for auth token, wifi name, wifi password

}

void loop()

{

  Blynk.run();         //This continuously runs with Blynk app commands

}


Working:

1) After the entire circuit is connected, enter the code in the Arduino IDE and select a PORT number and run the code, after the code gets uploaded into the esp8266 the circuit starts operating.

2) When the user clicks on the button in the Blynk app, the application sends the information to the ESP8266 through WIFI. The board triggers the information and passes it to the relay module and ON/OFF operation is performed.

3) Make sure the WIFI is turned ON, this entire mechanism is solely depended on WIFI. We can further operate this mechanism by replacing the WIFI with a Bluetooth module.


Anthony

Leave a Reply

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

Back to top