ESP8266IOT Projects

IOT security system | IOT Home Alarm | IoT Home Security System Project

IoT Security System Project Description:

 

IoT Security System- In this tutorial, you will learn how to make your own IoT based home/office security system using the Nodemcu ESP8266 Wifi module, PIR Sensor, Infrared Sensor, and Blynk application. Each time an Intruder is detected a notification message is sent to the Blynk application. This is a real-time IOT based Security system. With the help of the Nodemcu ESP8266 Wifi Module, the PIR Sensor and IR Sensor can be monitored from anywhere around the world.


In this tutorial, we will cover

  1. Complete circuit diagram explanation
  2. Interfacing
  3. Nodemcu Programming and finally
  4. Testing

Without any further delay, let’s get started!!!

Amazon Links:

Nodemcu ESP8266 WiFi Module:

LM7805 Voltage Regulator:

470uf capacitor:

330-ohm resistor:

DC Female Power Jack:

Female Headers:

Male Headers:

Mini Pir Sensor:

PIR Sensor Arduino:

Obstacle IR Infrared Sensor:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

DISCLAIMER:

Please Note: these are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

 



Iot Security System Circuit Diagram:

IOT Security System

This Schematic is designed in CadeSoft Eagle 9.1.0 version. If you want to learn how to make a schematic and PCB then watch my video tutorial.

As you can see in this project two power supplies are used. The power supply on the left side is used to power up the Nodemcu ESP8266 wifi Module while the power supply on the right side is used to power up the PIR Sensor.  The voltage required to power up the PIR Sensor is from 5 to 20 volts as the PIR sensor module has a 3.3v voltage regulator. So the PIR Sensor module cannot be powered up using 3.3 volts from the Nodemcu Module. So that’s why I am using a separate 5v regulated power supply for the PIR Sensor. Both the Power Supplies are exactly the same and can be powered up using a single 12v adaptor.


J1 is the Female Power Jack and this is where we connect a 12v adaptor, battery, or a Solar panel. Two 470uf capacitors are connected at the input and output sides of the 7805 voltage regulator. A 330-ohm resistor is connected in series with a 2.5v LED. This is a current limiting resistor. The output of the voltage regulator is connected with the Vin pin of the Nodemcu ESP8266 Wifi module and the GND of the power supply is also connected with the ground of the Nodemcu Module.

The Out pin of the IR sensor is connected with the digital pin D1, VCC pin of the infrared sensor is connected with the 3v pin of the Nodemcu module while the GND is connected with the GND. The VCC pin of the PIR Sensor is connected with the output of the regulated power supply. The out pin is connected with the digital pin D0 and the ground pin is connected with the ground.

IOT Security System

This is the Final board after soldering, the PCB designing, online order placement, and soldering are already explained in my previous tutorial. The link to the video tutorial is already given above.


IOT Security System

This is the IR Sensor that I am going to use in this project. As you can see all the pins are clearly labeled with OUT, GND, and VCC. The white wire is connected with the OUT pin of the IR sensor and this will be connected with the digital pin D1 of the Nodemcu module, the brown wire is connected with the ground pin of the IR sensor and this will be connected with the ground of the Nodemcu module. The Red wire which is the VCC wire will be connected with the 3.3v pin of the Nodemcu module.

IOT Security System

This is the PIR Sensor. The leftmost pin is the VCC “Red Wire”. The middle one is the OUT “Yellow Wire” while the rightmost pin is the ground “Black Wire”. I have a very detailed getting started tutorial on the PIR sensor. So for the basic understanding, you should watch that tutorial which explains everything. You can find a link to the tutorial in the related projects section.


IOT Security System

This is the regulated 5 volts power supply based on the LM7805 voltage regulator. This power supply will be used to power up the PIR Sensor. The Orange wire is the 5v wire while the Blue wire is the ground wire.

Interfacing IR sensor and PIR with Nodemcu ESP8266:

 

IOT Security System

All the components are interfaced as per the circuit diagram already explained. As you can see the output of this power supply is connected with the VCC pin of the PIR Sensor, while the out pin is connected with the D0 and Ground is connected with the ground.

The red wire from the IR Sensor is connected with the 3.3v pin of the Nodemcu module, the brown wire is connected with the ground while the out pin of the IR sensor is connected with the D1 pin of the Nodemcu module. One more thing make sure you connect the ground of the 5v power supply with the ground of the Nodemcu Module. So that’s all about the interfacing.



Note: this old version of the Blynk app is no more functional. For the blynk mobile App setup and Blynk.cloud dashboard setup ready my article on the New Blynk V2.0. In this article I have explained how to migrate your projects from Blynk 1.0 to the new Blynk V2.0. You can also watch the video.

Blynk Application designing for IoT Security System:

Watch Video Tutorial given at the end which explains how to design the Blynk application or you can follow the following steps.

  • Open the Blynk application…
  • Click on the new project and enter the project name as IoT security system…
  • Click on the choose device and select Nodemcu…
  • Make sure you set the connection type to WIFI…
  • Finally, click on the create button, an authentication token will be sent on your email ID which will be then used in the programming. Simply copy and paste it in the programming…
  • Now click on the screen and search for the LED…
  • Click again on the screen and add another LED…
  • Click again on the screen and this time search for the terminal widget and add it…
  • Finally, add a notification widget…
  • Click on the first LED set the name and select the virtual pin V2…
  • Now click on the 2nd LED to set the name and select virtual pin V3…
  • Finally, click on the terminal widget, set the name and select virtual pin V4…
  • Set add a new line to yes and input line to off…so that’s all about the application designing.

IoT Security System Programming “Nodemcu”:

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>



char auth[] = "DyWieVh9EKgPbrDQAapbwWVFBJXN_Bqv";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "ZONG MBB-E8231-6E63";
char pass[] = "electroniclinic";

SimpleTimer timer;



// This function sends Arduino's up time every second to Virtual Pin (1).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
  
}

int pir_s = D0; // pir sensor
int ir_s = D1;  // infrared sensor


void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(pir_s, INPUT_PULLUP); 
  pinMode(ir_s, INPUT); 
  timer.setInterval(1000L,sensorvalue1); 

}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer   
}

void sensorvalue1()
{

if(digitalRead(pir_s) == HIGH)
{
  Blynk.virtualWrite(V2,255 ); // turns on the led
  Blynk.virtualWrite(V4,"Intruder detected on PIR Sensor!!!" ); 
  Blynk.notify("Intruder detected on PIR Sensor!!!"); 
}

if(digitalRead(pir_s) == LOW)
{
  Blynk.virtualWrite(V2,0 ); //turns off the led
  Blynk.virtualWrite(V4,"PIR Normal" ); 
}


    if( digitalRead(ir_s) == LOW)
{
  Blynk.virtualWrite(V3,255 ); // turns on the led
  Blynk.virtualWrite(V4,"Intruder detected on IR Sensor!!!" );
  Blynk.notify("Intruder detected on IR Sensor!!!"); 
} 

 if( digitalRead(ir_s) == HIGH)
{
  Blynk.virtualWrite(V3,0 ); // turns off the led

}


}


IOT Security System Program Explanation:

Before you start the programming, first of all, make sure that you download the following libraries. You can find the link in the related projects section.

 

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#include <SoftwareSerial.h>

#include <SimpleTimer.h>

char auth[] = “DyWieVh9EKgPbrDQAapbwWVFBJXN_Bqv”;

This is the authentication number which was sent via email.

char ssid[] = “ZONG MBB-E8231-6E63”;

This is the name of the wifi router

char pass[] = “electroniclinic”;

This is the password.

void myTimerEvent()

{

// You can send any value at any time.

// Please don’t send more that 10 values per second.

Blynk.virtualWrite(V1, millis() / 1000);

}

This is the same function I have been using in all of my IoT based projects.

int pir_s = D0; // PIR sensor

int ir_s = D1;  // infrared sensor

The PIR sensor is connected with the digital Pin D0 of the Nodemcu Module and the Infrared Sensor is connected with the digital pin D1.

Unlike the Arduino and Mega, the Nodemcu ESP8266 WIFI module also has at least two functions which are the void setup and void loop functions. The programming of the Nodemcu module is just like the Arduino and Mega.

void setup()

{

// Debug console

Serial.begin(9600);

Blynk.begin(auth, ssid, pass);

pinMode(pir_s, INPUT_PULLUP);

pinMode(ir_s, INPUT);

timer.setInterval(1000L,sensorvalue1);

}

In the void setup function I activated the serial communication. 9600 is the baud rate.

Then using the pinMode function I set both the sensors to input.

Sensorvalue1 is a user defined function and this function is called every 1 second.

void loop()

{

Blynk.run();

timer.run(); // Initiates BlynkTimer

}

Then starts the void loop function.  inside this function, we have only Blynk.run and timer.run functions.

As I said earlier sensorvalue1 is a user-defined function. This function has no return type and does not take any arguments as the input. Inside this function, we are using if conditions to check which sensor is activated. I have already explained all of these instructions in my previous tutorials. I have a separate video on how to use the notification widget. This program is very simple. Still, if you have any questions let me know in a comment. So that’s all about the programming.

This project was a great success, I successfully detected both the sensors which you can practically see in the video given below.



Watch Video Tutorial:

Related Articles:

Download Arduino Libraries and how to use them.

Pir Sensor

 

 

 

 

 

 

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

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

Back to top button