How to make a home security system using the Nodemcu ESP8266 and the Blynk app
Hello, welcome back to another tutorial from the SriTu Hobby. In this tutorial, we will learn how to make a home security system using the Nodemcu ESP8266 board and the Blynk application. Also, the PIR sensor is mainly used for this project. We have done this project using the Telegram app in a previous article. You can study it from this link. Also, this project can be used for our home, place of business, shops. So this tutorial will cover how to make this project at a low cost. Keep reading.
How does this security system work?
When this security system is powered on, the NodeMCU board connects to the Blynk cloud via the internet. We can then turn the system on and off using the button on the interface set up in the Blynk app. When the PIR sensor detects motion, the buzzer and red LED are activated, and a push notification is sent to the mobile phone via the Blynk app. After a short time, the system will return to its normal state. This duration can be adjusted using the preset on the PIR sensor. Additionally, the green LED bulb turns on when the system is operating normally.
OK, let’s do this project step by step. The required components are given below.
- Nodemcu ESP8266 board x 1 — Our Store / Amazon
- PIR sensor x 1 — Our Store / Amazon
- LED x 2 — Our Store / Amazon
- 180-ohm resistor x 2 — Our Store / Amazon
- 5v buzzer x 1 — Our Store / Amazon
- Jumper wires — Our Store / Amazon
- Foam board — Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Nodemcu ESP8266 board
PIR sensor
LED bulb x 2
180-ohm resistor x 2
5v buzzer
Jumper wires
Foamboard
Step 2
Secondly, cut the foam board pieces as follows.
Step 3
Thirdly, solder the jumper wires for the buzzer and LEDs.
Step 4
Next, connect all the components to the Nodemcu board. To do this, use the circuit diagram below.
Step 5
Then, adjust a 1.5 x 3.5-inch piece to fit the Nodemcu board and glue it on.
Step 6
Next, set a 2.5 x 3.5-inch piece to fit the PIR sensor and the two LEDs. After, glue them.
Step 7
Then, take a 1.5 x 3.5-inch piece and adjust it to fit the buzzer. After, glue it on.
Step 8
Now, connect the piece that holds the Nodemcu board to the 3.5 x 2.5-inch piece.
Step 9
Then, glue the 1.5 x 2.5-inch piece to the base foam board piece. Also, glue the buzzer-connected piece to the base piece.
Step 10
Next, glue the 1.5 x 2.5-inch piece to the main foam board piece. Also, glue the PIR sensor attachment piece to the top as follows.
Step 11
Ok, now let’s set up the Blink app step by step.
- First, download and install the Blynk app from your mobile phone. Then, sign up for this app using your Gmail. Next, click the new project button.
- Then, enter the project name as you like. Also, select the device and connection type. After. Click the “Confirm” button.
- Now, we can see the project interface. Then, click the “+” icon and add one button and notification widget.
- Then, click the button and enter the name of your choice. Next, change the pin to A0 and the mode to the switch. Afterward, click the Notification Widget and change the priority to HIGH.
Step 12
OK, the Blynk app is ready. Now, connect this project to the computer. After that, let’s create the program for this project. It is as follows.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = ""; //Enter your Blynk application auth token
char ssid[] = ""; //Enter your WIFI name
char pass[] = ""; //Enter your WIFI passowrd
BlynkTimer timer;
int pinValue = 0;
void setup() {
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D6, INPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, notifiaction);
}
BLYNK_WRITE(V0) {
pinValue = param.asInt();
}
void notifiaction() {
bool sensor = digitalRead(D3);
Serial.println(sensor);
if (pinValue == 1) {
Serial.println("System is ON");
if (sensor == 1) {
Blynk.notify("WARNING! Please check your security system");
digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
} else if (sensor == 0) {
digitalWrite(D0, LOW);
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
}
} else if (pinValue == 0) {
Serial.println("System is OFF");
}
}
void loop() {
Blynk.run();
timer.run();
}
Code Explanation
First, WIFI and Blynk libraries are included.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Secondly, enter your Blynk app token and WIFI connection details.
char auth[] = "BMFz-z1357p65VVCAcsWTPfg_K-Jcuwj";
char ssid[] = "Dialog 4G 025";
char pass[] = "12345";
Next, variables were created for BlynkTimer and Button Widget.
BlynkTimer timer;
int pinValue = 0;
In the void setup, the LEDs, buzzer, and sensor pins are set as output. Also, the Blynk library starts using the Auth token, WIFI name, and WIFI password. Later, the notification function is called. The notification function is described below.
void setup() {
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D6, INPUT);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, notifiaction);
}
void notifiaction() {
First, values are obtained from the PIR sensor and these values are entered into the boolean variable. Also, these values are printed on the serial monitor
bool sensor = digitalRead(D3);
Serial.println(sensor);
If the Blynk app button value is 1, the system is activated. Also, it is printed on the serial monitor.
if (pinValue == 1) {
Serial.println("System is ON");
Then, PIR sensor values are checked using the IF condition. If the value is 1, a push notification is sent to your phone, and the red LED and buzzer are activated.
if (sensor == 1) {
Blynk.notify("WARNING! Please check your security system");
digitalWrite(D0, HIGH);
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
If the value is 0, the green LED is active.
} else if (sensor == 0) {
digitalWrite(D0, LOW);
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
}
If the Blink application button value is 0, the system deactivates. Also, it is printed on the serial monitor.
} else if (pinValue == 0) {
Serial.println("System is OFF");
}
}
This code gets values from the Blynk Button Widget.
BLYNK_WRITE(V0) {
pinValue = param.asInt();
}
In the loop function, the blink library and timer are activated.
void loop() {
Blynk.run();
timer.run();
}
Step 13
OK, now select the board and port. Then, upload this code to the Nodemcu board.
Step 14
Now, run the Blynk app interface and enjoy this project. The full video guide is given below. So, we will meet in the next tutorial. Have a good day.
How to make a home security system using the Nodemcu ESP8266 and the Blynk app