My mom loves her cat, Zelie, even if she’s a fearless little hunter. Birds, mice, the occasional surprise catch… all proudly delivered right through the catflap and into the house.
The problem? My mom is terrified of mice. 😱
Since you work with AI, can’t you make something to stop her from bringing me presents?
Usually, she calls me about her printer or her phone, but this time I couldn’t resist the challenge.
After a bit of hardware tinkering, a dash of AI, and a few late-night experiments, it actually works! 🎉
The system uses a small camera to detect whether Zelie is carrying prey, automatically locks the door and sends alerts.
Now my mom is happy (and mouse-free), I got to play with edge AI on a fun side project, and Zelie is mildly offended by the new security measures.
Full details here https://github.com/fl2o/catflap-prey-detector Happy building!
Disclaimer: This project requires an AI model to detect the prey. In order to get your own model, you will need to collect data from your cat and fine tune the yolo model. To get started on it I provide a global model under a paid API that works like a charm.
1. The Solution: How It WorksThe system runs on a Raspberry Pi 5 with a night-vision camera monitoring your cat flap 24/7. Here's the detection flow:
1. Frame Capture — The Picamera 3 IR Wide continuously captures frames
2. Object Detection — YOLO11n (optimized with NCNN) detects cats approaching the catflap
3. Prey Analysis — Cropped cat images are sent to the Prey Detection API for analysis
4. Decision — If prey is detected, the RFID jammer activates, blocking the catflap
5. Notification — You receive a Telegram alert with the image
6. Auto-unlock — The catflap automatically unlocks after 5 minutes
The RFID jammer works by emitting a 134.2 kHz signal that interferes with your catflap's RFID reader. Your cat's microchip can't be read, so the flap stays locked.
📖 More details:Architecture Overview
2. Hardware Assembly: Wiring the RFID Jammer
The RFID jammer is what physically stops your catflap from unlocking when prey is detected. It’s just a relay‑controlled RFID reader that we turn on and off from the Pi.
Wiring
1. Relay to Pi:
- - Relay VCC → Pi 5V (Pin 2 or 4)
- - Relay GND → Pi Ground (Pin 6)
- - Relay IN → Pi GPIO 26 (Pin 37)
2. RFID Module:
- - Pi 5V → Relay COM terminal
- - Relay NO (Normally Open) → RFID module VCC
- - Pi GND → RFID module GND
- - Solder antenna coil to L1 and L2 pins
3. Position the antenna coil directly next to your catflap's RFID reader (usually in the tunnel). When the relay activates, the RFID module emits a 134.2 kHz carrier wave that prevents the catflap from reading your cat's microchip.
Quick Test
Once wired, use this small script to test the relay (you should hear a click):
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.OUT)
# Activate relay (should hear click)
GPIO.output(26, GPIO.LOW) # Active-low relay
time.sleep(2)
# Deactivate relay
GPIO.output(26, GPIO.HIGH)
GPIO.cleanup()📖 More details:Hardware Setup Guide
3. Hardware Assembly: Mounting the CameraThe Picamera 3 IR Wide provides the eyes of the system with infrared capability for 24/7 operation.
Camera Setup
1. Connect the camera to the Pi using the ribbon cable (use an extension cable for flexible mounting)
2. Mount the camera above or beside your catflap, angled to capture cats entering
3. Position an 850nm IR illuminator nearby for night vision
Live Preview for Positioning
To perfect the installation, use the built-in live stream server to perfect your camera angle:
uv run python -m catflap_prey_detector.detection.fastapi_mjpeg_server
Open http://<raspberry-pi-ip>:8000 in your browser to see a real-time feed. Adjust until the catflap entrance is clearly visible.
📖 More details:Hardware Setup Guide
4. Software Setup: Installation & ConfigurationThis project mixes hardware and quite a lot of software. I highly recommend checking the GitHub page for reading and understanding the code. Here are some components.
Installationon the Raspberry Pi
git clone https://github.com/fl2o/catflap-prey-detector.git
cd catflap-prey-detector
make install
Telegram Bot
The project interacts with telegram both to alert you in case of detections and to provide some controls on the cat flap over / commands.
1. Message @BotFather on Telegram
2. Send /newbot and follow the prompts
3. Copy your bot token to BOT_TOKEN
4. Start a chat with your bot, then use /where to get your chat ID
Prey detection API
The system automatically:
1. Detect cats using Yolo model on the Pi.
2. Crops detected cats from frames.
3. Resizes to 384x384 pixels.
4. Filters duplicates using SSIM (>90% similarity = skipped).
5. Sends up to 10 concurrent requests to the prey detection API for fast analysis.
The Prey Detection API is a custom AI service trained to detect prey in cat images. It works with any cat breed, any environment, and even infrared images. You can replace this piece of code with your own.
API Specifications
- Latency: ~1 second per request
- Rate limit: 1000 calls per day
- Image size: 384x384 pixels max
- Formats: RGB or grayscale (IR compatible)
Purchase an API key with stripe. After purchase, add it to your environment.
📖 More details:Full open source codebaseDeployment toolsPrey Detection API Documentation
5. What's Next- Train your own model — After running the system for a while, you will have collected enough data to train your own prey detection model and run it on the Pi! A guide for training custom prey detection models using collected data is in the future, check out the Github repository for updates.
- Custom APIs — The system is flexible. Want to detect something else? Different objects, behaviors, or conditions can be monitored with custom APIs. Do not hesitate to build your own detectors or to reach out for help.
Full Project Repository github.com/fl2o/catflap-prey-detector












Comments