Intruder Alarm System with Automatic Online Updates using NodeMCU devkit v1.0
utopian-io·@japh·
0.000 HBDIntruder Alarm System with Automatic Online Updates using NodeMCU devkit v1.0
#### What Will I Learn? <br><hr> - You will learn how to <b>make a burglar/intruder alarm system using a NodeMCU devkit v1.0.</b> - You will learn how to <b>make a user interface on a local web server that automatically updates the data provided by PIR sensor.</b> - You will learn some other applications of this tutorial besides home security.<p></p> #### Requirements <center><hr><b>Materials Needed</b><hr></center> - NodeMCU devkit v1.0 - PIR Sensor (HC-SR501) - 220 ohms Resistor (1/4 W) - USB Cable (Type A to Mini B) - Junction Wires - Power Supply Unit (+5V) - Computer <center><hr><b>Software Applications </b><hr></center> - Open-Source Arduino Software (IDE) / Arduino IDE #### Difficulty<hr> - Intermediate <hr><p><br> <b>Description: </b><br><center>https://res.cloudinary.com/hpiynhbhq/image/upload/v1516817054/tdybir4dbqzqknhsfv7s.png</center><br> Home security is at risk as heinous activities of burglars and intruders are rampant. They can reach anywhere including your home. As responsible home owners, it is our duty to make necessary measures to protect our homes from these crimes. There are lot of ways to do this but it is always been the easiest and most convenient option to utilize technology to solve this.<p> Being fascinated on the prospects and initial progress of the IoT technology on the current development of engineering and electronics, I have come up with an idea to develop a system that integrates the use of the internet by providing a burglar alarm notification on a web page and body heat sensors such as a passive infrared sensor to provide a potential solution to home security threats. <p><div class=pull-left>http://www.theorycircuit.com/wp-content/uploads/2015/12/PIR-motion-sensor-pinout.png<a href="http://www.theorycircuit.com/wp-content/uploads/2015/12/PIR-motion-sensor-pinout.png"><center>PIR sensor (HC-SR501)</center></a></div> </b><p> The <b>Passive Infrared sensor (PIR sensor)</b> is an electronic sensor that gauges infrared (IR) light emanating from objects on its field of view. They are frequently utilized as a part of PIR-based movement indicators.<p> Using the PIR sensor, this system can sense body heat, which is normally caused by ample amount of infrared radiation, within the area of its range. The role of the NodeMCU devkit v1.0 in this system is to provide input and output mechanisms in conjunction with the data of the PIR sensor, as microcontroller. Moreover, as stated on my previous tutorials, this board is also IoT ready. Therefore, I can also use its capabilities as a Wi-Fi module to configure Internet protocols or simply to connect things thru the internet. Hence, the term IoT (Internet of Things) is justified. <p><blockquote>For further research about NodeMCU devkit v1.0. Here is its official <a href="www.nodemcu.com">website</a></blockquote><p> In this <b>tutorial</b>, we will use the microcontroller and wifi module capabilities of the NodeMCU devkit v1.0 board to <b>make an intruder alarm system that provides online updates by the use of a local web server.</b>.<p></p> <h2>Tutorial Contents</h2><hr> <center><b>"Intruder Alarm System with Automatic Online Updates<br> using NodeMCU devkit v1.0"</b></center><p></p> <b>Step 1:</b><center><b><em>"Downloading the ESP8266 Boards<br>and its Necessary Files"</em></b></center><hr> <br>Open Arduino IDE. And create a new sketch.<p> <em><b>Note:</b> Make sure that you have already downloaded and installed the boards and the necessary files to make the NodeMCU devkit v1.0. If you haven't install or download them, kindly click <a href="https://utopian.io/u/25578052">here</a>. And follow the first step of my tutorial there.</em> <p> After the installation of ESP8266, go to the <b>Tools</b> tab and change the board to <em>NodeMCU 1.0 (ESP-12E Module)</em><p><center>https://res.cloudinary.com/hpiynhbhq/image/upload/v1516177346/khn1srl1nqv4vlel6oav.png</center> <b>Step 2:</b><center><b><em>"Programming your Board"</em></b></center><hr> <p>Since we have to position the system to specific area on the house, we will start on programming our NodeMCU devkit v1.0 board first then, we could easily isolate the system after assembling the circuit on the next step.<br>On your new sketch in Arduino IDE, input this program:<p> <hr> <code>#ifndef UNIT_TEST <br>#include <<a href="">Arduino.h</a>> <br>#endif <br>#include <<a href="">ESP8266WiFi.h</a>> <br>const char* ssid = "my WiFi SSID"; <br>const char* password = "my WiFi Password"; <br>WiFiServer server(301);//the port <br>IPAddress ip(192, 168, 43, 67); <br>IPAddress gateway(192, 168, 43, 1); <br>IPAddress subnet(255, 255, 255, 0); <br>IPAddress dns(192, 168, 43, 1); <br>void setup(void) { <br>Serial.begin(115200); <br>delay(10); <br>//set the gpio pin D2 as an input pin. <br>pinMode(D2, INPUT_PULLUP); <br> // Connect to WiFi network <br>Serial.println(); <br>Serial.println(); <br>Serial.print("Connecting to "); <br>Serial.println(ssid); <br>//Static IP Setup Info Here... <br>WiFi.config(ip,dns,gateway,subnet); <br>WiFi.begin(ssid, password); <br>while (WiFi.status() != WL_CONNECTED) { <br>delay(500); <br>Serial.print("."); <br>} <br>Serial.println(""); <br> Serial.println("WiFi connected"); <br>// Start the server <br>server.begin(); <br>Serial.println("Server started"); <br> // Print the IP address <br>Serial.print("Use this URL to connect: "); <br>Serial.print("http://"); <br> Serial.print(WiFi.localIP()); <br>Serial.println("/"); <br>} <br>void loop() <br>{ <br>// Check if a client has connected <br>WiFiClient client = server.available(); <br>if (!client) { <br>return; <br>} <br> // Wait until the client sends some data <br>Serial.println("new client"); <br>while(!client.available()){ <br>// delay(1); <br>client.setNoDelay(1); <br>} <br>// Read the first line of the request <br>String request = client.readStringUntil('\r'); <br>Serial.println(request); <br>client.flush(); <br>// Return the response <br>client.println("HTTP/1.1 200 OK"); <br>client.println("Content-Type: text/html"); <br>client.println(""); // do not forget this one <br>client.println("<!DOCTYPE HTML>"); <br>client.println("<<a href="">html></a>"); <br>client.println("<<a href="">meta http-equiv='refresh' content='20'</a>>"); <br>client.println("<<a href="">title</a>>INTRUDER ALARM SYSTEM <<a href="">/title</a>>"); <br>client.println("<<a href="">h1 style='color:yellow'</a>>USING NODEMCU 1.0 BOARD<<a href="">/h1</a>><<a href="">hr</a>><<a href="">hr</a>>"); <br>client.print("<<a href="">body style = 'background-color:gray;'</a>>"); <br>client.print("<<a href="">br</a>>"); <br>client.print("<<a href="">br</a>>"); <br> if (digitalRead(D2)==HIGH) <br>{ <br>client.println("<<a href="">button style='background-color:red;width:800px;height:200px'</a>><<a href="">font size= '+7' color='white'</a>><<a href="">b</a>>INTRUDER DETECTED!<<a href="">/b</a>><<a href="">/font</a>><<a href="">/button</a>><<a href="">p</a>>"); <br>} <br> else <br>{ <br>client.println("<<a href="">button style='background-color:green;width:800px;height:200px'</a>><<a href="">font size= '+7' color='white'</a>><<a href="">b</a>>SAFE<<a href="">/b</a>><<a href="">/font</a>><<a href="">/button</a>><<a href="">p</a>>"); <br>client.println("<<a href="">/body</a>>"); <br>client.println("<<a href="">/html</a>>"); <br>delay(1); <br>Serial.println("Client disconnected"); <br>Serial.println(""); <br>}</code><hr><p> <blockquote>The program of this system is just easy to understand. The pin d2 which is connected to the data of the PIR is set as an input pin on the code <code> pinMode(D2, INPUT_PULLUP);</code>. Using the if statement <code>if (digitalRead(D2)==HIGH)</code>, the web page displays a big red box with a warning <b>INTRUDER ALERT!</b> when a PIR sensor detects a change of the measures of infrared that it senses as a warm body is detected. On the contrary, when there is no signals detected, the display on the web page is just a big green box with the word <b>SAFE</b>.By the code <code>client.println("<<a href="">meta http-equiv='refresh' content='20'</a>>");</code>, the web page automatically refresh <b> every 20 seconds</b> to display if the sensor has sensed an intruder.<br>The program simply let your NodeMCU devkit v1.0 board to connect to your local access point or your Wi-Fi hotspot <code>const char* ssid = "my wifi SSID"</code> and use the password <code>const char* password = "my wifi password"</code> to authenticate.<br>I have set the port, ip, default gateway, subnet mask and the dns addresses of the web server as static in the program. But we may have different configurations of IP addresses. It will depend on the network address of your local area network. This is to make sure that when your server shuts down, it will still have the same ip address when it is establish again. </blockquote><p> Now, connect your NodeMCU devkit v1.0 to your computer using the USB cable (Type A to Mini B). Go to the <b>device manager</b> then, identify its port number if it is your first time to use this board. Now, go the Arduino IDE and click <b>Tools</b> > <b>Port</b> and look for the port of your NodeMCU devkit v1.0. Upload the program above. <em> Make sure to input it properly. (I have already compiled this program and it has no errors)</em><p>After you are done uploading your program to your board, you can test your web server by using your web browser. But make sure that your computer or device is connected on the same local access point or Wi-Fi hotspot.<p>To access your simple web server, just type the ip address you set like in my case, it is <code>192.168.43.67:301</code>. Your web page must look like this.<p> <center>https://res.cloudinary.com/hpiynhbhq/image/upload/v1516781955/rspzn8yzvsdkyzizx4id.png</center> <p> <b>Step 3:</b> <center><b><em>"Assembling your Circuit"</em></b></center><hr> <p>Get your breadboard and other components and carefully assemble the circuit below.<br><center>https://res.cloudinary.com/hpiynhbhq/image/upload/v1516808064/dlzbmrr9ug2yp7b2awyv.png</center> <p><b>Take note of the pin configurations of the NodeMCU devkit v1.0 and the PIR sensor.</b> <center>http://simba-os.readthedocs.io/en/latest/_images/nodemcu-pinout.png</center><br><a href="http://simba-os.readthedocs.io/en/latest/_images/nodemcu-pinout.png"><center>NodeMCU devkit v1.0 Board</center></a><p><center>http://www.theorycircuit.com/wp-content/uploads/2015/12/PIR-motion-sensor-pinout.png</center><br><a href="http://www.theorycircuit.com/wp-content/uploads/2015/12/PIR-motion-sensor-pinout.png"><center>PIR sensor</center></a> <b>Step 4:</b> <center><b><em>"Testing your System"</em></b></center><hr> <p> <br>Walk away from the field of view of the PIR sensor. Make sure no one is blocking the PIR sensor while you are testing. And open the local web page you have created by accessing the IP address of the web server using a web browser. My web server's ip address is <code>192.168.43.67:301</code>. The display should have a big green box with a word <b>SAFE</b> in it.<center>https://res.cloudinary.com/hpiynhbhq/image/upload/v1516814498/ae1vxgrzfk8ly91qpfy5.png</center><p> Then, ask someone to stand or block the field of view of the PIR sensor like the illustration below. Observe that the display on the web page has a big red box with text <b>INTRUDER ALERT!</b> now.<p> <center>https://res.cloudinary.com/hpiynhbhq/image/upload/v1516814581/stjf5sn3o7mgn278rlxc.png</center><br> Reference Images for Illustration: <a href ="https://www.3dcadbrowser.com/download.aspx?3dmodel=27288">1</a> | <a href="https://lh6.googleusercontent.com/proxy/NaQcaB2BcrjjM267C-UEpDgLOYYRmdOaz8TMPP-yLKaO8mjoGLTi1mO3uuw3JZWqbxxqxe0BoK60fBFdYbhivWSiJYt8T9qnmjcdtK7hCMVHD5NKEK1fEza3vQFi97mIiG442-E8=w443-h332-nc">2</a><p> Now, you have successfully made your own <b>Intruder Alarm System with Automatic Online Updates.</b> <h3> Curriculum</h3><hr> <br> • <a href="https://utopian.io/u/25578052">Auxiliary Wireless TV Power Remote Control using NodeMCU devkit v1.0</a><br> • <a href="https://utopian.io/u/26198599">Make Your Own Web Server using NodeMCU devkit v1.0</a><br> • <a href="https://utopian.io/u/26718005">External GPIO Pin State Monitoring using HTTP Client Request for NodeMCU Devkit v1.0 Boards</a><br> • <a href="https://utopian.io/u/27254457">Web-controlled Servomotor using NodeMCU devkit v1.0 board</a> <p></p> This tutorial can also be applied in detection systems for electronic projects or studies that uses wireless local area network for hardware controls, besides its huge potential in home security.<p> <blockquote>I hope you enjoy this tutorial. Till next time!</blockquote><p> Your contributor, @japh <br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@japh/intruder-alarm-system-with-automatic-online-updates-using-nodemcu-devkit-v1-0">Utopian.io - Rewarding Open Source Contributors</a></em><hr/>
👍 steemitstats, claraquarius, earlybiiird, steemph.cebu, themanualbot, jassennessaj, surpassinggoogle, arcange, raphaelle, cub2, remlaps2, dwaeji-aizelle, ted7, carpieeew, zynagraphy, bayanihan, juvyjabian, dianargenti, bien, aauthespian1, marlon82, melvinlumacad, shairanada, firatozbek, dynamicgreentk, technology-trail, marzyoung22, smeet, jazzybells, utopian-io,