[{"element_type":"markdown","content":"\u003ch2\u003eIntroduction\u003c/h2\u003e\n\n\u003cp\u003eThe motion detector will be deployed alongside the \u003ca href=\"https://adafruit-playground.com/u/ntynen/pages/home-hub-camera\"\u003edriveway camera\u003c/a\u003e.\u003c/p\u003e\n\n\u003cp\u003eIt can be used anywhere you'd like to track and report on motion.\u003c/p\u003e\n\n\u003ch2\u003eDesign\u003c/h2\u003e\n\n\u003cp\u003eDesign\nThe sensor is coded in CircuitPython\u003c/p\u003e\n\n\u003cp\u003eThe current case is the snap fit case provided by team Adafruit. There will be a smaller case for the sensors mounted on doors and windows.\u003c/p\u003e\n\n\u003cp\u003eYou will need an MQTT broker for all of this to work together. You can use Adafruit IO.\u003c/p\u003e\n\n\u003cp\u003eIn my implementation I set up a Mosquitto MQTT broker on a RaspberryPi 4 Model B running Debian Bookworm and Mosquitto v2.022.\u003c/p\u003e\n\n\u003ch2\u003eParts\u003c/h2\u003e\n\n\u003cp\u003eI recently moved from a Raspberry Pi Pico W to a Feather ESP32v2 Huzzah because I will be using a solar to power the project and needed battery storage.\u003c/p\u003e\n","metadata":{"markdown":"## Introduction\nThe motion detector will be deployed alongside the [driveway camera](https://adafruit-playground.com/u/ntynen/pages/home-hub-camera).\n\nIt can be used anywhere you'd like to track and report on motion.\n\n## Design\nDesign\nThe sensor is coded in CircuitPython\n\nThe current case is the snap fit case provided by team Adafruit. There will be a smaller case for the sensors mounted on doors and windows.\n\nYou will need an MQTT broker for all of this to work together. You can use Adafruit IO.\n\nIn my implementation I set up a Mosquitto MQTT broker on a RaspberryPi 4 Model B running Debian Bookworm and Mosquitto v2.022.\n\n## Parts\nI recently moved from a Raspberry Pi Pico W to a Feather ESP32v2 Huzzah because I will be using a solar to power the project and needed battery storage."}},{"element_type":"product","content":"https://www.adafruit.com/product/189","metadata":{"name":"Motion Sensor","url":"https://www.adafruit.com/product/189","description":"PIR (motion sensor","quantity":"1","featured":false}},{"element_type":"product","content":"https://www.adafruit.com/product/5400","metadata":{"name":"Feather Huzzah","url":"https://www.adafruit.com/product/5400","description":"Feather ESP32 v2","quantity":"1","featured":false}},{"element_type":"parts","content":"\n  \u003cdiv class=\"parts-details\"\u003e\n    \u003cdiv\u003e\n      \u003cspan class=\"parts-quantity\"\u003e1\u003c/span\u003e\u003cspan\u003e x \u003c/span\u003e\n        \u003ca href=\"https://www.amazon.com/dp/B01DC0KIT2?ref_=ppx_hzsearch_conn_dt_b_fed_asin_title_3\" class=\"parts-name\" target=\"_blank\"\u003eConnector\u003c/a\u003e\n      \u003cdiv class=\"parts-description\"\u003eJST SM 3 Pin Connectors\u003c/div\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n  \u003cdiv class=\"parts-action\"\u003e\n  \u003cdiv\u003e\n      \u003ca href=\"https://www.amazon.com/dp/B01DC0KIT2?ref_=ppx_hzsearch_conn_dt_b_fed_asin_title_3\" class=\"parts-url btn-primary\" target=\"_blank\"\u003eBuy Now\u003c/a\u003e\n\n  \u003c/div\u003e\n\u003c/div\u003e\n\n  \u003cdiv class=\"clearfix\"\u003e\u003c/div\u003e\n","metadata":{"name":"Connector","url":"https://www.amazon.com/dp/B01DC0KIT2?ref_=ppx_hzsearch_conn_dt_b_fed_asin_title_3","description":"JST SM 3 Pin Connectors","quantity":"1"}},{"element_type":"product","content":"https://www.adafruit.com/product/5584","metadata":{"name":"Headers (optional)","url":"https://www.adafruit.com/product/5584","description":"Short headers for Raspberry Pi","quantity":"1","featured":false}},{"element_type":"markdown","content":"\u003ch2\u003eCode\u003c/h2\u003e\n\n\u003ch4\u003eMotion Detector\u003c/h4\u003e\n\n\u003cp\u003e\u003ca href=\"https://github.com/niccit/disturbance-in-force\"\u003eHome hub\u003c/a\u003e projects are all in this parent project.\u003c/p\u003e\n\n\u003cp\u003eHere you'll find the \u003ca href=\"https://github.com/niccit/disturbance-in-force/blob/main/motion_detect.py\"\u003emotion detector\u003c/a\u003e code.\u003c/p\u003e\n\n\u003ch4\u003eLibraries Required\u003c/h4\u003e\n\u003ccode class=\"\"\u003e\u003cpre\u003eimport os\nimport time\nimport alarm.pin\nimport board\nimport digitalio\nimport wifi\nimport adafruit_minimqtt.adafruit_minimqtt\nfrom adafruit_minimqtt.adafruit_minimqtt import MMQTTException\nimport adafruit_connection_manager\nimport adafruit_logging\nimport analogio\n\u003c/pre\u003e\u003c/code\u003e\n\u003ch4\u003eFeatured Highlights and One Lowlight\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003eLoads all configurations from settings.toml\u003c/li\u003e\n\u003cli\u003eNotifies devices on network when motion is detected\u003c/li\u003e\n\u003cli\u003eSuspends sending motion events when recording is in progress\u003c/li\u003e\n\u003cli\u003eDoes not utilize secure connection for MQTT broker, I have been unable to successfully connect using certificates. Even followed the solution that worked on an ESP32 a last year with no success. Instead uses a special MQTT user that has access restricted by ACL until I can get encryption working.\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch5\u003eThe TL;DR Nuts and Bolts\u003c/h5\u003e\n\n\u003ch4\u003eThe sensor will subscribe to:\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003emonitoring.recording\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch4\u003eThe sensor will publish to:\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003emonitoring.motion-detect\u003c/li\u003e\n\u003cli\u003emotion-detect.battery\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cp\u003eWhen the sensor detects motion it will publish to monitoring.motion-detect which will trigger the camera to start working\u003c/p\u003e\n\n\u003cp\u003eWhen sensor receives a message on monitoring.recording that recording has begun, it will enable recording mode and will not send any motion detection events\u003c/p\u003e\n\n\u003cp\u003eWhen the sensor receives a message on monitoring.recording that recording is complete, it will disable recording mode and will begin sending new motion detection events\u003c/p\u003e\n\n\u003cp\u003eYou will need a local MQTT server or Adafruit IO in order to record and display sensor data.\u003c/p\u003e\n\n\u003ch4\u003eCurrently implemented actions based on motion detection\u003c/h4\u003e\n\n\u003cul\u003e\n\u003cli\u003eDriveway camera: when motion is detected will take a snapshot and record a 30 second clip\u003c/li\u003e\n\u003cli\u003eEntryway or trellis lights: when motion is detected will stop the current running animation and set the lights to solid white\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003ch4\u003eCase\u003c/h4\u003e\n\n\u003cp\u003eI used \u003ca href=\"https://openscad.org\"\u003eOpenSCAD\u003c/a\u003e and the \u003ca href=\"https://github.com/mrWheel/YAPP_Box\"\u003eYAPP Box\u003c/a\u003e (Yet Another Parametric Project Box Generator) library from mrWheel. This library is well documented and has a lot of features.\u003c/p\u003e\n\n\u003ch2\u003eNode-Red\u003c/h2\u003e\n\n\u003cp\u003eNode-Red subscribes to the monitoring.motion-detect feed. When a message is received it will update \nthe UI LED node on the dashboard and on the sensors page.\u003c/p\u003e\n\n\u003ch3\u003eAdafruit IO\u003c/h3\u003e\n\n\u003cp\u003eIn order to monitor the sensor status when I'm out of the house, I have configured Node-Red to send the driveway motion sensor data to Adafruit IO.\u003c/p\u003e\n","metadata":{"markdown":"## Code\n\n#### Motion Detector\n[Home hub](https://github.com/niccit/disturbance-in-force) projects are all in this parent project.\n\nHere you'll find the [motion detector](https://github.com/niccit/disturbance-in-force/blob/main/motion_detect.py) code.\n\n#### Libraries Required\n```\nimport os\nimport time\nimport alarm.pin\nimport board\nimport digitalio\nimport wifi\nimport adafruit_minimqtt.adafruit_minimqtt\nfrom adafruit_minimqtt.adafruit_minimqtt import MMQTTException\nimport adafruit_connection_manager\nimport adafruit_logging\nimport analogio\n```\n#### Featured Highlights and One Lowlight\n* Loads all configurations from settings.toml\n* Notifies devices on network when motion is detected\n* Suspends sending motion events when recording is in progress\n* Does not utilize secure connection for MQTT broker, I have been unable to successfully connect using certificates. Even followed the solution that worked on an ESP32 a last year with no success. Instead uses a special MQTT user that has access restricted by ACL until I can get encryption working.\n\n##### The TL;DR Nuts and Bolts\n\n#### The sensor will subscribe to:\n* monitoring.recording\n\n#### The sensor will publish to:\n* monitoring.motion-detect\n* motion-detect.battery\n\nWhen the sensor detects motion it will publish to monitoring.motion-detect which will trigger the camera to start working\n\nWhen sensor receives a message on monitoring.recording that recording has begun, it will enable recording mode and will not send any motion detection events\n\nWhen the sensor receives a message on monitoring.recording that recording is complete, it will disable recording mode and will begin sending new motion detection events\n\nYou will need a local MQTT server or Adafruit IO in order to record and display sensor data.\n\n#### Currently implemented actions based on motion detection\n* Driveway camera: when motion is detected will take a snapshot and record a 30 second clip\n* Entryway or trellis lights: when motion is detected will stop the current running animation and set the lights to solid white\n\n#### Case\nI used [OpenSCAD](https://openscad.org) and the [YAPP Box](https://github.com/mrWheel/YAPP_Box) (Yet Another Parametric Project Box Generator) library from mrWheel. This library is well documented and has a lot of features.\n\n## Node-Red\n\nNode-Red subscribes to the monitoring.motion-detect feed. When a message is received it will update \nthe UI LED node on the dashboard and on the sensors page.\n\n### Adafruit IO\n\nIn order to monitor the sensor status when I'm out of the house, I have configured Node-Red to send the driveway motion sensor data to Adafruit IO."}},{"element_type":"markdown","content":"\u003ch2\u003eProject Construction\u003c/h2\u003e\n\n\u003ch4\u003eMotion detector\u003c/h4\u003e\n\n\u003cp\u003eI opted to solder \u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/238/large1024/IMG_0277.JPG?1769661050\"\u003eJST SM 3 pin connectors\u003c/a\u003e to the Feather and the sensor so I could remove the lid and unplug the sensor from the Pi if needed.  Plus, I'm not a huge fan of direct soldering bits together so I try to avoid it when I can.\u003c/p\u003e\n\n\u003cp\u003eOn the PIR sensor and the Feather I soldered 3 headers for earth, power, and data and then soldered the connector onto the headers. \u003c/p\u003e\n\n\u003cp\u003eBe aware, if you opt to use the battery, you need to be sure the sensor power is connected to the BAT pin.\u003c/p\u003e\n\n\u003cp\u003e\u003ca href=\"https://cdn-learn.adafruit.com/user_assets/assets/000/002/142/large1024/motion_sensor3.png?1767669822\"\u003eThe sensor\u003c/a\u003e\u003c/p\u003e\n\n\u003ch4\u003eCase\u003c/h4\u003e\n\n\u003cp\u003eThe case is printed using Polymaker PolyLite ASA filament. This is a weather resistent filament which makes it perfect for the camera on the house under an eave.\u003c/p\u003e\n\n\u003cul\u003e\n\u003cli\u003e3D Printing Settings\u003c/li\u003e\n\u003cli\u003eExtruder temperature: 250\u003c/li\u003e\n\u003cli\u003ePlatform temperature: 85\u003c/li\u003e\n\u003cli\u003eBase print speed: 40mm/s\u003c/li\u003e\n\u003cli\u003eInfill: Hexagon 15%\u003c/li\u003e\n\u003cli\u003eSupports: No\u003c/li\u003e\n\u003cli\u003eRaft: No\u003c/li\u003e\n\u003cli\u003eBrim: Yes, fully enabled, no brim generated in holes\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003cp\u003eThe case has 4 self-threading posts to which the Pi is secured using MX 2x4 screws. You can configure the post to be whatever size based on the screws available to you.\u003c/p\u003e\n\n\u003cp\u003eThe case has snap joins, two on each side, one front and one back, for a secure closure. There's one opening for USB power. I've put waterproof silicone around the PIR sensor where it protrudes from the case.\u003c/p\u003e\n\n\u003cp\u003eFor mounting to the garage, there are box mounts on the base, front and back.\u003c/p\u003e\n\n\u003cp\u003eEven though this will be under an eave when mounted, I'm planning on using electrical tape to close any gaps that couldn't be handled by the silicone.\u003c/p\u003e\n\n\u003ch4\u003ePictures\u003c/h4\u003e\n","metadata":{"markdown":"## Project Construction\n\n#### Motion detector\nI opted to solder [JST SM 3 pin connectors](https://cdn-learn.adafruit.com/user_assets/assets/000/002/238/large1024/IMG_0277.JPG?1769661050) to the Feather and the sensor so I could remove the lid and unplug the sensor from the Pi if needed.  Plus, I'm not a huge fan of direct soldering bits together so I try to avoid it when I can.\n\nOn the PIR sensor and the Feather I soldered 3 headers for earth, power, and data and then soldered the connector onto the headers. \n\nBe aware, if you opt to use the battery, you need to be sure the sensor power is connected to the BAT pin.\n\n[The sensor](https://cdn-learn.adafruit.com/user_assets/assets/000/002/142/large1024/motion_sensor3.png?1767669822)\n\n#### Case\nThe case is printed using Polymaker PolyLite ASA filament. This is a weather resistent filament which makes it perfect for the camera on the house under an eave.\n\n* 3D Printing Settings\n* Extruder temperature: 250\n* Platform temperature: 85\n* Base print speed: 40mm/s\n* Infill: Hexagon 15%\n* Supports: No\n* Raft: No\n* Brim: Yes, fully enabled, no brim generated in holes\n\nThe case has 4 self-threading posts to which the Pi is secured using MX 2x4 screws. You can configure the post to be whatever size based on the screws available to you.\n\nThe case has snap joins, two on each side, one front and one back, for a secure closure. There's one opening for USB power. I've put waterproof silicone around the PIR sensor where it protrudes from the case.\n\nFor mounting to the garage, there are box mounts on the base, front and back.\n\nEven though this will be under an eave when mounted, I'm planning on using electrical tape to close any gaps that couldn't be handled by the silicone.\n\n#### Pictures"}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/142/original/motion_sensor3.png?1767669822","metadata":{}},{"element_type":"user_image","content":"https://cdn-learn.adafruit.com/user_assets/assets/000/002/238/original/IMG_0277.JPG?1769661050","metadata":{}},{"element_type":"markdown","content":"\u003cp\u003eThis project is part of the larger \u003ca href=\"https://adafruit-playground.com/u/ntynen/pages/home-hub-project-with-node-red-dashboard\"\u003eHome Hub Project with Node-Red\u003c/a\u003e\u003c/p\u003e\n","metadata":{"markdown":"This project is part of the larger [Home Hub Project with Node-Red](https://adafruit-playground.com/u/ntynen/pages/home-hub-project-with-node-red-dashboard)"}}]