WiFi Security System

by millerman4487 in Circuits > Arduino

2462 Views, 19 Favorites, 0 Comments

WiFi Security System

IMG_20171209_101303378-01.jpeg
Screenshot_20171209-091240.png

This project will track movement and the light level of the surrounding area. You can put this in your room to let you know if your dog is snooping around, use it as a home security system, or to find Santa in your house on Christmas eve.

Set Up the Circuit

Untitled Sketch_bb.png
IMG_20171209_101404662-01.jpeg
IMG_20171209_101528711.jpg
IMG_20171209_101601667.jpg

Using a breadboard and jumper wires, follow the diagram to build this circuit. To power it, use a micro-USB cable.

Set Up the App

Screenshot_20171209-091240.png
Screenshot_20171209-101753.png
Screenshot_20171209-101758.png
Screenshot_20171209-101812.png
Screenshot_20171209-101825.png
Screenshot_20171209-101834.png

In the Blynk app you need to create these widgets:

  • A SuperChart
  • Two Gauges

One gauge is for tracking the light level and the other is for movement. The SuperChart is used to track both of these over time. Follow the pictures for how to set them up.

Upload the Code

IMG_20171209_101710701-01.jpeg

Upload this code to your Blynk Board in the Arduino IDE and remember to change these three things:

  • char BlynkAuth[] = "yourauthcode";
  • char WiFiNetwork[] = "yournetworkname";
  • char WiFiPassword[] = "yourwifipassword";
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define BLYNK_PRINT Serial

char BlynkAuth[] = "";
char WiFiNetwork[] = "";
char WiFiPassword[] = "";

int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;

void setup() {
  pinMode(A0, INPUT);
  Blynk.begin(BlynkAuth, WiFiNetwork, WiFiPassword);
  pinMode(12, INPUT);
  digitalWrite(12, LOW);
  for (int i = 0; i < calibrationTime; i++) {
    delay(1000);
  }
  delay(50);
}

void loop() {
  Blynk.run();
}

BLYNK_READ(V5) {              //hardware to app
  int light = analogRead(A0);
  Blynk.virtualWrite(5, light);
}

BLYNK_READ(V4) {              //hardware to app
  if (digitalRead(12) == HIGH) {
    if (lockLow) {
      lockLow = false;
      delay(50);
    }
    takeLowTime = true;
  }
  if (digitalRead(12) == LOW) {
    if (takeLowTime) {
      lowIn = millis();          //save the time of the transition from high to LOW
      takeLowTime = false;       //make sure this is only done at the start of a LOW phase
    }
    if (!lockLow && millis() - lowIn > pause) {
      lockLow = true;
      delay(50);
    }
  }

  Blynk.virtualWrite(4, digitalRead(12));
}

You will need to have the Blynk library installed in order for this code to work. Download it in the attached file.

How to install a Library: www.arduino.cc/en/Guide/Libraries