Raspberry Pi Door Sensor

Feb 26, 2015 by Naomi Category: Blog, Brand New 0 comments

“Raspberry Pi Door Sensor” is a little unimaginative, wouldn’t you agree?  Please help us name our door sensor?

Raspberry Pi’s are being talked about all over the tech community at the moment, they’re an exciting bit of kit creating endless possibilities.  Here at SoBytes we’ve introduced ‘Fun Day Friday’ purely so we get to play with a Raspberry Pi, hack a new product together and have fun.

Our first Friday we managed to get a tiny little light bulb working from a computer.  This sounds like a basic task, and yes you’re correct in thinking this.  However, the excitement in the office would make you believe we’d taken control of Las Vegas.  The blinking light unlocked SoBytes ability to start accomplishing numerous other projects with the Raspberry Pi.

Next Friday we moved on from blinking lights and set up a security camera next to the office door. The camera is connected to the Raspberry Pi, the Raspberry Pi sends a signal over WiFi and the computer then picks up HD quality video footage of anyone who walks through the door.  Needless to say our co-workers turned the camera upside down, no one likes to be spied on.  It worked though and that’s all we care about.

Moving onto the exciting door sensor product.  For now we have pinned a magnetic sensor to the door (we would love a mini laser beam).  Similar to the camera, this links to the Raspberry Pi, however we’ve added on a set of speakers.  The video (below)  shows the sensor working, we currently have it set up so that music plays every time someone opens the door.

We plan to progress with this idea as we believe there are so many ways to use it.  Our next step is to build an app to liaise with the Raspberry Pi.  With the app you can record your own messages, upload music or sound bites or type notifications.  The basic idea is that each time you open the door your phone can remind you not to forget whatever it is you might need that day. Milk for the office, for example, always need a cup of tea to start the day.

If like us, you think this is an awesome idea, please feel free to get in touch, we’d love to hear your name ideas, what shall we call the app?  We’ve found over the years that sharing ideas builds a more creative working environment. Thanks for following us and please keep supporting us.

# Imports
import picamera
import sys
import time
import RPi.GPIO as GPIO
import os
import json
import tinys3
import requests
from time import gmtime, strftime

# Variables
PIN = 16                                # Pin we are using to read the door switch
prev_input = 0                  # Variable to track if door was opened

# Setup the GPIO
GPIO.setmode(GPIO.BCM)          # GPIO layout mode
GPIO.setup(PIN,GPIO.IN)         #Setup the gpio pin we are reading from as an input

# Loop checking the switch
while True:
  # Read the switch value
  input = GPIO.input(PIN)

  # If the last reading was low and this one high, run our function
  if ((not prev_input) and input):
    print("Door Open")

    os.system('omxplayer -o local song.wav')
  # Update previous input
  prev_input = input
  # Wait slightly for debounce
  time.sleep(0.05)

 

Leave a Comment!

Your email address will not be published. Required fields are marked *