Distance-Senstitive Monitoring and Surveillance System

This system can detect any object approaching then takes a photo and sends it to a social media.

IntermediateWork in progress125
Distance-Senstitive Monitoring and Surveillance System

Things used in this project

Story

Read more

Schematics

Connection Diagram

Code

Ultrasonic code

Python
#Libraries
import RPi.GPIO as GPIO
import time
 
#GPIO Mode (BOARD / BCM)
GPIO.setmode(GPIO.BCM)
 
#set GPIO Pins
GPIO_TRIGGER = 23
GPIO_ECHO = 24
 
#set GPIO direction (IN / OUT)
GPIO.setup(GPIO_TRIGGER, GPIO.OUT)
GPIO.setup(GPIO_ECHO, GPIO.IN)
 
def distance():
    # set Trigger to HIGH
    GPIO.output(GPIO_TRIGGER, True)
 
    # set Trigger after 0.01ms to LOW
    time.sleep(0.00001)
    GPIO.output(GPIO_TRIGGER, False)
 
    StartTime = time.time()
    StopTime = time.time()
 
    # save StartTime
    while GPIO.input(GPIO_ECHO) == 0:
        StartTime = time.time()
 
    # save time of arrival
    while GPIO.input(GPIO_ECHO) == 1:
        StopTime = time.time()
 
    # time difference between start and arrival
    TimeElapsed = StopTime - StartTime
    # multiply with the sonic speed (34300 cm/s)
    # and divide by 2, because there and back
    distance = (TimeElapsed * 34300) / 2
 
    return distance
 
if __name__ == '__main__':
    try:
        while True:
            dist = distance()
            print ("Measured Distance = %.1f cm" % dist)
            time.sleep(1)
 
        # Reset by pressing CTRL + C
    except KeyboardInterrupt:
        print("Measurement stopped by User")
        GPIO.cleanup()

Telegram Bot with Camera module

Python
import teleport
import time
from picamera import PiCamera
 
 
 
def handle(msg):
    chat_id = msg['chat']['id']
    command = msg['text']
    print(msg['chat']['username'])
    print('Got command: %s' % command)
    if command == '/start':
            bot.sendMessage(chat_id, 'program successfully started')
      
    if command == '/photo':
            camera.capture('/home/pi/Desktop/1.jpg')
            bot.sendPhoto(chat_id,open('/home/pi/Desktop/1.jpg','rb'))
 
 
 
 
       
camera=PiCamera()       
bot = telepot.Bot('273667621:AAEW2fCUbywfss83SwhRc7XwAw9_jZDGekU')ا  
bot.message_loop(handle)
print('The code is running')
 
while 1:
    time.sleep(1)

Camera module

Python
from picamera import PiCamera

from time import sleep

 camera = PiCamera()

 camera.start_preview()

 sleep(10)

 camera.stop_preview()

Credits

Danial Haji aqa babaei

Danial Haji aqa babaei

1 project • 3 followers
Never give up
Ehsan Aerabi

Ehsan Aerabi

18 projects • 60 followers
Researcher on IoT and Embedded Systems
Ahmad Tavakoli

Ahmad Tavakoli

1 project • 2 followers
Hossein

Hossein

1 project • 3 followers
Erfan Saghabashi

Erfan Saghabashi

1 project • 22 followers

Comments