├── LICENSE ├── README.md └── motion.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Initial State 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with the Pi Zero W - Motion Dashboard 2 | 3 | ![pizerow motion main](https://cloud.githubusercontent.com/assets/10930201/24424627/d781e274-13c6-11e7-8edb-403f21ac2e6f.png) 4 | 5 | Raspberry Pi just released what we've all been waiting for - the [Pi Zero W](https://www.raspberrypi.org/blog/raspberry-pi-zero-w-joins-family/). A full Linux computer complete with WiFi, bluetooth, and a camera connector! And the best part? It's only $10. 6 | 7 | In honor of this most exciting board, we've put together a quick little tutorial on hooking up a streaming motion sensor to your new little Pi Zero W! We'll go through board setup, connecting the sensor, and creating your own live motion dashboard. [Read more...](https://github.com/initialstate/pi-zero-w-motion-sensor/wiki) 8 | -------------------------------------------------------------------------------- /motion.py: -------------------------------------------------------------------------------- 1 | import RPi.GPIO as GPIO 2 | from time import sleep 3 | from ISStreamer.Streamer import Streamer 4 | 5 | # Tell the Pi we're going to use it's numbering system 6 | GPIO.setmode(GPIO.BCM) 7 | # Pin that D1 is connected to 8 | PIN=23 9 | 10 | # Specify our pin as input 11 | GPIO.setup(PIN,GPIO.IN) 12 | 13 | # Initial State bucket name (displayed) 14 | BUCKET_NAME = ":wave: Motion Sensor" 15 | # Initial State bucket key (hidden) 16 | BUCKET_KEY = "pizerowmotion" 17 | # Initial State access key 18 | ACCESS_KEY = "Your_Access_Key_Here" 19 | 20 | # Variables that ensure we don't stream "Motion Detected" or "No Motion" twice in a row 21 | # This saves on sent events and processing power 22 | alreadyRecordedMotion = False 23 | alreadyRecordedNoMotion = False 24 | 25 | # Initialize the Initial State Streamer 26 | streamer = Streamer(bucket_name=BUCKET_NAME, bucket_key=BUCKET_KEY, access_key=ACCESS_KEY) 27 | 28 | # Loop indefinitely 29 | while True: 30 | # If the motion sensor pulls high (detects motion): 31 | if GPIO.input(PIN) == 1: 32 | print "Motion detected" 33 | # If we haven't streamed yet: 34 | if not alreadyRecordedMotion: 35 | # Stream to Initial State 36 | streamer.log(":spy: Anybody Around?",":runner: Motion Detected") 37 | streamer.flush() 38 | alreadyRecordedMotion = True 39 | alreadyRecordedNoMotion = False 40 | else: 41 | # Pause the script for 1 second 42 | sleep(1) 43 | else: 44 | print "No motion detected" 45 | # If we haven't streamed yet: 46 | if not alreadyRecordedNoMotion: 47 | # Stream to Initial State 48 | streamer.log(":spy: Anybody Around?",":no_pedestrians: No Motion") 49 | streamer.flush() 50 | alreadyRecordedNoMotion = True 51 | alreadyRecordedMotion = False 52 | else: 53 | # Pause the script for 1 second 54 | sleep(1) 55 | --------------------------------------------------------------------------------