Log in to your Raspberry Pi using the Adafruit WebIDE and create a new file. Mine's called SitcomSFX.py

Upload two audio files to that directory, one named "enter.wav" the other "exit.wav"

You can find pretty decent sound clips here & here, and more professional ones here.

If you are using the 1/8inch audio jack, you'll need to ssh into your Pi and run this command to route audio to that output
$ sudo amixer cset numid=3 1
#!/usr/bin/env python

from time import sleep

import pygame.mixer
import RPi.GPIO as GPIO


door_switch_pin = 23
motion_sensor_pin = 24

#Set up inputs
GPIO.setup(door_switch_pin, GPIO.IN)
GPIO.setup(motion_sensor_pin, GPIO.IN)

motion_LED_pin = 18
door_LED_pin = 25

#Set up output LED indicators
GPIO.setup(door_LED_pin, GPIO.OUT)
GPIO.setup(motion_LED_pin, GPIO.OUT)

pygame.mixer.init(44100, -16, 2, 1024)

prev_door = False

#sound files expect to be in the same directory as script
enter = pygame.mixer.Sound("./enter.wav")
exit = pygame.mixer.Sound("./exit.wav")

while True:
	#Update sensor and LED states each loop
	door = GPIO.input(door_switch_pin)
	motion = GPIO.input(motion_sensor_pin)

	GPIO.output(motion_LED_pin, motion)
	GPIO.output(door_LED_pin, door)
#When the door is opened, if there is movement outside, it means that someone is entering. If not, someone is exiting		
	if door and not prev_door:		
		if motion:
	prev_door = door
Run the code on your Pi and make sure it works. If the green LED is lit (motion detected) it should play enter.wav when the door switch is opened, and exit.wav if there is no motion detected. 

The PIR sensor has two physically adjustable potentiometers on it, I've found it's best to set it to max sensitivity and minimum retrigger time. For more info, check out the PIR tutorial

Now lets mount it!
Last updated on 2015-05-04 at 04.27.11 PM Published on 2012-12-20 at 07.35.26 AM