Theft Detection Project

Introduction

This article is written to create a theft protection system using microcontrollers. It can benefit both beginners and more experienced programmers that have interest in the basics of home security. This design uses an accelerometer to measure displacement for protection against forced entry. A sensor to measure fluctuations in temperature in order to simulate a fire alarm and an ultrasonic sensor to monitor movement. If any of these sensors are triggered an alarm is activated and a camera turns on and takes pictures of the intruder. Bluetooth technology allows your phone to activate/deactivate the system.

Parts List

  • Mbed x2
  • MMA8452Q Accelerometer
  • TMP36 Temperature Sensor
  • HC-SR04 Ultrasonic Sensor
  • Adafruit Bluefruit LE UART Friend Bluetooth
  • LS-Y201 Camera
  • 4DGL ULCD
  • Speaker
  • 2N3904 Transistor
  • 220-1k Ohm Resistor
  • Push button x2

Schematic

/media/uploads/tkoindala3/screen_shot_2017-12-13_at_11.05.15_pm.png <<Theft Detection Code for Primary MBED>> <<

  1. include "mbed.h"
  2. include "rtos.h"
  3. include "uLCD_4DGL.h"
  4. include "MMA8452.h"
  5. include "ultrasonic.h"

Serial pc(USBTX,USBRX); Serial blue(p13,p14); DigitalOut led4(LED4); DigitalOut led3(LED3); DigitalOut led2(LED2); DigitalOut led1(LED1); AnalogIn tmp(p15); uLCD_4DGL uLCD(p9, p10, p11); MMA8452 acc(p28, p27, 100000); PwmOut speaker(p23); ultrasonic mu(p6, p7, .1, 1); Thread thread1; Thread thread2; Thread thread3; Thread thread4; Thread thread5; Thread thread6; Mutex m; DigitalOut camera_trigger(p18); DigitalOut wifi_trigger(p18); DigitalIn pb1(p20); DigitalIn pb2(p19); DigitalIn pb3(p17);

float tempC, tempF; double x, y, z, dist_accel; int dist_sonar; int i; volatile bool sound = false; volatile bool arm = false;

void temp_thread() {

while(1) {

float vin = 5.0 * LM61 / 1024.0;

tempC = (1.8663 - vin) / 0.01169; tempF = 1.8 * tempC + 32.0;

tempC = ((tmp * 3.3) * 100 - 50); tempF = 1.8 * tempC + 32.0; m.lock(); uLCD.locate(1,1); uLCD.printf("%5.2F C %5.2F F \n\r", tempC, tempF); m.unlock(); Thread::wait(900); } }

void accel_thread(){

while(1) {

acc.readXYZGravity(&x,&y,&z); m.lock(); uLCD.locate(0,3); uLCD.printf("x:%lf\n",x); uLCD.locate(0,4); uLCD.printf("y:%lf\n",y); uLCD.locate(0,5); uLCD.printf("z:%lf\n",z); m.unlock(); dist_accel = (x*x + y*y + z*z)^0.5; uLCD.printf("dist:%lf\n", dist_accel); Thread::wait(800); } }

void dist(int distance) { put code here to execute when the distance has changed uLCD.printf("Distance %d mm\r\n", distance); if less than 50mm, alarm activated }

ultrasonic mu(p6, p7, .1, 1, &dist);

void sonar_thread() { while(1) { mu.startUpdates();start measuring the distance --SONAR mu.checkDistance(); m.lock(); uLCD.locate(0,10); dist_sonar = mu.getCurrentDistance(); uLCD.printf("Distance: %d", dist_sonar); wait(0.2); uLCD.printf(" "); m.unlock(); Thread::wait(700); } }

void speaker_thread() { while(1) { led3 = !led3; if(sound){ for (i=0; i<10; i=i+2) { --SPEAKER speaker.period(1.0/969.0); speaker = float(i)/50.0; wait(.5); speaker.period(1.0/800.0); wait(.5); } } Thread::wait(600); } }

void checker_thread(){ while(1){ if(arm){ if(tempC > 27 || x > 0.3 || y < -0.5 || dist_sonar < 50){ sound = true; camera_trigger = 1; m.lock(); uLCD.printf("DONE!"); m.unlock(); for (i=0; i<10; i=i+2) { --SPEAKER speaker.period(1.0/969.0); speaker = float(i)/50.0; wait(.5); speaker.period(1.0/800.0); wait(.5); } led2 = !led2; } if(tempC < 27 || x > 0.3 || y < -0.5 || dist_sonar > 50){ sound = false; speaker = 0.0; camera_trigger = 0; } else{ sound = false; } } Thread::wait(200); }

}

int main() { pb1.mode(PullUp); pb2.mode(PullUp); pb3.mode(PullUp);

uLCD.locate(0,0); uLCD.printf("Alarm System Menu"); uLCD.locate(0,3); uLCD.printf("1: Boot System"); uLCD.locate(0,5); uLCD.printf("2: How to Guide");

while(1){ if(pb1 == 0){ uLCD.cls(); break; } if (pb2 == 0) { uLCD.cls(); uLCD.locate(0,0); uLCD.printf("Connect via BT"); uLCD.locate(0,3); uLCD.printf("'1' to arm"); uLCD.locate(0,5); uLCD.printf("'2' to disarm"); uLCD.locate(0,7); uLCD.printf("'PB1 to exit"); } }

thread1.start(temp_thread); thread2.start(accel_thread); thread3.start(sonar_thread); thread4.start(speaker_thread); thread5.start(checker_thread); thread6.start(camera_thread);

char bnum=0; char bhit=0; while(1) { m.lock(); if(blue.readable()){

if (blue.getc()=='!') { if (blue.getc()=='B') { button data packet bnum = blue.getc(); button number bhit = blue.getc(); 1=hit, 0=release

switch (bnum) { case '1': arm the system if (bhit=='1') { arm = true; pin = 0; led1 = 1; } break; case '2': disarm the system if (bhit=='1') { arm = false; led1 = 0; } break; case '3' : email for help if (bhit = '1') {

} break; default: break; } } } } m.unlock(); Thread::wait(100); }

}

<<Theft Detection Code for Secondary MBED>> <<

  1. include "mbed.h"
  2. include "uLCD_4DGL.h"
  3. include "JPEGCamera.h"

DigitalOut myled1(LED1); show successful picture was taken DigitalOut myled2(LED2); show end of sequence DigitalOut myled3(LED3); show picture take failed DigitalOut myled4(LED4); show camera is not ready uLCD_4DGL uLCD(p9, p10, p11); DigitalIn signal(p20); Serial pc(USBTX, USBRX);

int main() { uLCD.printf("HeLLO"); while(1) { pc.printf("Signal is: %f \n", signal); if(signal == 1) { uLCD.printf("Hello"); JPEGCamera camera(p13, p14); TX, RX LocalFileSystem local("local"); save images on mbed camera.setPictureSize(JPEGCamera::SIZE640x480); Timer timer; timer.start(); if(camera.setPictureSize(JPEGCamera::SIZE640x480)) { myled1 = 1; wait(2.0); myled1 = 0; wait(2.0); } for (int i = 1; i < 5; i++) { if (camera.isReady()) { char filename[32]; sprintf(filename, "/local/pict%03d.jpg", i); uLCD.printf("Picture: %s \n", filename); if (camera.takePicture(filename)) { while (camera.isProcessing()) { camera.processPicture(); }

myled1 = 1; show successful picture was taken wait(2.0); myled1 = 0; } else { uLCD.printf("take picture failed\n"); myled3 = 1; show picture take failed wait(2.0); myled3 = 0; } } else { uLCD.printf("camera is not ready\n"); myled4 = 1; show camera is not ready wait(2.0); myled4 = 0; } } myled2 = 1; show end of sequence wait(2.0); myled2 = 0; uLCD.printf("time = %f\n", timer.read()); } } } >>

Hardware Connections

/media/uploads/tkoindala3/screen_shot_2017-12-11_at_2.59.44_pm.png /media/uploads/tkoindala3/screen_shot_2017-12-11_at_3.01.13_pm.png /media/uploads/tkoindala3/screen_shot_2017-12-11_at_3.02.23_pm.png /media/uploads/tkoindala3/screen_shot_2017-12-11_at_3.05.38_pm.png /media/uploads/tkoindala3/screen_shot_2017-12-11_at_3.03.32_pm.png /media/uploads/tkoindala3/screen_shot_2017-12-11_at_3.04.48_pm.png /media/uploads/tkoindala3/screen_shot_2017-12-11_at_3.09.05_pm.png

Images from Jim Hamblen's notebook pages

/media/uploads/tkoindala3/25383147_1927964967219237_980010178_o.jpg

Project Created By

Tej Koindala Julio Garcia Jeffrey Twitchell Sarthak Batra


Please log in to post comments.