SuperKitz.com Project Manual
Wifi Intruder detector using a Reed Switch and NodeMCU(ESP8266) DIY Kit
Intruder detector System using a Window Sensor Magnetic Recessed Reed Switch and esp8266.
A Home Intruder system is defined as a network of electronics devices working together with a central control panel to protect against burglars or other home intruders etc. In this project, we design a home intrusion system or an alarm system using a wifi esp8266 module in combination with the reed sensor.
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 trigger, 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
Window Sensor Magnetic Recessed Reed Switch
Hardware
Getting
Started with
Web Switch ESP8266
NODE MCU esp8266
Node MCU is a micro controller which is made under the LUA based firmware and architecture made for IOT application . It also includes expressif systems and hardware firmware ,which is based on the ESP-12 module. It is a very capable microcontroller which can be used easily for IOT applications with the blynk-app . The features are :
- The operating voltage is 5V
- The input voltage is between 7-12 v
- Digital input/output pins are 16
- Analog i/p pins is 1
- Flash Memory is 4 MB
- SRAM is 64 KB
- CLK Speed is 80 MHz
What is Blynk?
Blynk is an app made for smartphones to communicate with Arduino and raspberry pi. It has a very neat graphical interface which makes it very easy to control and use. We use this with the NODE MCU esp8266
Pin out diagram
ESP8266
Reed switch or Window Sensor Magnetic Recessed Reed Switch
The Reed switch/Door Sensor is a simple sensor which detects when the magnet gets closer to it .
We are able to use this to make an alarm system ,where when a door/ window is opened which has a reed switch installed .It will detect that the magnet isn’t touching the reed switch , thus we can send a data to tell where the door is opened or closed . We are able to use this in tandem with the motion sensor to make the burglar alarm much more reliant .
This is also used in cycle tyres to get to know how much rotations the tire has and calculates with respect to time , how much speed the cycle is traveling in.
Read Switch
Door Sensor/Read Switch
As in the above paragraph we talked about using the reed switch as a door or a window sensor .This door sensor is also known as entry sensory, contactt sensor or window sensor .
Door sensor includes two components:
- One reed switch with two pins
- One magnet
How It Works
The magnet is attached to the door/window (moving part), and the reed switch is attached to the door frame (fixed part). The two components of the reed sensor are in contact with each other when the door is closed.
- The reed switch circuit is closed when the magnet comes in contact with the reed switch
- The reed switch circuit is open when the magnet is far away from the reed switch.
Connections
STEP1:
CONNECTING SOUND SENSOR TO NodeMCU
Connections Explained:-
One end reed switch connected to A0 and other to Vin of NodeMCU
Connect all the components provided in the kit according to the provided wiring diagram mention in the documentation.
Reed Switch Connection Diagram
With ESP8266
Setting up the Blynk App : IoT Dashboard
Now it’s time to set up the Blynk App to monitor sensor values. The first step is to install the Blynk App on your smartphone.
After the code has been uploaded to the NodeMCU. Following steps are to be performed on Blynk App.
Step 1: Create a Blynk account and select add new project and add project title and select nodeMCU
Step 2: After creating a new account, create a new project, and select your hardware.
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”
Notification of motion detection or on an event of Intruder detection will be shown below. Which would later be coded in Arduino IDE
Step 6: Choose the Virtual pin as VO
Step 7 : Program on NodeMCU and choose 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 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
In Arduino IDE, paste the link using the following sequence-:
Choose File menu -> select Preferences-> Paste copied link into the area shown in the black box in the above image. Then Close and restart the Arduino IDE.
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.
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 Library for Arduino IDE as a zip file
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 Blynk Library by clicking the button:
- 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.
If you used the Installer, Windows – from XP up to 10 –
- Delete the Documents -> Arduino -> Libraries to remove all your libraries.
- Delete the User -> AppData -> Local -> Arduino15 folder to remove all the preferences.
- Uninstall Arduino IDE.
- 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.
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 sensor value to blynk.
virtualWrite ( ) in the Arduino Blynk libraryA 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();
}
Then, click the Upload button in the Arduino IDE and wait a few seconds until you see the message “Done uploading.” in the bottom left corner.
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", "In truder detected");
//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.