
Ever wondered who’s really visiting your garden at night? Foxes? Owls? That suspiciously chubby squirrel? With a Raspberry Pi and a bit of computer vision, you can build an AI Wildlife Camera Trap that quietly watches your yard, snaps photos when something moves, identifies the species, and emails you the results.
It’s perfect for birdwatchers, amateur conservationists, and curious makers who want a window into the hidden life happening just outside their door.
What You’ll Need
Here’s your gear list:
- Raspberry Pi 4 (4GB or 8GB) — handles AI inference comfortably
- Raspberry Pi Camera Module 3 (or the NoIR version for night vision)
- PIR motion sensor (HC-SR501) to trigger captures efficiently
- IR LED illuminator for nighttime shots
- MicroSD card (32GB+) with Raspberry Pi OS (64-bit)
- Weatherproof enclosure (IP65-rated) with a clear lens window
- Power source — a power bank, 12V battery, or small solar panel kit for remote setups
- Mounting strap or bracket for trees or posts
- Wi-Fi connection (or a 4G USB dongle for truly wild locations)
- (Optional) Google Coral USB Accelerator for faster species detection
Step 1: Prepare the Raspberry Pi
Flash Raspberry Pi OS (64-bit) with Raspberry Pi Imager, boot up, connect to Wi-Fi, and update:
sudo apt update && sudo apt full-upgrade -y
sudo apt install python3-pip python3-opencv -y
pip3 install tflite-runtime numpy pillow
Enable the camera via sudo raspi-config → Interface Options → Camera, then reboot.
Test your camera:
libcamera-still -o test.jpg
Step 2: Wire Up the PIR Motion Sensor
The PIR sensor saves huge amounts of power and storage by only waking the camera when something moves.
- VCC → 5V
- GND → GND
- OUT → GPIO 4
Adjust the sensitivity and delay potentiometers on the sensor to fit your environment — a bit of trial and error pays off.
Step 3: Choose an AI Species Classifier
You have a few great options:
- iNaturalist / Google’s Bird & Insect models — available as TensorFlow Lite models capable of recognizing thousands of species
- MobileNet trained on iNat2021 — lightweight and Pi-friendly
- Custom model — train your own with Roboflow or Teachable Machine using photos of local wildlife
Drop the .tflite file and labels.txt into ~/wildlife-cam/.
Step 4: Write the Capture & Classify Script
Create wildlife_cam.py that waits for motion, snaps a photo, runs classification, and emails the result:
import RPi.GPIO as GPIO, time, subprocess
import tflite_runtime.interpreter as tflite
import numpy as np
from PIL import Image
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN)
interpreter = tflite.Interpreter(model_path="wildlife.tflite")
interpreter.allocate_tensors()
labels = open("labels.txt").read().splitlines()
def classify(path):
img = Image.open(path).resize((224, 224))
data = np.expand_dims(np.array(img, dtype=np.float32)/255.0, axis=0)
interpreter.set_tensor(interpreter.get_input_details()[0]['index'], data)
interpreter.invoke()
out = interpreter.get_tensor(interpreter.get_output_details()[0]['index'])[0]
return labels[np.argmax(out)], float(max(out))
while True:
if GPIO.input(4):
filename = f"/home/pi/wildlife-cam/{int(time.time())}.jpg"
subprocess.run(["libcamera-still", "-o", filename, "-n", "-t", "500"])
species, conf = classify(filename)
print(f"Detected: {species} ({conf:.0%})")
time.sleep(5) # cooldown
time.sleep(0.2)
Step 5: Email Photos Automatically
Add a function to send the photo straight to your inbox using Gmail’s SMTP server (with an app password):
import smtplib, ssl
from email.message import EmailMessage
def send_email(path, species, conf):
msg = EmailMessage()
msg["Subject"] = f"🦉 Wildlife detected: {species}"
msg["From"] = "[email protected]"
msg["To"] = "[email protected]"
msg.set_content(f"Species: {species}\nConfidence: {conf:.0%}")
with open(path, "rb") as f:
msg.add_attachment(f.read(), maintype="image", subtype="jpeg",
filename="capture.jpg")
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=ssl.create_default_context()) as s:
s.login("[email protected]", "APP_PASSWORD")
s.send_message(msg)
Call send_email() right after classification — but consider only sending when confidence is above, say, 60%, to avoid spammy false positives.
Step 6: Weatherproof and Mount It
Place everything inside your IP65 enclosure, making sure:
- The camera lens lines up with a clear waterproof window
- The PIR sensor has a clean line of sight
- Cable glands seal any openings
- The enclosure is angled slightly downward so rain runs off
Mount it on a tree, fence post, or garden pole around 1–1.5m high, pointed at a feeder, water dish, or well-used animal path.
Step 7: Power It for the Long Haul
For short deployments, a 20,000mAh USB power bank will keep the Pi running for a day or two. For permanent setups, a small solar panel + charge controller + 12V battery combo is the gold standard.
To stretch battery life further, underclock the Pi and have the script sleep between checks.
Tips for Better Wildlife Shots
- Pre-focus the camera on the area where animals are likely to appear
- Use IR illumination for nocturnal visitors without scaring them
- Bait the spot with seeds, suet, or a water dish
- Avoid pointing at busy branches — wind triggers endless false captures
- Check your local laws before recording in shared or public spaces
Wrapping Up
You’ve just built a silent, solar-friendly, AI-powered nature documentarian. Expand it by logging sightings to a database, building a public “garden wildlife gallery” website, or contributing your data to citizen science projects like iNaturalist.
Nature’s always happening — now you’ll finally see it. 🦊🦉🐿️
Loved this project? Follow @raspitips on Instagram for more Raspberry Pi builds, tips, and tutorials.


