Introduction
The motion detector will be deployed alongside the driveway camera.
It can be used anywhere you'd like to track and report on motion.
Design
Design The sensor is coded in CircuitPython
The 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.
You will need an MQTT broker for all of this to work together. You can use Adafruit IO.
In my implementation I set up a Mosquitto MQTT broker on a RaspberryPi 4 Model B running Debian Bookworm and Mosquitto v2.022.
Parts
I 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.
Code
Motion Detector
Home hub projects are all in this parent project.
Here you'll find the motion detector code.
Libraries Required
import os
import time
import alarm.pin
import board
import digitalio
import wifi
import adafruit_minimqtt.adafruit_minimqtt
from adafruit_minimqtt.adafruit_minimqtt import MMQTTException
import adafruit_connection_manager
import adafruit_logging
import analogio
Featured Highlights and One Lowlight
- Loads all configurations from settings.toml
- Notifies devices on network when motion is detected
- Suspends sending motion events when recording is in progress
- 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.
The TL;DR Nuts and Bolts
The sensor will subscribe to:
- monitoring.recording
The sensor will publish to:
- monitoring.motion-detect
- motion-detect.battery
When the sensor detects motion it will publish to monitoring.motion-detect which will trigger the camera to start working
When sensor receives a message on monitoring.recording that recording has begun, it will enable recording mode and will not send any motion detection events
When 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
You will need a local MQTT server or Adafruit IO in order to record and display sensor data.
Currently implemented actions based on motion detection
- Driveway camera: when motion is detected will take a snapshot and record a 30 second clip
- Entryway or trellis lights: when motion is detected will stop the current running animation and set the lights to solid white
Case
I used OpenSCAD and the YAPP Box (Yet Another Parametric Project Box Generator) library from mrWheel. This library is well documented and has a lot of features.
Node-Red
Node-Red subscribes to the monitoring.motion-detect feed. When a message is received it will update the UI LED node on the dashboard and on the sensors page.
Adafruit IO
In 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.
Project Construction
Motion detector
I opted to solder JST SM 3 pin connectors 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.
On the PIR sensor and the Feather I soldered 3 headers for earth, power, and data and then soldered the connector onto the headers.
Be aware, if you opt to use the battery, you need to be sure the sensor power is connected to the BAT pin.
Case
The 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.
- 3D Printing Settings
- Extruder temperature: 250
- Platform temperature: 85
- Base print speed: 40mm/s
- Infill: Hexagon 15%
- Supports: No
- Raft: No
- Brim: Yes, fully enabled, no brim generated in holes
The 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.
The 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.
For mounting to the garage, there are box mounts on the base, front and back.
Even 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.
Pictures
This project is part of the larger Home Hub Project with Node-Red
This page (Home Hub - Motion Detector) was last updated on March 15, 2026.