← Projects
raspberry-pi intermediate Aug 7, 2026 ◑ 9 views ◯ 5 min read

Build a Battery-Powered Raspberry Pi Wildlife Trail Camera with PIR Trigger

Build time: 6-10 hours
Tools needed: Soldering iron, 3D printer for enclosure, multimeter, small Phillips screwdriver, hot glue gun for gasket seating
Parts List
raspberry pipi zero 2wtrail camerawildlife camerapir sensorpicamera2battery powereddeep sleepoutdoordiy

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.

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

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.