Saturday, 30 May 2026

AI Smart Refrigerator Monitoring and Food Expiry Detection

AI Smart Refrigerator Monitoring & Food Expiry Detection System ESP32 + Agentic AI + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard
AI Smart Refrigerator Monitoring & Food Expiry Detection System ESP32 + Agentic AI + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Cloud Dashboard 1. Project Overview This project creates an intelligent refrigerator monitoring system that: ✅ Monitors refrigerator temperature and humidity ✅ Detects food expiry dates ✅ Predicts future power consumption using AI logic ✅ Stores data in Google Sheets ✅ Visualizes data in ThingSpeak Dashboard ✅ Sends Telegram alerts ✅ Generates Voice Notifications through Telegram ✅ Uses n8n automation as the workflow engine ✅ Uses ESP32 as the IoT edge device ✅ Can be extended into a fully Agentic AI Refrigerator Assistant 2. System Architecture +----------------+ | Refrigerator | +-------+--------+ | v +----------------+ | ESP32 | | DHT22 Sensor | | RFID/Manual | | Entry System | +-------+--------+ | WiFi MQTT/HTTP | v +----------------+ | ThingSpeak | | Cloud Dashboard| +-------+--------+ | v +----------------+ | n8n Workflow | +-------+--------+ | +----------------+ | | v v +--------------+ +--------------+ | Telegram Bot | | Google Sheet | +--------------+ +--------------+ | v +----------------+ | Voice Alerts | +----------------+ | v +----------------+ | AI Prediction | +----------------+ 3. Features Monitoring Refrigerator Temperature Humidity Door Open Duration Power Consumption Food Management Food Name Added Date Expiry Date Days Remaining Alerts High Temperature Food Expiry Power Consumption Anomaly Door Left Open Cloud Features Historical Data Dashboard Analytics AI Prediction 4. Hardware Components List Component Quantity ESP32 Dev Board 1 DHT22 Temperature Humidity Sensor 1 Reed Switch Door Sensor 1 RFID RC522 (optional) 1 RFID Tags 5 OLED Display 0.96" 1 Buzzer 1 Relay Module 1 ACS712 Current Sensor 1 Jumper Wires Several Breadboard 1 5V Adapter 1 5. Pin Connections DHT22 DHT22 ESP32 VCC 3.3V GND GND DATA GPIO4 Reed Switch Reed Switch ESP32 One Side GPIO15 Other Side GND Buzzer Buzzer ESP32 + GPIO18 - GND ACS712 Current Sensor ACS712 ESP32 OUT GPIO34 VCC 5V GND GND 6. Working Principle Step 1 ESP32 reads: Temperature Humidity Door Status Current Consumption every 30 seconds. Step 2 ESP32 sends data to: ThingSpeak n8n Webhook using HTTP requests. Step 3 n8n processes incoming data. Checks: Temperature > Threshold? Door Open Too Long? Power Consumption High? Food Expiry Near? Step 4 If abnormal: Telegram Message Telegram Voice Alert Google Sheets Entry generated automatically. 7. Flowchart START | v Initialize ESP32 | Connect WiFi | Read Sensors | Send to ThingSpeak | Send to n8n | Check Rules | +----No----+ | | | Continue | Yes | Send Telegram Alert | Generate Voice Alert | Store in Google Sheet | Repeat 8. ESP32 Source Code #include #include #include "DHT.h" #define DHTPIN 4 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); const char* ssid = "YOUR_WIFI"; const char* password = "YOUR_PASSWORD"; String webhookURL = "https://your-n8n-domain/webhook/fridge"; String thingSpeakAPI = "YOUR_THINGSPEAK_WRITE_KEY"; void setup() { Serial.begin(115200); WiFi.begin(ssid,password); while(WiFi.status()!=WL_CONNECTED) { delay(1000); } dht.begin(); } void loop() { float temp = dht.readTemperature(); float hum = dht.readHumidity(); if(WiFi.status()==WL_CONNECTED) { HTTPClient http; String url = "https://api.thingspeak.com/update?api_key=" + thingSpeakAPI + "&field1=" + String(temp) + "&field2=" + String(hum); http.begin(url); http.GET(); http.end(); HTTPClient webhook; webhook.begin(webhookURL); webhook.addHeader( "Content-Type", "application/json"); String payload = "{\"temp\":" + String(temp) + ",\"humidity\":" + String(hum) + "}"; webhook.POST(payload); webhook.end(); } delay(30000); } 9. ThingSpeak Setup Create Account Create ThingSpeak account. Create new channel. Fields: Field1 Temperature Field2 Humidity Field3 Door Status Field4 Power Copy Write API Key Channels → API Keys → Write API Key Paste into ESP32 code. 10. Google Sheets Setup Create Sheet: Date Time Temperature Humidity Power Door Food Item Expiry Date Status Example: Date Temp Food Expiry 12-05-2026 4°C Milk 15-05-2026 11. Telegram Bot Setup Step 1 Open Telegram Search: BotFather Create Bot: / newbot Get: BOT TOKEN Step 2 Get Chat ID Open: https://api.telegram.org/botTOKEN/getUpdates Save Chat ID. 12. n8n Workflow Design Node 1 Webhook POST /fridge Node 2 IF Node Condition: {{$json.temp > 8}} Node 3 Telegram Node Message: ⚠ Refrigerator Temperature High Current: {{$json.temp}} °C Node 4 Google Sheets Node Append Row Date Time Temperature Humidity Node 5 Text-To-Speech Node Input: Warning. Refrigerator temperature is high. Please check immediately. Generate MP3. Node 6 Telegram Send Voice Attach generated MP3. 13. n8n Workflow JSON Structure { "nodes":[ { "name":"Webhook" }, { "name":"IF" }, { "name":"Telegram" }, { "name":"Google Sheets" } ] } Import and customize. 14. Food Expiry Detection Logic Google Sheet Example: Food Expiry Date Milk 15-May Eggs 20-May Yogurt 18-May n8n Daily Scheduler: Every Day 8AM Formula: daysRemaining = expiryDate - currentDate Conditions <=3 days Send Alert. Telegram: Milk expires in 2 days. 15. AI Food Expiry Prediction Advanced model considers: Temperature variation Humidity Storage duration Food category Door opening frequency Prediction: Expected Remaining Shelf Life Example: Milk Original: 7 days Predicted: 5 days because of frequent temperature spikes. 16. AI Power Consumption Prediction Input Features Temperature Compressor Runtime Door Open Count Humidity Historical Power Usage Model Linear Regression y = a + bx Where y = predicted power x = usage factors or Random Forest More accurate Training Dataset Date Power Temperature Door Count Prediction Output Tomorrow Expected Usage: 1.8 kWh 17. Voice Notification Automation Workflow: ESP32 ↓ n8n ↓ OpenAI/TTS Engine ↓ Generate Voice ↓ Telegram Voice Message Example Voice: Attention. Milk will expire in 2 days. Please consume it soon. 18. AI Agent Features The AI Agent can answer: What food expires today? How much power did fridge consume? Why is temperature rising? Suggest grocery items. Agent accesses: ThingSpeak Google Sheets Historical Records through APIs. 19. Future Enhancements Computer Vision ESP32-CAM Detect: Milk Eggs Fruits Vegetables using object detection. QR Code Inventory Each food item has QR code. Scan when inserted. Automatic inventory update. Voice Assistant Voice Commands: What expires today? How much milk is left? Mobile App Flutter App Features: Dashboard Notifications Analytics Inventory 20. Deployment Guide Local Testing Connect sensors. Upload ESP32 code. Verify serial monitor. Test ThingSpeak updates. Test n8n webhook. Cloud Deployment Deploy n8n on: Raspberry Pi Docker VPS Cloud VM Recommended: 2 CPU 4GB RAM Security Use: HTTPS Webhook Authentication Encrypted Tokens Firewall Rules 21. Expected Outputs Dashboard Temperature: 4.2°C Humidity: 68% Power: 1.5 kWh Door: Closed Telegram Alert ⚠ Warning Milk expires tomorrow. Voice Alert Attention. Milk expires tomorrow. AI Prediction Power tomorrow: 1.8 kWh Confidence: 92% 22. Project Outcome This system combines: ESP32 Edge Computing IoT Sensor Monitoring Agentic AI Decision Making n8n Workflow Automation Telegram Messaging & Voice Alerts Google Sheets Data Logging ThingSpeak Analytics Food Expiry Intelligence Predictive Maintenance The result is a complete Industry 4.0 smart refrigerator solution suitable for academic projects, final-year engineering projects, smart-home deployments, and IoT/AI portfolio demonstrations.

No comments:

Post a Comment

AI Smart Road Pothole Detection and Mapping System

AI Smart Road Pothole Detection and Mapping System AI-Powered ESP32 + Agentic IoT + n8n Automation + Telegram Voice Alerts + Google Sheets +...