Automatically track what's inside your fridge using a Raspberry Pi 5, an ultrasonic sensor, and a custom AI camera model based on YOLOv8. Tired of discovering you’re out of eggs or milk only when you open the fridge at night? This project continuously monitors and updates you in real time—so you always know what's in stock.
Check out the demo video in the repository (or linked below) to see the system in action:
Demo Video
Demo.mp4
- Goal: Detect when the fridge door opens/closes (via ultrasonic sensor), trigger an AI camera to recognize key products (milk, cheese, eggs, etc.), and broadcast a real-time inventory update to a React dashboard.
- Motivation:
- I was fed up with coming home after a busy day only to realize I was missing essential groceries.
- This system ensures I always know what needs restocking, even when I’m still at the store.
- Raspberry Pi 5 as the central processing unit.
- YOLOv8n-based AI Camera (exported to an IMX500-compatible model).
- Ultrasonic Sensor to detect door distance (activates camera when < 50cm).
- Flask & SocketIO for real-time communication.
- React Dashboard that displays “IN” (available) and “OUT” (missing) items.
- Raspberry Pi 5 (with Python 3 installed).
- AI Camera Module (compatible with YOLOv8/IMX500 exports).
- Ultrasonic Sensor (HC-SR04 or similar).
- (Optional) PIR Motion Sensor (HC-SR501 or similar).
- Jumper Wires + Breadboard (for wiring sensors).
- Internet Connection (for Flask server & SocketIO to broadcast data).
See the docs/
or assets/
folder for a Fritzing diagram illustrating the setup.
-
Clone this Repository
git clone https://github.com/your-username/fridge-inventory-pi5.git cd fridge-inventory-pi5
-
Install Dependencies
- Make sure you have Python 3.x on your Raspberry Pi.
- Install Python packages (Flask, SocketIO, etc.):
pip install -r requirements.txt
-
Model & Camera Setup
- Place your YOLOv8n (IMX500 exported) model in the
models/
folder. - Update the path in
detect_products.py
to point to your model file. - Roboflow Dataset: https://app.roboflow.com/wow-7vmpw/ai-fridge-fssaf/1
- Place your YOLOv8n (IMX500 exported) model in the
-
Configure Sensor Pins
- Check and update the GPIO pins in
ultrasonic_sensor.py
(andpir_sensor.py
if using PIR). - Refer to your Raspberry Pi pin layout to ensure accurate connections.
- Check and update the GPIO pins in
-
Open a terminal on your Raspberry Pi (or any machine running Flask):
cd fridge-inventory-pi5/server python app.py
This will start a SocketIO-enabled Flask server on
http://0.0.0.0:5000
. -
(Optional) Expose it to the internet using a service like ngrok:
ngrok http 5000
Copy the generated forwarding URL for use in your React app.
- On the Raspberry Pi, run the sensor loop script (ultrasonic or PIR-based). For example:
This script reads from the ultrasonic sensor, triggers camera captures, and sends data to the Flask server.
python sensor_loop.py
- Navigate to the
dashboard
folder:cd fridge-inventory-pi5/dashboard
- Install dependencies and start the React app:
npm install npm start
- Update the SocketIO URL in
src/App.js
(or wherever you initialize the socket) to eitherhttp://<RPI-IP>:5000
or the ngrok URL.
RPI5-FRIDGE-INVENTORY/
├── best_imx_model_fridge/
│ ├── best_imx_MemoryReport.json
│ ├── best_imx.onnx
│ ├── best_imx.pbtxt
│ ├── dnnParams.xml
│ ├── labels.txt
│ ├── network.rpk
│ └── packerOut.zip
│
├── server/
│ ├── fridge_server.ipynb
│ └── imx500_object_detection_fridge.py
│
└── README.md
best_imx_model_fridge/
– Contains the exported IMX model files (ONNX, PBTXT, labels, etc.) for your YOLOv8 to IMX500 conversion.server/
– Holds the main server logic.fridge_server.ipynb
– A Jupyter notebook (possibly for testing or demonstration).imx500_object_detection_fridge.py
– The Python script handling object detection with the IMX500 model.
README.md
– Documentation for your project.
- Sensor Calibration:
Experiment with the distance threshold (e.g., 50cm) insensor_loop.py
to get reliable door detection. - Camera Angle:
Properly position the camera so it has a clear view of the fridge’s interior. - Performance:
If inference is slow, consider using a more optimized version of YOLO or upgrading your Raspberry Pi’s resources. - Logging:
Addprint
statements or use Python’slogging
module to debug any real-time issues with sensors or model inference.
- Exporting YOLO to IMX500: YouTube Tutorial by LukeDitria
- Roboflow Dataset: AI Fridge Dataset
- Full Blog Post: https://itaimiz.com/blog/rpi5-fridge
Enjoy a smarter fridge and never run out of essentials again!