TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Raspberry Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • Ferminal
    • Crypto Tracker
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me

What is it?


I wanted to create a system that would inform a parent or carer that a back door was opened or a security conscientious home owner that a window or a door had been opened.  We spend so much time with our mobile devices in out hand it seem obvious to use this as one method of alert.  So I created a simple prototype.                               (This will be developed further for a real door)
Picture

What it does?


The program is simple; a Green LED lights up if the door is closed and a message is outputted to the console screen and the system emails you a simple message to inform you that the door is closed.  Open the door, force it open, break it down and PiBrella kicks into action.  The Red LED flashes to warn of the danger! The ‘ear piercing buzzer’ provides an audio warning and again you are emailed to inform you that the door is open and someone / thing is going out or coming in! 

1. Sending an Email


The email component makes use of Python’s smtplib module which needs to be imported at the start of the program.  I used a G-Mail account which requires port 587.  You will be required to log into your account with the command server.login, followed by your email address and your password.   For example:

import smtpblib
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login("
your_email_address_here", "your_password_here")


The final part of the code requires you to create a variable,  called message and identify the sender and receiver of the email by their email addresses.

message = "message_content_you_want_to_send" 
server.sendmail("sender_email_address", "recipients_email", message


A more detailed overview of the code can be found here

Alarm System in Action



2. The Pibrella Code


The second part of the system makes use of Python’s Pibrella library to read the state of input A, return the value and then trigger the LED OR Buzzer.   This is achieved with the code if pib.input.a.read()==1: which checks that input A is connected and a current is flowing, completing the circuit.  If the circuit is broken then the input is read as '0' and the code responds triggering the buzzer and red LED.  The only missing ingredient is some conductive paint which enables the lego door to become conductive and complete or break the circuit.  An example of the code for the output, when the door is opened looks something like this:

 if pib.input.a.read()==1:
       pib.buzzer.off()
       print "THE DOOR IS NOW CLOSED " + time_of_event
       pib.light.red.off()
       pib.light.green.on()
      t
ime.sleep(5) 


A function called send_an_email_closed() was created to hold the code for the email which could send an email if triggered in the IF / ELIF statement and I also included the current time that the door was opened / closed with the code time_of_event = time.asctime(time.localtime(time.time())).  Then just film, add some titles and some tense theme music!   

The Final Code


Final Code
File Size: 1 kb
File Type: py
Download File

Powered by Create your own unique website with customizable templates.