Sergiu PetrovMarius Nedelcu
Published

Alarm System

A proximity detector alarm system.

IntermediateFull instructions provided306
Alarm System

Things used in this project

Hardware components

Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×10
LED (generic)
LED (generic)
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian
Python

Story

Read more

Schematics

Alarm System Circuit Diagram

Code

Program

Python
import sys
import RPi.GPIO as GPIO
import time
import smtplib

GPIO.setmode(GPIO.BCM)

buzzer = 23
trig = 3
echo = 4
GPIO.setwarnings(False)

GPIO.setup(2,GPIO.OUT)
GPIO.output(2,0)

GPIO.setup(buzzer,GPIO.OUT)
GPIO.setup(trig,GPIO.OUT)
GPIO.setup(echo,GPIO.IN)

GPIO.output(trig, False)
time.sleep(0.5)

while True:
        GPIO.output(trig, True)
        time.sleep(0.00001)
        GPIO.output(trig, False)

        while GPIO.input(echo)==0:
          pulse_start = time.time()

        while GPIO.input(echo)==1:
         pulse_end = time.time()

        pulse_duration = pulse_end - pulse_start
        distance = pulse_duration * 17150
        distance = round(distance, 2)
        print("Distance:",distance,"cm")

        if distance <= 15:
                GPIO.output(buzzer,GPIO.HIGH)
                server=smtplib.SMTP('smtp.gmail.com',587)
                server.starttls()
                server.login("proiect.smlab","SMlab12345")
                msg="A trecut cineva pe langa sensor"
                server.sendmail("[email protected]","[email protected]",msg)
                server.quit()
                time.sleep(0.5)
        else:
                GPIO.output(buzzer,GPIO.LOW)
                time.sleep(0.5)
GPIO.cleanup()
sys.exit()

Interface

PHP
<html>
<head>
<?php

if (isset($_POST['start'])) //Start
{
exec('sudo python /var/www/proiectSM.py');
}

if (isset($_POST['stop']))  //  Stop
{
exec('sudo python /var/www/led_On.py');
exec('sudo pkill -f /var/www/proiectSM.py');
}
?>

  <title>Alarma </title>
</head>
<body background="FX3.png">
<center>
<table witdh="400" border="1" bgcolor="silver">
<td>

<Font color='blue'><b>
<center>
Universitatea Tehnica 'Gh.Asachi' Iasi - Fac. Automatica si Calculatoare<br>
<br>
</Font><b>
<center> <h1> <Font color='navy'>
Alarma<br>

</h1></font>
<center>

<form method="post">
  <table
 style="width: 50%; text-align: left; margin-left: auto; margin-right: auto;"
 border="1" cellpadding="2" cellspacing="2">
      <tr>
        <td style="text-align: center;"><button name="start"><font face="impact" color="green">Start</button></td></font>
        <td style="text-align: center;"><button name="stop"><font face="impact" color="red">Stop </button></td> </font>
      </tr></font>
 </table>

</form>
<font color="navy">
<br>
&copy 2021 Fac. Automatica si Calculatoare

</td>
</table>

</body>
</html>

Led

Python
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(2,GPIO.OUT)

GPIO.output(2,1)

Credits

Sergiu Petrov
1 project • 0 followers
Marius Nedelcu
1 project • 0 followers

Comments