Build a Battery-Powered Raspberry Pi Wildlife Trail Camera with PIR Trigger
Commercial trail cameras are cheap, but they're also closed boxes — proprietary apps, SD cards you have to physically retrieve, and no way to get an instant notification when something walks by at 3am. A Raspberry Pi Zero 2 W with a PIR sensor and a camera module makes a trail camera you fully control: battery runtime measured in weeks instead of days thanks to deep power-down between triggers, photos or short clips pushed straight to your phone or a local server, and a 3D-printed weatherproof enclosure sized exactly for the electronics inside it. This project covers the PIR wiring, the power budget that makes multi-week battery life possible, and the software side — a lightweight Python trigger script rather than a full always-on video pipeline.
Why Pi Zero 2 W and Not a Pi 4/5
Trail camera power budget is dominated by idle current, and the Pi Zero 2 W idles at a fraction of what a Pi 4 or 5 draws — critical when the goal is weeks of battery life from a modest power bank rather than hours. Its quad-core A53 is still plenty for capturing a still image or a short H.264 clip on a PIR trigger; you're not doing real-time object detection or streaming here, so the extra horsepower of a larger Pi buys you nothing but shorter runtime.
Wiring the PIR Sensor
A standard HC-SR501 PIR module is the simplest option — it has its own onboard signal conditioning and gives a clean digital HIGH when motion is detected, so no analog reading or debouncing logic is needed on the Pi side.
HC-SR501 PinPi Zero 2 W Pin VCC5V (Pin 2) GNDGND (Pin 6) OUTGPIO17 (Pin 11)Two onboard potentiometers on the HC-SR501 adjust sensitivity (detection range, up to ~7m) and hold time (how long OUT stays HIGH after a trigger, 3s-300s) — set hold time low (a few seconds) since your script will handle its own cooldown logic rather than relying on the sensor to debounce repeated triggers from the same animal.
The Power Budget: What Actually Gets You Weeks of Runtime
The trick to multi-week battery life isn't a bigger battery, it's spending almost all your time in the lowest power state possible and waking only on a real trigger. Running the Pi fully awake and polling the PIR pin in a loop draws several hundred milliamps continuously — a 10,000mAh power bank would last well under two days that way.
- Use the PIR's OUT signal to physically interrupt Pi power rather than software polling, using a small latching relay or a MOSFET power-switch circuit gated by the PIR trigger — this is the single biggest power saver, since the Pi draws essentially zero current while fully powered off between triggers rather than idling at 100-200mA.
- A simpler middle ground if you don't want to build a power-switching circuit: run the Pi normally but call sudo halt at the end of the trigger script after a fixed timeout, and use a cron-free wake source — this only helps if you also cut power externally afterward, since a halted Pi with power still applied draws nearly as much as an idle one.
- Boot time is the tax you pay for full power-down — a Pi Zero 2 W takes roughly 15-20 seconds to boot to a working camera capture, which means fast-moving animals may pass before the camera is ready. This is the real trade-off between battery life and capture reliability; a fast SD card (A2-rated) and a minimal OS image (Raspberry Pi OS Lite, no desktop) meaningfully cuts boot time.
Capture Script
Using picamera2 (the current library for Raspberry Pi OS Bookworm and later):
from picamera2 import Picamera2 import time, datetime, os picam2 = Picamera2() config = picam2.create_still_configuration() picam2.configure(config) picam2.start() time.sleep(2) # let AE/AWB settle timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S") filename = f"/home/pi/captures/trail_{timestamp}.jpg" os.makedirs("/home/pi/captures", exist_ok=True) picam2.capture_file(filename) picam2.stop() print(f"Captured {filename}")Trigger this from a systemd service that starts on boot, checks the PIR pin once, captures if HIGH, then calls sudo shutdown now — pairing this boot-capture-shutdown cycle with the external power-switching circuit above is what gets you real multi-week runtime instead of multi-day.
Getting the Photo Off the Camera
Without WiFi coverage in the field, the simplest reliable option is just saving to the SD card and swapping it on a visit — but if you're within WiFi range of your home network, a periodic sync when the Pi wakes is straightforward:
# Add to the capture script before shutdown, if WiFi is available import subprocess subprocess.run(["rsync", "-avz", "/home/pi/captures/", "user@home-server:/mnt/trailcam/"], timeout=30)Wrap the rsync in a WiFi-availability check first (e.g. pinging the gateway with a short timeout) so the Pi doesn't sit waiting for a connection that isn't there and drain the battery — fail fast and shut down if the network isn't reachable within a few seconds.
Weatherproof Enclosure
Design the enclosure around the actual PCB footprints (Pi Zero 2 W, PIR module, and battery) with a clear or IR-transparent window over the camera lens, a mesh-covered vent for the PIR sensor's dome (PIR sensors need a line of sight through the housing — sealing them behind solid plastic blocks detection), and a gasketed seam or printed-in O-ring channel at the split line. Print in ASA or PETG rather than PLA for UV and weather resistance if it'll live outside for more than a season — see our guide on printing ASA without an enclosure and our enclosure design guide for IP-rating considerations and cable entry glands if you're running an external antenna or solar panel lead into the box.
Safety and Practical Notes
- Check local regulations before deploying anywhere it might capture identifiable people on adjacent property — trail cameras on your own land pointed at wildlife are generally fine, but the legal picture changes fast near property lines or public trails.
- A small silica gel packet inside the enclosure meaningfully reduces lens fogging from daily temperature swings even with a well-sealed case.
- LiFePO4 packs (see our solar power and battery chemistry guide) tolerate outdoor temperature swings and slow discharge far better than standard Li-ion for a device that will sit outside unattended for weeks.
The result is a trail camera that costs more up front than a commercial unit but gives you full control over what happens to every capture — instant sync to your own server instead of a card you have to walk out and retrieve, and a battery life that, once the power-switching circuit is dialed in, genuinely rivals dedicated wildlife cameras.
Related Guides
- Build a Battery-Powered ESP32 Smart Mailbox Notifier
- Raspberry Pi AI Camera Module (IMX500): On-Sensor Machine Learning Without an Accelerator HAT
- Build a Standalone ESP32 WiFi Security Testing Tool with Marauder
- Build a Raspberry Pi E-Ink Digital Photo Frame (Wired or Battery-Powered)
- Build a Raspberry Pi NAS with Samba File Sharing
- Build a Cyberdeck: Custom Portable Computer with a Laser-Cut and 3D Printed Enclosure
- Build a PiKVM: Remote Out-of-Band BIOS/Boot-Level Access with a Raspberry Pi
- Build a Raspberry Pi Whole-Home Audio Streamer: Volumio, DAC HAT, and Multi-Room Sync