An open-source, automated cat litterbox powered by Raspberry PI and TensorFlow Lite. Uses computer vision to detect when your cat uses the litterbox, waits an appropriate time after they leave, then automatically cycles a self-cleaning mechanism.
- Real-time cat detection using TensorFlow Lite and EfficientDet Lite0
- Smart timing — waits 7 minutes after cat leaves before cleaning
- Email notifications with photos at each state change
- Auto-start on boot — runs headlessly without intervention
- DC motor control via Adafruit Motor HAT
OpenLitterPI uses a state machine to manage the cleaning cycle:
IDLE → DETECTED → USING → WAITING → CYCLING → COMPLETE
- IDLE: Monitoring for cat presence
- DETECTED: Cat detected (< 15 frames)
- USING: Cat confirmed using litterbox (15+ frames)
- WAITING: Cat left, waiting 7 minutes before cleaning
- CYCLING: Motor rotating to sift and clean
- COMPLETE: Cycle finished, returns to IDLE
| Component | Specification |
|---|---|
| Raspberry PI | Raspberry PI 4 Model B (2GB+ RAM recommended) |
| Motor HAT | Adafruit DC & Stepper Motor HAT (PCA9685) |
| Camera | USB webcam (640×480 minimum) |
| Motor | DC gearmotor for drum rotation |
| Power | Adequate power supply for PI + motor |
- Motor connected to Motor 3 (M3) port on the Adafruit HAT
- Camera connected via USB
- Motor HAT communicates via I2C (address
0x60)
- Raspbian GNU/Linux 11 (Bullseye) or later
- Python 3.9+
- I2C enabled on Raspberry PI
cd ~/projects
git clone https://github.com/yourusername/openlitterpi.git
cd openlitterpipython3 -m venv openlitterpi-env
source openlitterpi-env/bin/activatepip install --upgrade pip
pip install -r requirements.txtsudo raspi-config
# Navigate to: Interface Options → I2C → EnableCopy the example environment file and edit with your credentials:
cp .env.example .env
nano .envSet these environment variables:
OPENLITTERPI_EMAIL_FROM=your-email@gmail.com
OPENLITTERPI_EMAIL_PASSWORD=your-app-password
OPENLITTERPI_EMAIL_TO=recipient@example.com
Then source the file before running:
source .envNote: Use a Gmail App Password, not your regular password. Generate one at Google Account → Security → App Passwords.
Place launch.sh in your home directory and add to crontab:
cp launch.sh ~/launch.sh
chmod +x ~/launch.sh
crontab -eAdd this line:
@reboot sleep 120; ~/launch.sh > ~/launch.log 2>&1
cd ~/projects/openlitterpi
source openlitterpi-env/bin/activate
python3 detect.pypython3 detect.py --display True# Rotate forward for 5 seconds
python3 move.py -v 1.0 -d 5.0
# Rotate backward for 5 seconds
python3 move.py -v -1.0 -d 5.0
# Run full cleaning cycle
python3 move.py -t cyclepython3 cycle.py| Parameter | Default | Description |
|---|---|---|
occupied_frames_threshold |
15 | Frames to confirm cat presence |
use_threshold |
45 sec | Time after cat leaves before WAITING |
wait_threshold |
7 min | Time to wait before cycling |
reset_threshold |
8 min | Timeout to reset to IDLE |
| Parameter | Default | Description |
|---|---|---|
rotate1 |
54 sec | Forward rotation (sift) |
rotate2 |
62 sec | Reverse rotation (dump) |
rotate3 |
7.28 sec | Return to home position |
speed |
1.0 | Motor speed (0.0 - 1.0) |
openlitterpi/
├── detect.py # Main detection & state machine
├── utils.py # Motor control, email, visualization
├── move.py # Manual motor control CLI
├── cycle.py # Standalone cycle test
├── launch.sh # Auto-start script
├── models/
│ ├── efficientdet_lite0.tflite # Standard TFLite model
│ └── efficientdet_lite0_edgetpu.tflite # EdgeTPU model (optional)
└── photos/ # State transition snapshots (auto-generated)
# List video devices
v4l2-ctl --list-devices
# Check if camera is recognized
lsusb | grep -i cam# Check if I2C is enabled
sudo i2cdetect -y 1
# Should show device at address 0x60- Verify motor is connected to M3 port
- Check power supply is adequate
- Test with
python3 cycle.py
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
See LICENSE for the full license text.
Contributions welcome! Please open an issue or submit a pull request.
- TensorFlow Lite for the object detection framework
- Adafruit for the excellent Motor HAT and CircuitPython libraries
- The Raspberry PI Foundation