1. Project Overview & Problem Statement
Everything you need to pitch, build, and demonstrate this real-world IoT + Machine Learning project for college evaluations.
The Real-World Problem
During perishable food, dairy, and vaccine transport, minor refrigeration failures or trapped volatile organic compounds (VOCs) silently accelerate spoilage. Conventional cold-chain loggers only trigger alarms after fixed temperature thresholds are breached—often too late to save the shipment.
How Edge AI Solves It
A BME680 environmental sensor continuously tracks temperature, humidity, and VOC gas resistance inside the storage container. A lightweight neural network trained in Edge Impulse runs directly on the ESP32-S3, detecting subtle early-spoilage patterns offline and triggering local OLED/buzzer alerts plus instant MQTT cloud notifications.
2. Interactive Real Wiring Diagram
Use the circuit filter buttons below to inspect power rails, the shared I2C bus, or alert outputs step-by-step.
3. Pin-to-Pin Connection Table & Bill of Materials
Follow this exact pin mapping when assembling your breadboard prototype.
| Component | Component Pin | ESP32-S3 Pin | Wire Color | Circuit Function |
|---|---|---|---|---|
| BME680 Sensor | VCC / GND | 3V3 / GND | Red / Black | 3.3V regulated power supply |
| BME680 Sensor | SDA / SCL | GPIO 8 / GPIO 9 | Blue / Orange | Shared I2C bus (Addr 0x76 or 0x77) |
| 0.96" OLED (SSD1306) | VCC / GND | 3V3 / GND | Red / Black | 3.3V regulated power supply |
| 0.96" OLED (SSD1306) | SDA / SCL | GPIO 8 / GPIO 9 | Blue / Orange | Shared I2C bus (Addr 0x3C) |
| Active Buzzer | + (Pos) / − (Neg) | GPIO 4 / GND | Purple / Black | Audible alarm on spoilage detection |
| Green LED + 220Ω | Anode (+) / Cathode (−) | GPIO 5 / GND | Green / Black | Visual indicator for FRESH state |
| Red LED + 220Ω | Anode (+) / Cathode (−) | GPIO 6 / GND | Coral / Black | Visual warning for SPOILING alert |
Bill of Materials (BOM)
| Item | Recommended Part / Spec | Qty | Est. Cost (INR / USD) |
|---|---|---|---|
| Microcontroller | ESP32-S3-DevKitC-1 (or Seeed XIAO ESP32S3) | 1 | ₹550 – ₹800 ($7–$10) |
| Gas & Climate Sensor | BME680 I2C Breakout (Temp + Humidity + VOC) | 1 | ₹400 – ₹600 ($5–$7) |
| Display | 0.96" I2C OLED Display (SSD1306, 128×64) | 1 | ₹180 – ₹250 ($2–$3) |
| Alert Components | Active Buzzer + Green/Red 5mm LEDs + 220Ω Resistors | 1 set | ₹50 – ₹80 ($1) |
| Prototyping | 830-Point Breadboard + Jumper Wires + USB-C Cable | 1 set | ₹120 – ₹180 ($1.50) |
4. Step-by-Step Build & Edge Impulse TinyML Workflow
Follow these four stages to go from a bare breadboard to a working Edge-AI device.
Hardware Assembly & I2C Scan
Wire the BME680 and OLED onto the shared I2C pins (GPIO 8 & 9). Upload the starter code below and open the Serial Monitor at 115200 baud to confirm both I2C devices respond cleanly.
Collect a 3-Class Dataset
Place the sensor inside a sealed box with fruit (e.g., banana or tomato). Log CSV rows of Temp, Humidity, Gas_kOhm over 2–3 days and label them into three files: Fresh, Early_Ripening, and Spoiling.
Train in Edge Impulse
Upload your CSV files to a free Edge Impulse project. Add a Raw Data processing block and a Classification (Keras) neural network block. Train until accuracy exceeds 90% on your validation split.
Deploy & Add MQTT Alerts
Export the trained model as an Arduino Library (.zip) and include it in your sketch. When inference predicts Spoiling (>80%), trigger GPIO 4/6 locally and publish a JSON alert to HiveMQ or Blynk over Wi-Fi.
5. Interactive Edge-AI Spoilage Simulator
Adjust the virtual BME680 sensor readings below to see how multi-sensor fusion classifies freshness on the OLED, LEDs, and buzzer before you buy hardware.
T: 4.5C | RH: 58% | VOC: 165kΩ
ON (GPIO 5)
OFF (GPIO 6)
SILENT
6. Copy-Ready Arduino Starter Code (ESP32-S3)
Install Adafruit BME680 and Adafruit SSD1306 from the Arduino Library Manager, select ESP32S3 Dev Module, and upload this sketch to log Edge Impulse CSV data and test your hardware.
// =========================================================================
// Edge-AI Cold-Chain Spoilage Predictor — Starter & Data Logger Sketch
// Board: ESP32-S3-DevKitC-1 | I2C: SDA=GPIO 8, SCL=GPIO 9
// Outputs: Buzzer=GPIO 4, Green LED=GPIO 5, Red LED=GPIO 6
// =========================================================================
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
// Pin Definitions matching the IoTInfo Wiring Diagram
#define I2C_SDA_PIN 8
#define I2C_SCL_PIN 9
#define BUZZER_PIN 4
#define GREEN_LED_PIN 5
#define RED_LED_PIN 6
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_BME680 bme;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
void setup() {
Serial.begin(115200);
delay(500);
// Configure Alert Pins
pinMode(BUZZER_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
// Start I2C on ESP32-S3 custom pins (GPIO 8 = SDA, GPIO 9 = SCL)
Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
// Initialize 0.96" SSD1306 OLED (Address 0x3C)
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("ERROR: SSD1306 OLED not found at 0x3C");
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 10);
display.println("Cold-Chain AI Boot...");
display.display();
// Initialize BME680 Sensor (tries 0x76 then 0x77)
if (!bme.begin(0x76) && !bme.begin(0x77)) {
Serial.println("ERROR: BME680 sensor not found! Check wiring.");
while (1) delay(1000);
}
// Configure BME680 oversampling and VOC gas heater
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320C for 150 ms
// CSV Header for Edge Impulse Data Forwarder
Serial.println("temp_c,humidity_pct,pressure_hpa,gas_kohm");
}
void loop() {
if (!bme.performReading()) {
Serial.println("Failed to read BME680");
delay(2000);
return;
}
float tempC = bme.temperature;
float humidity = bme.humidity;
float pressure = bme.pressure / 100.0;
float gasKOhm = bme.gas_resistance / 1000.0;
// 1. Print CSV row to Serial Monitor (record this for Edge Impulse training)
Serial.print(tempC, 2); Serial.print(",");
Serial.print(humidity, 2); Serial.print(",");
Serial.print(pressure, 2); Serial.print(",");
Serial.println(gasKOhm, 2);
// 2. Baseline Heuristic (Replace with Edge Impulse run_classifier() after training)
String statusText = "FRESH";
if (gasKOhm < 40.0 || (tempC > 18.0 && gasKOhm < 65.0)) {
statusText = "SPOILING!";
digitalWrite(GREEN_LED_PIN, LOW);
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
} else if (gasKOhm < 95.0 || tempC > 12.0) {
statusText = "RIPENING";
digitalWrite(GREEN_LED_PIN, LOW);
digitalWrite(RED_LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, LOW);
} else {
statusText = "FRESH";
digitalWrite(GREEN_LED_PIN, HIGH);
digitalWrite(RED_LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}
// 3. Update Live 0.96" OLED Display
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("COLD-CHAIN EDGE AI");
display.drawLine(0, 11, 128, 11, SSD1306_WHITE);
display.setTextSize(2);
display.setCursor(0, 18);
display.println(statusText);
display.setTextSize(1);
display.setCursor(0, 42);
display.printf("T:%.1fC RH:%.0f%%", tempC, humidity);
display.setCursor(0, 54);
display.printf("VOC Gas: %.1f kOhm", gasKOhm);
display.display();
delay(2000); // Sample every 2 seconds
}
7. College Viva & Presentation Q&A
Click each question to prepare confident, clear answers for project reviews and external examiners.
if-else rules trigger false alarms when a door opens briefly or miss early chemical spoilage when temperature is still cool. A TinyML model learns the combined multi-sensor signature and runs locally on the ESP32-S3's AI vector instructions without needing continuous cloud connectivity.
0x3C, while the BME680 listens at 0x76 (or 0x77).