Search

Kevin Bearam's Raspberry PiEta

Explore my experience with Raspberry Pi in my System Integration course.

Finally, Let’s Run it!

IMG_9413.PNG

Conclusion

In conclusion, this project was beneficial because I learned a lot and was able to obtain a solution to my problem of protecting confidential items in my office. I am beyond thankful for the opportunity that this course provided me which allowed me to create something and add my own features to it. In the future, I wish to add a feature that sends a text message alert when someone is detected and also have an increase in the alarm volume once someone is in front of the sensor for an extended period of time.

 

References:

https://diyhacking.com/raspberry-pi-gpio-control/

http://www.tutorialspoint.com/python/python_sending_email.htm

Coding

I used RPi.GPIO to connect the LEDs to GPIOs, time for sensor purposes, pygame for the alarm to sound and stop, smtplib to send emails from the pi to my email, and email libraries which forms the structure of the email. I started by initializing which GPIO’s I was using, then writing the IF statement which set the condition for the LED to react when the sensor detects something or someone. The sensor detecting someone leads to LED blink. LED blink triggers the alarm to go off. As a result of the alarm going off, I receive an email notification which tells me that  someone was detected.

Final Code:

import RPi.GPIO as GPIO

import time
import pygame
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email import Encoders
import os
gmail_user = “thenextwade3@gmail.com”
gmail_pwd = “johnwall11”
def mail(to, subject, text): #attach):
  msg = MIMEMultipart()
  msg[‘From’] = gmail_user
  msg[‘To’] = ‘, ‘.join(to)
  msg[‘Subject’] = subject
  msg.attach(MIMEText(text))
 # part = MIMEBase(‘application’, ‘octet-stream’)
 # part.set_payload(open(attach, ‘rb’).read())
  #Encoders.encode_base64(part)
 # part.add_header(‘Content-Disposition’,
          #’attachment; filename=”%s”‘ % os.path.basename(attach))
  #msg.attach(part)
  mailServer = smtplib.SMTP(“smtp.gmail.com”, 587)
  mailServer.ehlo()
  mailServer.starttls()
  mailServer.ehlo()
  mailServer.login(gmail_user, gmail_pwd)
  mailServer.sendmail(gmail_user, to, msg.as_string())
  # Should be mailServer.quit(), but that crashes…
  mailServer.close()
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(16,GPIO.IN)
GPIO.setup(25,GPIO.OUT)
pygame.init()
pygame.mixer.music.load(“/usr/share/scratch/Media/Sounds/Electronic/Whoop.wav”)
#pygame.mixer.music.play()
#pygame.event.wait()
while True:
    i=GPIO.input(16)
    if i==0:
        print “Coast is Clear”, i
        GPIO.output(25,0)
        time.sleep(0.1)
    elif i==1:
        print “ALERT ALERT”, i
        GPIO.output(25,1)
        pygame.mixer.music.play()
        mail(“kevinbearam@yahoo.com”,
  “Pi Alert”,
  “Hello Kevin, This is you raspberry Pi Eta. We have detected someone trying to enter the premisis!!”)
  #”/home/pi/scripts.tar”)
        pygame.time.wait(8000)
        time.sleep(0.1)

Casing

I cut a whole in a black plastic for the sensor, and nailed wood to surround the breadboard and portable speaker. The final project is shown as the sensor poking out ofthe front, and Pi strapped on the side. The casing took lots of trial and error, broken wood, wasted nails, and mistakenly injured my finger hammering so BE CAREFUL!

Demo

This is my demo of what has been completed so far. The system will print “Coast is Clear 0” when nothing is detected. It will print “Person Detected 1” when something is detected. Also, when something is detected, the LED will begin to light up. As a result of the LED lighting up, the alarm will begin to sound. Moving forward, I will begin looking into receiving an alert message to my phone when the alarm sounds.

projectview

Alarm Sound selection

After selecting my sound, I used “Ctrl + C” to cancel the sounds from continuing. Then I played the sound I selected separately as shown below, beginning with “omxplayer Wave…”

chosenwav

Directory Sounds

The Pi already contains sounds, so to hear those I browsed the directory for wav files (left). Various sounds in various categories began to play. Since my project is an alarm system, I waited until I heard an “alarm-like” sound.

 

Alsamixer & Speaker Testing

Before I use the speaker, which is used for the alarm, I have to make sure all ports are fully plugged in. After, to make sure the volume is up, use “alsamixer” to check the volume. Thirdly, once volume was up, I was able to test the speaker for sound using “speaker-test”. This gave me a blank white sound which let me know the speaker was ready to go.

alsamixer-and-speakertest

Create a free website or blog at WordPress.com.

Up ↑

Design a site like this with WordPress.com
Get started