How to make a home automation system using the Nodemcu ESP8266 board and the new Blynk app
Hello and welcome back. In this tutorial, we will learn how to make a home automation system using the Nodemcu ESP8266 board and the new Blynk application. I used a two-channel relay module for that. You can use any other relay module. Like 4-way, 8-way, or 16-way. It depends on your job. Also, the appliances in your home can be connected to these relays. These include lamps, fans, televisions, water pumps, etc. After that, we can easily control these appliances using our smartphones. For that, this article will guide you. Also, I used two lamps for example. You can use any other appliances. But, you have to be careful about the AC voltage.
Ok, let’s do this project step by step. The required components are given below.
- Nodemcu board x 1 — Our Store / Amazon
- Relay module x 1 — Our Store / Amazon
- Bulb holder x 2
- Bulb x 2
- Plug top x 1
- Wires
- Breadboard x 1 — Our Store / Amazon
- Jumper wires — Our Store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Step 2
Secondly, connect the Nodemcu board to the breadboard.
Step 3
Thirdly, connect the bulb holders to the relay module. For that, use the circuit diagram below.
Step 4
Next, connect the plug top to the 230VAC input point.
Step 5
OK, now connect the relay module to the Nodemcu board using the jumper wires. For that, use the circuit diagram above. Next, connect it to the computer.
Step 6
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.
Step 7
OK, now let’s create the program for this project. It’s as follows.
/*New Blynk app with Home Automation
Home Page
*/
//Include the library files
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//Define the relay pins
#define relay1 D0
#define relay2 D1
#define BLYNK_AUTH_TOKEN "" //Enter your blynk auth token
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "";//Enter your WIFI name
char pass[] = "";//Enter your WIFI password
//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);
}
}
void setup() {
//Set the relay pins as output pins
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
// Turn OFF the relay
digitalWrite(relay1, HIGH);
digitalWrite(relay2, HIGH);
//Initialize the Blynk library
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
}
void loop() {
//Run the Blynk library
Blynk.run();
}
- 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)
Step 8
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 ealiar. 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.
Step 9
Now, connect the 5 VDC external power supply to the Nodemcu board. For that, use the circuit diagram above.
Step 10
Finally, put the bulbs to the holders and connect the plug top to the AC voltage. (If you have no knowledge of this AC voltage, please seek the assistance of an adult)
OK, now you can operate these relays using the web or mobile dashboard. The full video guide is below. So, see you in the next project.
How to make a home automation system using the Nodemcu ESP8266 board and the new Blynk app