A hardware/software system that ensures each cat eats only from their designated bowl. Uses computer vision to identify cats and triggers a water spray deterrent when the wrong cat eats from the wrong bowl.
Ilana keeps eating Abbi's food. This system watches the food bowls and sprays Ilana with water if she tries to eat from Abbi's bowl before Abbi walks away.
- Camera monitors the feeding area continuously
- When a cat approaches a bowl, the system identifies which cat it is (Abbi or Ilana)
- Tracks which cat is at which bowl
- If Ilana eats from Abbi's bowl while Abbi hasn't finished, activates the water sprayer
- Logs all feeding events for analysis
| Component | Description | Approximate Cost |
|---|---|---|
| Raspberry Pi 4 (2GB or 4GB) | Main controller running the vision system | $45-75 |
| Raspberry Pi Camera Module 3 | Wide-angle camera for monitoring | $25-35 |
| 12V Solenoid Valve (normally closed) | Controls water flow | $10-15 |
| 5V Relay Module | Switches the solenoid valve | $5-8 |
| 12V Power Supply (2A) | Powers the solenoid | $10-15 |
| USB-C Power Supply (5V 3A) | Powers the Raspberry Pi | $10-15 |
| Silicone tubing (1/4" inner diameter) | Connects water source to nozzle | $8-12 |
| Spray nozzle | Creates a fine mist spray | $5-10 |
| Water reservoir (1-2 gallon) | Gravity-fed water source | $10-15 |
| Jumper wires | Connections | $5-8 |
| Project enclosure | Weatherproof box for electronics | $15-20 |
Total estimated cost: $160-230
- Raspberry Pi 4 Model B (4GB) - Any official retailer
- Raspberry Pi Camera Module 3 Wide - For better field of view
- DIGITEN 12V 1/4" Solenoid Valve - Commonly available, food-safe
- HiLetgo 5V Relay Module - Optoisolated for safety
- 12V 2A DC Power Adapter - Standard barrel jack
- Misting Nozzle Kit - Garden misting nozzles work well
- IR illuminator - For nighttime operation
- NoIR Camera Module - Better low-light performance
- Pressure tank - For more consistent spray pressure
- Flow sensor - To monitor water usage
| Component | Best Price | Amazon Alternative |
|---|---|---|
| Raspberry Pi 4 (4GB) | $60 - Adafruit | CanaKit Starter Kit - Amazon |
| Pi Camera Module 3 Wide | $35 - Adafruit | Camera Module 3 Wide - Amazon |
| 12V Solenoid Valve (1/4" NC) | - | DIGITEN 12V Solenoid - Amazon |
| 5V Relay Module (Opto-isolated) | - | HiLetgo 5V Relay - Amazon |
| 12V 2A Power Supply | - | 12V 2A Adapter - Amazon |
| USB-C Power Supply (5V 3A) | - | Raspberry Pi 4 Power Supply - Amazon |
| Silicone Tubing (1/4" ID) | - | Food Grade Silicone Tubing 10ft - Amazon |
| Misting Nozzle Kit | - | Brass Misting Nozzles - Amazon |
| Jumper Wires | - | 120pcs Jumper Wire Kit - Amazon |
| Waterproof Enclosure | $9.95 - Adafruit | Sixfab IP65 Enclosure - Amazon |
Adafruit (often cheaper):
- Raspberry Pi 4 4GB - $60
- Camera Module 3 Wide - $35
- Camera Module 3 Wide NoIR (for low light) - $35
- Weatherproof Enclosure with Cable Glands
Amazon (all-in-one shopping):
- Raspberry Pi 4 4GB Board
- Pi Camera Module 3 Wide
- DIGITEN 12V 1/4" Solenoid Valve
- HiLetgo 5V Relay Module (2-pack)
- 12V 2A DC Power Adapter (UL Certified)
- USB-C 5V 3A Power Supply with Switch
- Pure Silicone Tubing 1/4" x 10ft
- Brass Misting Nozzle Kit
- Jumper Wires Kit (120pcs M/F/M-M/F-F)
- Sixfab IP65 Outdoor Enclosure
+12V Power Supply
|
v
[Raspberry Pi 4] [12V Solenoid Valve]
| ^
| GPIO 17 |
v |
[5V Relay Module] -----> Switches --------+
|
| VCC -> Pi 5V
| GND -> Pi GND
| IN -> Pi GPIO 17
[Pi Camera] -----> CSI Port on Raspberry Pi
Water Flow:
[Reservoir] --> [Tubing] --> [Solenoid Valve] --> [Tubing] --> [Spray Nozzle]
|
v
[Aimed at Abbi's bowl]
Web Interface: http://192.168.86.36:5000
Start the service:
ssh alerer@192.168.86.36
cd ~/discipline && source venv/bin/activate && nohup python3 -m discipline.main --no-spray > /tmp/discipline.log 2>&1 &Check logs:
ssh alerer@192.168.86.36 "tail -f /tmp/discipline.log"Stop the service:
ssh alerer@192.168.86.36 "pkill -f 'python3 -m discipline.main'"# Flash Raspberry Pi OS (64-bit) to SD card using Raspberry Pi Imager
# Enable SSH and set up WiFi during imaging
# After first boot, update the system
sudo apt update && sudo apt upgrade -y
# Enable the camera
sudo raspi-config
# Navigate to: Interface Options -> Camera -> Enable
# Install required system packages
sudo apt install -y python3-pip python3-venv libcamera-apps python3-libcamera python3-picamera2# Clone the repository
git clone https://github.com/adamlerer/discipline.git
cd discipline
# Create virtual environment (--system-site-packages required for picamera2)
python3 -m venv --system-site-packages venv
source venv/bin/activate
# Install Python dependencies
pip install -r requirements.txt
# Download the cat detection model (YOLOv8)
python scripts/download_model.pyBefore the system can identify Abbi and Ilana, you need to train it with photos of each cat.
# Capture training images for each cat
python scripts/capture_training_images.py --cat abbi --count 50
python scripts/capture_training_images.py --cat ilana --count 50
# Train the cat classifier
python scripts/train_classifier.pyEdit config.yaml to set up your specific environment:
# Bowl positions (in pixel coordinates from camera view)
bowls:
abbi:
x: 200
y: 300
radius: 80
ilana:
x: 500
y: 300
radius: 80
# Spray settings
spray:
duration_ms: 500 # How long to spray
cooldown_s: 10 # Minimum time between sprays
# Camera settings
camera:
resolution: [1280, 720]
framerate: 30# Run the calibration tool to set bowl positions
python scripts/calibrate_bowls.py# Start the discipline system
python -m discipline.main
# Or run as a service (recommended for production)
sudo cp discipline.service /etc/systemd/system/
sudo systemctl enable discipline
sudo systemctl start disciplineIn addition to the water spray, you can enable a sound deterrent.
# Install audio support
pip install pygame
# Add a sound file (MP3 or WAV)
cp /path/to/your/sound.mp3 sounds/deterrent.mp3Enable in config.yaml:
sound:
file: "sounds/deterrent.mp3"
volume: 0.7
duration_ms: 2000
cooldown_s: 5
enabled: trueEnable a web dashboard for live video streaming and remote control.
# Install web dependencies
pip install flaskEnable in config.yaml:
web:
enabled: true
host: "0.0.0.0"
port: 5000Then access the dashboard at http://<pi-ip>:5000. Features include:
- Live video stream with cat identification overlays
- Toggle spray/sound deterrents on/off
- Test buttons for spray and sound
- Real-time system status and event log
discipline/
├── README.md
├── requirements.txt
├── config.yaml
├── discipline/
│ ├── __init__.py
│ ├── main.py # Main entry point
│ ├── camera.py # Camera capture and processing
│ ├── cat_detector.py # YOLO-based cat detection
│ ├── cat_identifier.py # Identifies Abbi vs Ilana
│ ├── bowl_monitor.py # Tracks cats at bowls
│ ├── sprayer.py # Controls water sprayer
│ ├── sound_player.py # Sound deterrent playback
│ ├── logger.py # Event logging
│ └── web/
│ ├── __init__.py
│ ├── app.py # Flask web application
│ ├── templates/
│ │ └── dashboard.html
│ └── static/
│ └── style.css
├── scripts/
│ ├── download_model.py
│ ├── capture_training_images.py
│ ├── train_classifier.py
│ └── calibrate_bowls.py
├── models/ # Trained models stored here
├── sounds/ # Sound files for deterrent
├── data/
│ └── training/ # Training images
└── logs/ # Event logs
- Water and Electronics: Keep all electronics in a waterproof enclosure away from the spray zone
- Electrical Safety: Use proper gauge wires and ensure all connections are secure
- Cat Safety: The spray should be a gentle mist, not a powerful jet. Test pressure before deployment
- Supervision: Monitor the system during initial deployment to ensure correct operation
# Check camera connection
rpicam-hello --list-cameras# Test GPIO manually
python -c "import RPi.GPIO as GPIO; GPIO.setmode(GPIO.BCM); GPIO.setup(17, GPIO.OUT); GPIO.output(17, True)"- Ensure good lighting in the feeding area
- Capture more training images from various angles
- Check that cats are visually distinct (color, pattern, size)
MIT License - Feel free to use and modify for your own cat discipline needs!