Icons and featured elements can add visual appeal and context to your blog posts. For a 'Jewish Holidays' blog/landing page, we want to create unique and eye-catching pixelated React nodes that capture the essence and importance of the jewish holidays for us.
Incorporating custom visuals can make your app stand out and provide a more immersive experience for your readers. In this tutorial, we'll guide you through the process of creating pixelated React nodes and use it for icons, games and hero components step by step.
Hey there! 👋 I'm Itai Mizlish , a passionate fullstack web developer with a knack for crafting captivating digital experiences using the magical world of JS frameworks and magical UI libraries. 🚀 When I'm not immersed in lines of code, you'll find me exploring the diverse landscapes of Israel, contributing to open source projects, and getting lost in the time-traveling adventures of Doctor Who! 🌌🌟 You can read more about me
2023 Itai Mizlish
RPI5-Fridge Inventory Management with AI Product Recognition 🍽️🤖
Published on
In this post, we detail our journey of building a smart fridge inventory management system powered by the Raspberry Pi 5 and an AI camera. Using an ultrasonic sensor mounted on the fridge side, our system determines when to start product detection and when to send updates. With our custom-trained YOLOv8n model (exported via Roboflow to IMX500 format), the camera recognizes key products—cheese, coke, eggs, ketchup, milk, pittas, and schnitzels—and categorizes them based on their location in the frame. The resulting "IN" and "OUT" lists are transmitted in real time through a Flask server with SocketIO to a React dashboard, helping you know what’s stocked and what needs restocking.
"An organized fridge is the first step to a healthier lifestyle."
— Anonymous
Introduction 🧊
Imagine opening your fridge and having an AI system instantly tell you what’s available and what’s missing. Our project automates fridge inventory tracking by using sensor triggers. When the ultrasonic sensor detects the fridge door is within 50cm, the AI camera kicks in to analyze product placement. Alternatively, with a PIR motion sensor, the camera starts detecting as soon as motion is sensed and sends updates after 5 seconds of inactivity. This seamless integration of embedded AI and full-stack development makes inventory management effortless.
Watch the Demo:
Observe the system in action as it updates your fridge inventory in real time.
Hardware Setup 🛠️
Our configuration leverages a mix of sensors and cutting-edge AI:
Raspberry Pi 5 – The processing hub.
AI Camera Module – Equipped with our custom YOLOv8n model (exported to IMX500) to detect products like cheese, coke, eggs, ketchup, milk, pittas, and schnitzels.
Ultrasonic Sensor – Mounted on the fridge side to measure the distance to the door. When the distance is less than 50cm, the system activates product detection.
PIR Motion Sensor (Alternative) – Triggers detection when motion is sensed and sends an update after 5 seconds of no motion.
Flask Server with SocketIO – Handles real-time communication.
React Dashboard – Displays two lists: items currently IN the fridge and those that are OUT (for restocking).
Wiring & Diagram:
Below is our Fritzing diagram illustrating the sensor and camera connections:
Ultrasonic Sensor Setup:
Place the sensor on the fridge side, facing the door.
The sensor continuously monitors the distance. If the door is close (50cm), the system starts capturing frames for analysis. When the door moves away (>50cm), it triggers the update transmission.
PIR Motion Sensor Setup (Optional):
Mount the sensor to detect movement near the fridge.
On motion detection, the camera begins product recognition. If no motion is detected for 5 seconds, an inventory update is sent.
At the core of our system is an AI camera using a custom-trained YOLOv8n network. This model, optimized and exported to an IMX500-compatible format via Roboflow, recognizes our key products and differentiates between items on the "IN" half (inside the fridge) and the "OUT" half (being removed or absent).
Product Recognition Logic Code Snippet
Sensor Integration & SocketIO Communication 📡
Ultrasonic Sensor Logic
The ultrasonic sensor measures the distance between the sensor and the fridge door. When the door is within 50cm, the system begins capturing frames for product detection. Once the door moves away (distance exceeds 50cm), the accumulated "IN" and "OUT" lists are sent to the server.
PIR Motion Sensor (Alternative) Logic
For environments using a PIR sensor, the camera activates on motion detection and sends an inventory update if no motion is sensed for 5 seconds.
Flask Server with SocketIO
Our Flask server receives these real-time inventory updates and broadcasts them to all connected clients, ensuring that the React dashboard displays the latest data.
Full-Stack Integration (Flask + React) 💻📱
The real-time data pipeline flows from the Raspberry Pi through our Flask server (exposed via ngrok) to the React dashboard. The dashboard displays two lists: products IN the fridge and those OUT (for restocking).
React Dashboard Code Snippet
Deployment & Troubleshooting ⚙️
Deploying an edge AI solution like this comes with its challenges:
Sensor Calibration:
Fine-tune the ultrasonic sensor’s threshold (50cm) and ensure proper placement of the PIR sensor (if used).
Network Stability:
Running the Flask server via ngrok demands a reliable internet connection. Monitor connection quality and latency.
Model Optimization:
Leverage lightweight frameworks and ensure your custom model for product recognition is optimized for real-time inference.
Logging & Monitoring:
Implement robust logging in your sensor loops and server to quickly diagnose any issues.
Conclusion 🌟
This project unites embedded systems, deep learning, and full-stack development to create a smart fridge inventory management solution. With the Raspberry Pi 5, an AI camera using a custom YOLOv8n model, and sensor-triggered detection, you can automatically track what’s in your fridge and what needs restocking—all in real time.
Ready to automate your kitchen? Fork our repository, set up your Raspberry Pi, and start managing your fridge inventory like never before. Happy hacking and enjoy a smarter, more organized kitchen!
For questions or feedback, feel free to reach out or open an issue on our GitHub repository.
Hey there! 👋 I'm Itai Mizlish, a passionate fullstack web developer with a knack for crafting captivating digital experiences using the magical world of JS frameworks and magical UI libraries. 🚀 When I'm not immersed in lines of code, you'll find me exploring the diverse landscapes of Israel, contributing to open source projects, and getting lost in the time-traveling adventures of Doctor Who! 🌌🌟 You can read more about me here
Table of Contents
loading...
import cv2
import numpy as np
# Load the custom product detection model (YOLOv8n exported to IMX500)
model = load_model('path_to_imx500_model')
def detect_products(frame):
# Preprocess the frame for the model
processed_frame = preprocess_frame(frame)
# Run inference
detections = model(processed_frame)
# Parse detections and categorize into 'in' and 'out'
in_products = []
out_products = []
for det in detections:
label = det['label']
x, y, w, h = det['bbox']
# Assume the frame is split vertically: left half is "IN", right half is "OUT"
if x + w / 2 < frame.shape[1] // 2:
in_products.append(label)
else:
out_products.append(label)
return in_products, out_products
# Helper functions: preprocess_frame() and load_model() are implemented elsewhere.
import time
import socketio
# Initialize SocketIO client
sio = socketio.Client()
sio.connect('http://your-ngrok-url')
THRESHOLD = 50 # Distance threshold in cm
def read_ultrasonic_sensor():
# Simulated sensor reading; replace with actual sensor logic.
return get_distance()
def sensor_loop():
detecting = False
in_list = []
out_list = []
while True:
distance = read_ultrasonic_sensor()
if distance < THRESHOLD and not detecting:
print("Fridge door detected! Starting inventory check...")
detecting = True
# Capture frame for product detection (simulate camera capture)
frame = capture_frame() # Replace with actual camera capture logic
in_list, out_list = detect_products(frame)
elif distance >= THRESHOLD and detecting:
print("Fridge door closed. Sending inventory data to server.")