Wifi Intruder Detection IoT using Sound Sensor DIY Kit

SuperKitz.com ​Project Manual

Wifi Intruder Detection IoT using Sound Sensor DIY Kit

Intruder detector System using a sound sensor and esp8266.

An Intruder system is defined as a software or hardware tool used to detect the unauthorized access of a computer system or the network. In this project, we design an intrusion system or an alarm system using a new sensor called a Sound sensor or Sound detector.

This project guides us to learn how to send emails and push notifications from the WiFi ESP8266 module, or any other IoT device, using Blynk Email and Push Notification APIs. For this, we are going to designing a simple thermometer project and then set up temperature Alarm points. Whenever the alarms triggers, an email and a push notification will be sent.

 

Requirements :

  • Computer/ Smartphone with an internet connection
  • Download and install Arduino IDE

Components

NodeMCU ESp8266

Breadboard

Jumper wires

Sound Sensor

Hardware

node mcu 8266 wifi

Getting
Started with
Web Switch ESP8266

NodeMCU ESP8266

NodeMCU is an open-source Lua based firmware and development board specially targeted for IoT based applications.It includes firmware that runs on the ESP8266 Wi-Fi SoC from Espressif Systems and hardware which is based on the ESP-12 module.

Pin out diagram
ESP8266

Sound Sensor

A Sound Sensor is a simple device that detects sound waves through their intensity and converts it into electrical signals. It is simply a module consisting of a Microphone with some processing circuit. In a Sound Sensor, the intensity of sound is measured from different sources like knocks, claps, loud voices, etc. 

Sound sensor module consists of a microphone, a voltage comparator IC (LM393), a potentiometer, a transistor, couple of LEDS and a few other passive components (resistors and capacitors).

Sound Sensor Connection Diagram
With ESP8266

Circuit Diagram

STEP1:

CONNECTING SOUND SENSOR TO NodeMCU

 Sound Sensor VCC -> NodeMCU Vcc

Sound Sensor VCC GND -> NodeMCU GND

Sound Sensor VCC Signal -> NodeMCU Analogy A0

 

Connections Explained:-

  • Connect all the components provided in the kit according to the provided wiring diagram mention in the documentation.

Setting up the Blynk App : IoT Dashboard

The first step is to install the Blynk App on your smartphone inorder to monitor the sensor values

Soon after the code has been uploaded to the NodeMCU, following steps are to be performed on the Blynk App.

Step 1: Create  a Blynk account and>select add new project>add project title >select nodeMCU

Step 2:Create a new project, and select your hardware  as soon as you create the new account

Step 3:Select the hardware as NodeMCU

Step 4: Navigate to project settings and copy Auth Token to clipboard -or- will be sent to your email account.

 A unique authentication code is sent for every new project you created by the Blynk app.  In order to connect your smartphone to the hardware, you need this code. The authentication code will be sent to the email address you used at the time of registration.

Step 5:  To control the digital pin, add widget “Button

You get notification of motion detection or on an event of Intruder detection. Which would later be coded in Arduino IDE

Step 6: Select the Virtual  pin as VO

Step 7 : Program on NodeMCU and Press the Run button on the BLYNK App.

PROGRAMMING

The NodeMCU programming is the same as that of Arduino except for the distribution of pins in the Nodemcu board. Follow the below steps for programming NodeMCU & Arduino IDE

Step 1: Install the Arduino IDE 1.6.4 or Greater

Download Arduino IDE

Download Arduino IDE from Arduino.cc (1.6.4 or greater) –never use 1.6.2!  Use your existing IDE in case if you have already installed it. In case of the proxy is giving you any problem, try downloading the ready-to-go package from the ESP8266-Arduino project

Note: In case if your board is not detected by the computer, check whether the USB data cable connection is damaged or not and if still the problem exists check if the correct driver is installed( follow step 2 to install the driver).

In order to upload code to the ESP8266 and use the serial console, connect any data-capable micro USB cable to ESP8266 IOT Board and the other side to your computer’s USB port.

 

The new version NodeMCUv1.0 comes with the CP2102 serial chip, you can download (also provided with the kit)  and install the driver from https://www.silabs.com/products/development-tools/…. The NodeMCUv0.9 comes with the CH340 serial chip, you can download and install the driver from: https://github.com/nodemcu/nodemcu-devkit/tree/mas…

 


Step 2: Installing NodeMCU package for Arduino IDE

Paste the copied link(givenbelow) and insert it(add. boad Manager URL) in Arduino IDE using the following sequence->File menu -> Preferences-> Paste copied link into the area shown in the black box in the above image. Close and restart the Arduino IDE.

The link should look something like this:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

Select Tools -> Boards manager and search for ESP8266 and install the libraries/files given under the heading ESP8266 by ESP community.

Restart the Arduino IDE

 

Scroll down, Install “esp8266 by ESP8266 Community”, from the ESP8266 board menu as shown below.

If you used the Installer, Windows – from XP up to 10 – 

  1. Delete the Documents -> Arduino -> Libraries to remove all your libraries.
  2. Delete the User -> AppData -> Local -> Arduino15 folder to remove all the preferences.
  3. Uninstall Arduino IDE.
  4. Install a fresh one.

If you used the -Mac OX  from  –

First of all, make sure to log into your Mac with an administrator account, or you will be asked for a password when you try to delete something.

Open the Applications folder in the Finder (if it doesn’t appear in the sidebar, go to the Menu Bar, open the “Go” menu, and select Applications in the list), search for Arduino 1.6.4 application by typing its name in the search field, and then drag it to the Trash (in the dock) to begin the uninstall process. Alternatively you can also click on the Arduino 1.6.4 icon/folder and move it to the Trash by pressing Cmd + Del or choosing the File and Move to Trash commands.

Remove all components related to Arduino 1.6.4 in Finder
Though Arduino 1.6.4 has been deleted to the Trash, its lingering files, logs, caches and other miscellaneous contents may stay on the hard disk. For complete removal of Arduino 1.6.4, you can manually detect and clean out all components associated with this application. You can search for the relevant names using Spotlight. Those preference files of Arduino 1.6.4 can be found in the Preferences folder within your user’s library folder (~/Library/Preferences) or the system-wide Library located at the root of the system volume (/Library/Preferences/), while the support files are located in “~/Library/Application Support/” or “/Library/Application Support/”.

Open the Finder, go to the Menu Bar, open the “Go” menu, select the entry:|Go to Folder… and then enter the path of the Application Support folder:~/Library

Search for any files or folders with the program’s name or developer’s name in the ~/Library/Preferences/, ~/Library/Application Support/ and ~/Library/Caches/ folders. Right click on those items and click Move to Trash to delete them.

 

Select NodeMCU 1.0 ( ESP-12EModule), from the list of boards in Tool-Boards menu

Choose connected NodeMCU port number and the rest of the settings values can be left to default values

Install Blynk Library for Arduino IDE

 Install Blynk as ZIP file in Arduino IDE

Blynk library is available as a downloadable ZIP.  install 3rd party libraries in the IDE, starting with Arduino IDE version 1.0.5.

 Download Blynk Library from the given below link Download Blynk Library, you should never unzip the downloaded library, leave it as is.

Download the Blynk Library

  • In the Arduino IDE, select to Sketch > Include Library > Add .ZIP Library from the drop-down list in menu
  • Choose the library zip file you have already downloaded.
  • Return to the Sketch > Include Library menu at the bottom of the drop-down menu. Now it’s ready to be used in your sketch. In your Arduino sketches directory, the zip file will already have been expanded in the libraries folder.

Install SimpleTimer for Arduino IDE

 

Repeat the above  process for the SimpleTimer library is available as a downloadable ZIP .

Download SimpleTimer Library by clicking the button: Download SimpleTimer Library

Press CNTRL + A & press DELETE to clear the Arduino IDE page

Copy Paste the code and Click upload

Arduino Code

Download the Arduino source code.

 There are two functions to send data to the Blynk App. The first function sends data of alarmPin to vo virtual of blynk app.

The Arduino Blynk library has a method called virtualWrite ( ) to write the sensor reading into virtual pins we have already configured in our Blynk app.

Before sending the values, we must configure the Wi-Fi settings.

#include <BlynkSimpleEsp8266.h>

#define BLYNK_PRINT Serial
//#include <ESP8266WiFi.h>
#include <SimpleTimer.h>


/*http://www.superkitz.com/libraries/blynk-library-master.zip */
/*http://www.superkitz.com/libraries/SimpleTimer-master.zip */
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Blynk Auth key";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Your wifi ssid";
char pass[] = "your wifi password";

const int alarmPin = A0;
SimpleTimer timer;

void sendSensor() {
  int sensorValue = analogRead(alarmPin);
  Serial.println(sensorValue);
  Blynk.virtualWrite(V0, sensorValue);  // Send the data to blynk cloud.

  if (sensorValue < 900) { // SETUP the ALARM Trigger and Send EMAIL and PUSH Notification
    Blynk.email("YourEmail@mail.com", "ESP8266 Alert", "Intruder detected");
    Blynk.notify("ESP8266 Alert - Intruder detected!");
  }
}

void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(2500L, sendSensor);
}

void loop() {
  Blynk.run();

  timer.run();
} 

Output

Whenever the alarms will trigger, an email and a push notification will be sent.

Whenever the alarms will trigger, an email and a push notification will be sent.

//Blynk API call for EMAIL sending
Blynk.email("youremail@gmail.com", "ESP8266 Alert", "Temperature over 28C!");
//Blynk API call for NOTIFICATION pushing
Blynk.notify("Intruder detected!""); 

As you can see in the example above, first line stands for calling the Blynk Email API. Execution is done with 3 parameters: email address, subject and body, pretty much familiar as in many programming languages.

Blynk Email limitation and downsides

Maximum allowed length is 120 symbols for all email + subject + message. However you can increase this limit if necessary by adding following commands to you sketch:

/#define BLYNK_MAX_SENDBYTES XXX 

Where XXX is desired max length of your email. For example for ESP you can set this to 1200 max length #define BLYNK_MAX_SENDBYTES 1200. Note that this line must be on top of any of the Blynk includes in your sketch.

The time limit between sending emails is minimum 15 seconds. In case you are using gmail you are limited with 500 mails per day (by google). Other providers may have similar limitations, so please be careful. The Blynk free cloud server gives you a maximum of 100 emails every day.

Leave a Reply