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)
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:
server = smtplib.SMTP('smtp.gmail.com', 587)
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:
print "THE DOOR IS NOW CLOSED " + time_of_event
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