Home automation is a modern technology that allows homeowners to control their home appliances remotely using a smartphone or other electronic device. With the Internet of Things (IoT), home automation has become more accessible, affordable, and user-friendly. In this article, we will discuss how to build an IoT home automation system using ESP8266 and Blynk, including the materials needed, code, and steps involved in the process.
Material Needed :
To build an IOT home automation system using ESP8266 and Blynk, you will
need the following materials:
1 ESP8266 module
2 4-channel relay module
3 Breadboard
4 Jumper wires
5 Blynk app (available for free on Android and iOS devices)
6 Arduino IDE software
Firstly, identify these components.
fig: ESP8266 Module
fig: 4 Channel Relay Module
fig: breadboard
fig: jumper wire
Hardware Setup
The first step is to connect the ESP8266 microcontroller with the 4
channel relay module using jumper wires. The connection diagram is as
follows:
ESP8266 -> Relay Module
D0 -> IN1
D1 -> IN2
D2 -> IN3
D3 -> IN4
GND -> GND
VCC -> VCC
Circuit Diagram :
fig : Home Automation Circuit Diagram
Now, let’s set up the Blynk web application step by step. For that,
follow the instructions below.
First, go to the Blynk official website using your browser. Then login
to this site using your email and password. (If you don’t have a Blynk
account, you must make a new account. For that, use this link. It will
guide you)
Next, click the template button and create a new template . For that,
name it as you like. Also, select the hardware as ESP8266 and the
connection as WIFI.
Then, click the “Datastreams” tab and create two Datastreams as
VitualPin. Also, set the first pin and the second pin to V0 and V1.
Then, select the data type as an integer.
Now, click on the Web Dashboard tab. Then, drag and drop two buttons
to the dashboard. Next, click the setting icon in the button and
select the datastream we created earlier. That is, V0 for button one
and V1 for button two. Finally click the save button.
Next, click the Search Icon button. After, click the New Devices button
and after click the “From template” button. Finally, select the template
we created earlier.
OK, the Blynk web application is ready for us, Now setup other two
relays like this.
Code :
The code for this IoT home automation system is written in the Arduino
IDE software. It includes code for connecting the ESP8266 module to Wi-Fi,
controlling the 4-channel relay module, and communicating with the Blynk
app. Here is the code:
//**************************************//Program Developed By Sakchyam Bastaktoi//****************************************************************//
//Include the library files
#define BLYNK_PRINT Serial
#include
#include
#define BLYNK_TEMPLATE_ID "Enter Your Template ID"
#define BLYNK_TEMPLATE_NAME "Enter your Template Name "
#define BLYNK_AUTH_TOKEN "Enter your Blynk Auth Token"
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "WIFI NAME";//Enter your WIFI name
char pass[] = "Password";//Enter your WIFI password
//Define the relay pins
#define relay1 D0
#define relay2 D1
#define relay3 D2
#define relay4 D3
#define relay5 D4
#define relay6 D5
//Get the button values
BLYNK_WRITE(V0) {
bool value1 = param.asInt();
// Check these values and turn the relay1 ON and OFF
if (value1 == 1) {
digitalWrite(relay1, LOW);
} else {
digitalWrite(relay1, HIGH);
}
}
//Get the button values
BLYNK_WRITE(V1) {
bool value2 = param.asInt();
// Check these values and turn the relay2 ON and OFF
if (value2 == 1) {
digitalWrite(relay2, LOW);
} else {
digitalWrite(relay2, HIGH);
}
}
BLYNK_WRITE(V2) {
bool value3 = param.asInt();
// Check these values and turn the relay3 ON and OFF
if (value3 == 1) {
digitalWrite(relay3, LOW);
} else {
digitalWrite(relay3, HIGH);
}
}
BLYNK_WRITE(V3) {
bool value4 = param.asInt();
// Check these values and turn the relay4 ON and OFF
if (value4 == 1) {
digitalWrite(relay4, LOW);
} else {
digitalWrite(relay4, HIGH);
}
}
BLYNK_WRITE(V4) {
bool value5 = param.asInt();
// Check these values and turn the relay5 ON and OFF
if (value5 == 1) {
digitalWrite(relay5, LOW);
} else {
digitalWrite(relay5, HIGH);
}
}
BLYNK_WRITE(V5) {
bool value6 = param.asInt();
// Check these values and turn the relay6 ON and OFF
if (value6 == 1) {
digitalWrite(relay6, LOW);
} else {
digitalWrite(relay6, HIGH);
}
}
//#################################################################################################################################################//
//Set the relay pins as output pins
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
// Turn OFF the relay
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
digitalWrite(relay3, HIGH);
digitalWrite(relay4, HIGH);
digitalWrite(relay5, HIGH);
digitalWrite(relay6, HIGH);
//Initialize the Blynk library
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}
//#################################################################################################################################################//
void loop() {
//Run the Blynk library
Blynk.run();
}
//**************************************//Program Developed By Sakchyam Bastaktoi//****************************************************************//
Now let’s create the program for this project. It’s as follows.
Now, copy and paste the Blynk auth token. To do this, check the “Device Info” tab of your Blynk web application.
Next, enter your correct WIFI name and password.
Now, select the board and port. Then, upload this program to the Nodemcu board. (If you haven’t yet installed the ESP8266 boards, please use this link and follow the instructions)
OK, now let’s set up the Blynk mobile dashboard. For that, follow the instructions below.
First, download and install the Blynk app on your phone. Then, run this application. Now, you can see the template we created earlier. Next, click this template and set up your dashboard.
Now, click the upper right corner button and include the two buttons to the dashboard. Then, arrange these widgets as you like.
Next, click the buttons one by one and select the detastreams V0 and V1 respectively. Also, select the mode as switch.
OK, the Blynk app is ready.
Here are the some pictures of our project:
Now you can operate these relays using the web or mobile dashboard. The show video guided below. So, see you in the next project.
project video
Conclusion :
DIY home automation using the Blynk app and ESP8266 microcontroller is a great way to automate your home without spending a lot of money. This system is easy to use and can be easily programmed even by beginners. However, it may not be as secure or reliable as more advanced home automation systems. If you are looking for a more secure and reliable home automation system, you may want to consider investing in a more advanced system.
If you have any questions regarding this project, feel free to ask us in the comment section, you will get a guaranteed reply from us.