#!/usr/bin/env python from time import sleep import pygame.mixer import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) motion_sensor_pin = 24 #Set up inputs GPIO.setup(motion_sensor_pin, GPIO.IN) motion_LED_pin = 18 #Set up output LED indicators GPIO.setup(motion_LED_pin, GPIO.OUT) pygame.mixer.init(44100, -16, 2, 1024) #sound files expect to be in the same directory as script enter = pygame.mixer.Sound("./enter.wav") while True: #Update sensor and LED states each loop motion = GPIO.input(motion_sensor_pin) GPIO.output(motion_LED_pin, motion) #When the door is opened, if there is movement outside, it means that someone is entering. If not, someone is exiting if motion: enter.play() sleep(0.01)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question