amrmostaafaa
Published

Security System Using Arduino Bluetooth Camera

A security system using the Arduino Bluetooth Camera and ultrasonic to detect that a stranger has entered house and capture a photo of him.

BeginnerFull instructions provided1 hour39,560
Security System Using Arduino Bluetooth Camera

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
USB-A to B Cable
USB-A to B Cable
×4
Android device
Android device
×1
1Sheeld
1Sheeld
×1

Story

Read more

Schematics

circuit

Code

Arduino_Security_Bluetooth_Camera_using_1Sheeld.ino

Arduino
/*
  Security System using Arduino Bluetooth Camera Project

  This project shows an application on 1Sheeld's camera shield.

  By using this project, you can track whether anything stranger
  has entered your house and capture his photo  by using camera
  shield from 1Sheeld.
  
  OPTIONAL:
  To reduce the library compiled size and limit its memory usage, you
  can specify which shields you want to include in your sketch by
  defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define.
*/

/* Include required shields */
#define CUSTOM_SETTINGS
#define INCLUDE_CAMERA_SHIELD
#define INCLUDE_BUZZER_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_TEXT_TO_SPEECH_SHIELD

/* A command which will be converted to speech */
const char command[] = "warning a stranger has entered your house";

/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* Define pins for the ultrasonic sensor */
const int trigPin = 9;
const int echoPin = 10;

/* Variable to save the measured distance from ultrasonic */
int distance;

void setup() 
{
  pinMode(trigPin, OUTPUT);     // Sets the trigPin as an Output
  pinMode(echoPin, INPUT);      // Sets the echoPin as an Input
  
  /* Start 1Sheeld communication. */
  OneSheeld.begin();
}
void loop()
{
  /* Get the current distance from the ultrasonic */
  distance = getUltrasonicDistance();

  /* Print the distance on the Terminal shield */
  Terminal.println(distance);
  
  /* Check if distance is less than 10cm which means that a stranger has entered the house */
  if (distance < 10)
  {
    /* Turn on the camera's flash while capturing */
    Camera.setFlash(ON);
    
    /* Take a photo for that stranger using the phone's rear camera */
    Camera.rearCapture();

    /* Also turn the alarm in form of a buzzer */
    Buzzer.buzzOn();
    
    /* Delay for 2 seconds */
    OneSheeld.delay(2000);

    /* Turn the alarm off */
    Buzzer.buzzOff();
    
    /* Use text-to-speech shield to announce a break into security orally */
    TextToSpeech.say(command);

    /* Delay for 5 seconds to give the camera shield enough time for taking and saving the photo */
    OneSheeld.delay(5000);
  }
}

/* A function that makes the whole operation of the ultrasonic and returning the detected distance */
long getUltrasonicDistance(void)
{
  /* Variable to save the sound wave travel time in microseconds */
  long duration;

  /* Variable to save the detected distance in cm */
  long distanceReturned;
  
  /* Clears the trigPin */
  digitalWrite(trigPin, LOW);

  /* delay 2 micro seconds */
  delayMicroseconds(2);

  /* Sets the trigPin on HIGH state for 10 micro seconds */
  digitalWrite(trigPin, HIGH);

  /* delay 10 micro seconds */
  delayMicroseconds(10);

  /* Sets the trigPin on LOW state */
  digitalWrite(trigPin, LOW);
  
  /* Reads the echoPin, returns the sound wave travel time in microseconds */
  duration = pulseIn(echoPin, HIGH);

  
  /* Calculating the distance */
  distanceReturned = duration * 0.034 / 2;

  /* Returning the detected distance in cm */
  return distanceReturned;
}

Credits

amrmostaafaa

amrmostaafaa

7 projects • 44 followers
Maker, Engineer, dreamer and passionate about technology.

Comments