Ex 10
Ex 10
OBJECTIVE:
To build a Security system which can trigger an E-mail with Date and time to a
particular E-mail ID stating the intrusion and gives alert by the own audio clip when it
detects someone. This system is a fully functional Security system which can be
Armed/Disarmed (Activated/De-activated) remotely via the internet.
REQUIRED COMPONENTS:
● Arduino UNO
● ESP8266
● PIR sensor
● ISD1820 Voice Module
● LM317, LM7805
● BC547 (2Nos)
● 1K, 200ohm, 330ohm resistors
● 10uf and 0.1uf Capacitors
● 12V adapter / 9V battery to power the setup
CIRCUIT DIAGRAM:
Circuit Diagram.
BLOCK DIAGRAM:
IoT Based Security System for Theft Identification.
WORKING EXPLANATION:
Creating an API to send E-mail using IFTTT:
Once the hardware is ready lets create an API (Application Program Interface) that can
send E-mail to a particular E-mail ID. This can be easily done with the help of a website
called IFTTT.com. It is also possible to covered a project that could send SMS using
ESP8266 and Email using PIC Microcontroller which uses the same IFTTT services.
Follow the below steps:
1. Login into the IFTTT account
2. Search for “Maker Web hooks” and click on connect
3. Now search for “Gmail” and click on connect and follow the steps to give access
4. Then, create an Applet by clicking on My Applet-> New Applet.
5. Here, the “This” function will be for web makerhooks service and “that” function will be
Gmail Services
6. So click on “This”, search and select Web maker hooks. It will ask for event name like
“123”
7. Then click on “That”, search and select Gmail and enter the subject and body of the
mail.
8. Once all the required details are entered the Apple should be ready.
9. Now, search and get into Web Maker Hooks again and click on “Documentation”. Then
under the event name enter the event name to be used in the Applet. In my case it is
“123” and copy the URL since it is required in the Arduino program.
Once if ready with the Hardware and the codes can be uploaded the program to the
ESP8266 module by using a FTDI board. After uploading the program click on the serial
monitor and it is possible to see something like an IP address in that page. If not, reset
the ESP8266 module and try again.
Once verified all these can now be transferred the ESP8266 to the Perf board and power
it ON and then short the switches.
After powering on it can be used the IP to get into the above shown web page and enable
the Security system. After enabling, wait for 50-60 seconds for the PIR sensor to calibrate.
Now the project is ready for action, it is possible to leave it in a place and if anyone crosses
that place and falls within the range of PIR sensor a voice message will be triggered and
an E-mail will be sent to the E-mail ID with the Date and time he/she crossed.
PROGRAM:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
MDNSResponder mdns;
boolean trigger_sms = false;
boolean power_module = false;
const char* ssid = "BPAS home"; //Enter you Wifi SSID here
const char* password = "cracksen"; //Enter the password here
ESP8266WebServer server(80);
String mainPage = ""; //The default page
String feedback = ""; //Gives status of the switch
String currentPage = ""; //Combines main and feedback page
int GPIO_0 = 0; //Pin definition
int GPIO_2 = 2; //Pin definition
void setup(void){ //HTML code for webpage//
mainPage += "<h1 align=\"center\">IOT based security System</h1><h2
align=\"center\">-CircuitDigest</h2><h1 align=\"center\"><p>Alarm Status: <a
href=\"switch2On\"><button>ARM</button></a> <a
href=\"switch2Off\"><button>DISARM</button></a></p>";
feedback = "<h3 align=\"center\">Click on ARM to enable the security system</h3>";
//End of HTML code//
currentPage = mainPage+feedback;
// preparing GPIOs
pinMode(GPIO_0, INPUT); //feeded by PIR sensor
pinMode(GPIO_2, OUTPUT); //used to turn on PIR and Voice module
digitalWrite(GPIO_2, LOW);
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
} // config static IP
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //Serial monitor will give the IP address of the ESP module
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
currentPage = mainPage+feedback;
server.send(200, "text/html", currentPage);
currentPage = "";
});
server.on("/switch2On", [](){
feedback = "<h3 align=\"center\">Alarm is up and running </h3>"; //HTML code
modification
currentPage=mainPage+feedback;
server.send(200, "text/html", currentPage);
currentPage="";
digitalWrite(GPIO_2, HIGH); //Turn on PIR and Voice module
power_module=true;
delay(1000);
});
server.on("/switch2Off", [](){
feedback = "<h3 align=\"center\">Alarm is down</h3>"; //HTML code modification
currentPage=mainPage+feedback;
server.send(200, "text/html", currentPage);
currentPage="";
digitalWrite(GPIO_2, LOW); //Turn off PIT and Voice Module
power_module=false;
delay(1000);
});
server.begin();
Serial.println("IOT security system is up and running");
} //Function to send an E-mail//
void send_Email()
{
const char* host = "maker.ifttt.com"; //The host of API URL will be the same for all
const int httpsPort = 443;
WiFiClientSecure client;
Serial.print("connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
String url = "/trigger/123/with/key/mDsoOV_EERS3xRfrh3_UQBhbcx0qlRHns-
z2qXXXXX"; //Must change it to the API URL
Serial.print("requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: BuildFailureDetectorESP8266\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected()) {
String line = client.readStringUntil('\n');
if (line == "\r") {
Serial.println("headers received");
break;
} }
String line = client.readStringUntil('\n');
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
} //Function to send an E-mail
void loop(void){
server.handleClient();
if (digitalRead(GPIO_0==HIGH) && power_module==true)
trigger_sms=true;
else
trigger_sms=false;
if (trigger_sms==true) {
send_Email(); //If the PIR module is powered and if a person is detected send a E-mail
trigger_sms=false;
delay(2000);
}}
OUTPUT:
RESULT:
Thus, an IOT based Security system for Theft identification has been done, by
sending E-mail and voice alert to the user when it detects someone with the help of
ESP8266 module using Arduino IDE.