Ultra Anti-Theft System

This security system aims to equip rooms with a cheap but fairly reliable system using ultrasonic sensors to detect movement.

BeginnerFull instructions provided24 hours1,744
Ultra Anti-Theft System

Things used in this project

Hardware components

CC3200-LAUNCHXL SimpleLink CC3200 Wi-Fi LaunchPad
Texas Instruments CC3200-LAUNCHXL SimpleLink CC3200 Wi-Fi LaunchPad
create a web server
×1
MSP-EXP430G2 MSP430 LaunchPad
Texas Instruments MSP-EXP430G2 MSP430 LaunchPad
for ultra sonic and server motor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Energia
Texas Instruments Energia

Story

Read more

Code

code for web server

C/C++
#ifndef _CC3200R1M1RGC_
// Do not include SPI for CC3200 LaunchPad
#include <SPI.h>
#endif
#include <WiFi.h>

// your network name also called SSID
char ssid[] = "rohit";
// your network password
char password[] = "234567891";
// your network key Index number (needed only for WEP)
int keyIndex = 0;

WiFiServer server(80);

void setup() {
  Serial.begin(9600);      // initialize serial communication
  pinMode(RED_LED, OUTPUT);      // set the LED pin mode

  // attempt to connect to Wifi network:
  Serial.print("Attempting to connect to Network named: ");
  // print the network name (SSID);
  Serial.println(ssid); 
  // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED) {
    // print dots while we wait to connect
    Serial.print(".");
    delay(300);
  }
  
  Serial.println("\nYou're connected to the network");
  Serial.println("Waiting for an ip address");
  
  while (WiFi.localIP() == INADDR_NONE) {
    // print dots while we wait for an ip addresss
    Serial.print(".");
    delay(300);
  }

  Serial.println("\nIP Address obtained");
  
  // you're connected now, so print out the status  
  printWifiStatus();

  Serial.println("Starting webserver on port 80");
  server.begin();                           // start the web server on port 80
  Serial.println("Webserver started!");
}

void loop() {
  int i = 0;
  WiFiClient client = server.available();   // listen for incoming clients
  int k =digitalRead(4);
  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    char buffer[150] = {0};                 // make a buffer to hold incoming data
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character
           
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (strlen(buffer) == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.println("<html><head><title>Energia CC3200 WiFi Web Server</title></head><body align=center>");
            client.println("<h1 align=center><font color=\"blue\">THEFT DETECTION STYSTEM - ROOM :-6</font></h1>");
            client.print("System <button onclick=\"location.href='/H'\">ON</button>");
            client.println(" <button onclick=\"location.href='/L'\">OFF</button><br>");
            if(k==1)
             {if (digitalRead(RED_LED)==HIGH)
               {client.println("<h1 align=center><font color=\"red\">ALERT:INTRUSION HAS OCCURED</font></h1>");
                digitalWrite(7,HIGH);
                delay(15000);
                digitalWrite(7,LOW);}
             }
            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          }
          else {      // if you got a newline, then clear the buffer:
            memset(buffer, 0, 150);
            i = 0;
          }
        }
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          buffer[i++] = c;      // add it to the end of the currentLine
        }
         
        // Check to see if the client request was "GET /H" or "GET /L":
        if (endsWith(buffer, "GET /H")) {
          digitalWrite(RED_LED, HIGH);   // GET /H turns the LED on
         
        }
        if (endsWith(buffer, "GET /L")) {
          digitalWrite(RED_LED, LOW);                // GET /L turns the LED off
        }
         }
      
    }
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

//
//a way to check if one array ends with another array
//
boolean endsWith(char* inString, char* compString) {
  int compLength = strlen(compString);
  int strLength = strlen(inString);
  
  //compare the last "compLength" values of the inString
  int i;
  for (i = 0; i < compLength; i++) {
    char a = inString[(strLength - 1) - i];
    char b = compString[(compLength - 1) - i];
    if (a != b) {
      return false;
    }
  }
  return true;
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID:");
  Serial.println(WiFi.SSID());

  // print your WiFi IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  // print where to go in a browser:
  Serial.print("To see this page in action, open a browser to http://");
  Serial.println(ip);
}

code for ultra sonic sensors and servo motor

C/C++
#include <Servo.h> 

Servo sg90servo;    // create servo object to control a servo 
int angle = 0;    // variable to store the servo position 

const int trigPin = 6;
const int echoPin = 3;

void setup() {
  // initialize serial communication:
  sg90servo.attach(4);
  Serial.begin(9600);
  pinMode(8,OUTPUT);
 // pinMode(5,OUTPUT);
 pinMode(10,INPUT);
}

void loop() {
  // establish variables for duration of the ping, and the distance result
  // in inches and centimeters:
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH pulse
  // whose duration is the time (in microseconds) from the sending of the ping
  // to the reception of its echo off of an object.
  pinMode(trigPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  if(cm<=30){
    Serial.println("Alert");
    digitalWrite(8,HIGH);
    delay(5000);
    for(angle = 0; angle< 180; angle++)  // goes from 0 degrees to 180 degrees 
  {                                       // in steps of 1 degree 
    sg90servo.write(angle);              // tell servo to go to position in variable 'angle 
    delay(20);                       // waits 20ms for the servo to reach the position 
  } 
  }
  if(cm>30){
    digitalWrite(8,LOW);
  }
    delay(1000);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  if(digitalRead(10)==HIGH)
   for(angle = 0; angle< 180; angle++)  // goes from 0 degrees to 180 degrees 
  {                                       // in steps of 1 degree 
    sg90servo.write(angle);              // tell servo to go to position in variable 'angle 
    delay(20);                       // waits 20ms for the servo to reach the position 
  } 

  delay(100);
}

long microsecondsToInches(long microseconds) {
  // According to Parallax's datasheet for the PING))), there are 73.746
  // microseconds per inch (i.e. sound travels at 1130 feet per second).
  // This gives the distance travelled by the ping, outbound and return,
  // so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds) {
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the object we
  // take half of the distance travelled.
  return microseconds / 29 / 2;
}

Credits

rohit khoja
1 project • 3 followers
Contact
Anirudh Menon
1 project • 7 followers
Contact
Texas Instruments University Program
91 projects • 120 followers
TI helps students discover what's possible to engineer their future.
Contact
MANAN LOHANI
1 project • 1 follower
Contact
Navneet
2 projects • 5 followers
Interested in IoT, and Embedded systems,Image Processing
Contact
Krishna Gundu
1 project • 2 followers
Contact

Comments

Please log in or sign up to comment.