- System Overview
- Components Architecture
- API Specifications
- Model Integration Guide
- UI/UX Implementation
- Real-Time Sensor Integration
- Data Flow
- Installation & Setup
- Testing Checklist
- Troubleshooting
EcoGuard is a smart waste management system that combines:
- Image Recognition - Identifies waste items from photos
- Weight Estimation - Calculates weight from object size
- Carbon Calculation - Computes CO₂ emissions
- Real-Time Monitoring - Tracks air quality with MQ7 sensor
- Lifestyle Tracking - Monitors user's carbon footprint
User Takes Photo → App Analyzes → Shows Results + Air Quality → User Takes Action
↓
App Logs Action & Updates Score
- Capture image from camera
- Send image to backend Vision API
- Display detection results
- Connect to MQ7 sensor for real-time data
- Show historical data and recommendations
- Track user achievements
File: vision_model/best.pt
Size: 6.2 MB
Input: Image (JPG, PNG, any size)
Output: JSON with detections
Expected Output:
{
"detections": [
{
"class_id": 4,
"class_name": "plastic",
"confidence": 0.92,
"bbox": {
"x1": 100,
"y1": 150,
"x2": 250,
"y2": 400
}
}
],
"image_shape": [720, 1280, 3],
"processing_time_ms": 6.6
}Classes Detected:
- 0: cardboard
- 1: glass
- 2: metal
- 3: paper
- 4: plastic
- 5: trash
File: weight_model/weight_estimator.pkl
Config: weight_model/weight_estimator_config.json
Input: Bounding box + class name + image shape
Output: Weight in grams
Expected Output:
{
"weight_g": 83.5,
"weight_kg": 0.0835,
"material": "plastic",
"size_category": "medium (25-50% of image)",
"confidence": "high",
"explanation": "Base plastic = 25g. Size is medium. Adjusted weight: 83.5g"
}Base Weights (grams):
{
"plastic": 25,
"glass": 250,
"metal": 50,
"paper": 15,
"cardboard": 40,
"trash": 30
}Type: Python class (built-in, no separate file)
Input: Weight + material type
Output: CO₂ emissions
Expected Output:
{
"material": "plastic",
"weight_kg": 0.0835,
"carbon_kg": 0.2088,
"carbon_g": 208.8,
"emission_factor": 2.5,
"recycling_reduction_percent": 70.0,
"if_recycled_co2_kg": 0.0626,
"co2_saved_kg": 0.1462
}Emission Factors (kg CO₂ per kg material):
{
"plastic": 2.5,
"glass": 1.8,
"metal": 8.0,
"paper": 1.0,
"cardboard": 0.9,
"trash": 1.5
}File: lifestyle_model/best_ml_model.joblib
Input: 20 lifestyle features
Output: User's carbon footprint prediction
Required Features (20):
- Daily energy consumption (kWh)
- Transportation mode (car/bus/bike)
- Distance traveled (km)
- Food type (meat/vegetarian)
- Food waste percentage
- Water consumption (liters)
- Clothing purchases per month
- Shopping frequency
- Recycling rate (%)
- Waste per day (kg)
- Number of people in household
- House size (sqft)
- Heating type (gas/electric)
- AC usage hours/day
- Number of flights/year
- Streaming hours/day
- Game playing hours/day
- Phone charging cycles/day
- Internet data usage (GB)
- Overall eco-consciousness (1-10 scale)
Expected Output:
{
"monthly_carbon_kg": 450.5,
"yearly_carbon_kg": 5406,
"daily_average_kg": 15.02,
"compared_to_average_percent": -15,
"country_average_kg": 630,
"recommendation": "Your carbon footprint is 15% below average. Keep it up!"
}Hardware: MQ7 Gas Sensor + ESP8266/ESP32
Connection: WiFi/Bluetooth
Update Rate: Every 1 second
Range: 0-1000 ppm CO
Expected Data Stream:
{
"timestamp": "2026-03-27T10:30:45Z",
"co_ppm": 45,
"status": "GOOD",
"trend": "IMPROVING",
"trend_percent": -10,
"last_24h_avg": 52,
"peak_today": 78,
"low_today": 32
}Status Mapping:
- CO 0-50 ppm: GREEN (GOOD)
- CO 50-100 ppm: YELLOW (FAIR)
- CO 100-500 ppm: ORANGE (POOR)
- CO 500+ ppm: RED (DANGEROUS - Alert!)
POST /api/vision/detect
Content-Type: multipart/form-data
Body: image file
Response: 200 OK
{
"detections": [...],
"image_shape": [...],
"processing_time_ms": 6.6
}
POST /api/weight/estimate
Content-Type: application/json
Body:
{
"bbox": [100, 150, 250, 400],
"class_name": "plastic",
"image_shape": [720, 1280, 3]
}
Response: 200 OK
{
"weight_g": 83.5,
"weight_kg": 0.0835,
"material": "plastic",
"size_category": "medium (25-50% of image)",
"confidence": "high",
"explanation": "..."
}
POST /api/carbon/calculate
Content-Type: application/json
Body:
{
"weight_kg": 0.0835,
"material": "plastic"
}
Response: 200 OK
{
"carbon_kg": 0.2088,
"carbon_g": 208.8,
"if_recycled_co2_kg": 0.0626,
"co2_saved_kg": 0.1462
}
POST /api/lifestyle/predict
Content-Type: application/json
Body:
{
"features": [45.2, 1, 25.5, 2, 15, 150, 2, 3, 85, 1.5, 4, 2500, 1, 6, 3, 4, 2, 5, 50, 8]
}
Response: 200 OK
{
"monthly_carbon_kg": 450.5,
"yearly_carbon_kg": 5406,
"compared_to_average_percent": -15
}
WebSocket: ws://backend.local/api/sensor/stream
Connection established, receive:
{
"timestamp": "2026-03-27T10:30:45Z",
"co_ppm": 45,
"status": "GOOD",
"trend": "IMPROVING"
}
(Updates every 1 second)
The backend should be running Python Flask/FastAPI with these requirements:
- Python 3.8+
- ultralytics (YOLOv8)
- opencv-python
- scikit-learn
- numpy, pandas
- joblib, pickle
Backend folder should contain:
backend/
├── vision_model/
│ └── best.pt (6.2 MB)
├── weight_model/
│ ├── weight_estimator.pkl
│ └── weight_estimator_config.json
├── lifestyle_model/
│ └── best_ml_model.joblib
├── app.py (Flask/FastAPI server)
└── requirements.txt
Implementation:
// Capture image from camera
const captureImage = async () => {
const input = document.getElementById('cameraInput');
const file = input.files[0];
// Send to backend vision API
const formData = new FormData();
formData.append('image', file);
try {
const response = await fetch('/api/vision/detect', {
method: 'POST',
body: formData
});
const data = await response.json();
handleDetections(data.detections);
} catch (error) {
console.error('Vision API error:', error);
}
};Implementation:
// For each detected object, estimate weight
const handleDetections = async (detections) => {
const results = [];
for (const detection of detections) {
// Get weight estimate
const weightResponse = await fetch('/api/weight/estimate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
bbox: detection.bbox,
class_name: detection.class_name,
image_shape: [720, 1280, 3] // replace with actual
})
});
const weight = await weightResponse.json();
// Get carbon impact
const carbonResponse = await fetch('/api/carbon/calculate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
weight_kg: weight.weight_kg,
material: weight.material
})
});
const carbon = await carbonResponse.json();
results.push({
...detection,
...weight,
...carbon
});
}
displayResults(results);
};UI Layout:
┌─────────────────────────────────┐
│ ITEM DETECTED │
├─────────────────────────────────┤
│ [Image of item] │
│ │
│ Material: Plastic │
│ Confidence: 92% │
│ Weight: 83.5 grams │
│ CO₂ Cost: 0.21 kg │
│ │
│ If Recycled: │
│ CO₂ Reduced to: 0.06 kg (70%) │
│ You Save: 0.15 kg CO₂ │
│ │
│ Current Air Quality: 45 ppm ✓ │
│ Status: GOOD │
│ │
│ [RECYCLE] [TRASH] [MORE INFO] │
└─────────────────────────────────┘
┌─────────────────────────────────┐
│ EcoGuard - Scan Waste │
├─────────────────────────────────┤
│ │
│ [CAMERA VIEW] │
│ [Tap to capture] │
│ │
│ [UPLOAD PHOTO] │
│ │
│ [RECENT SCANS] │
│ • Plastic bottle │
│ • Glass jar │
│ • Paper box │
│ │
└─────────────────────────────────┘
┌─────────────────────────────────┐
│ Analysis Results │
├─────────────────────────────────┤
│ [Item Image] │
│ │
│ PLASTIC BOTTLE │
│ Confidence: 92% │
│ │
│ Weight: 83.5g │
│ CO₂ Impact: 0.21 kg │
│ If Recycled: -70% (0.06 kg) │
│ │
│ Current Air Quality: │
│ [45 ppm] GOOD ✓ │
│ Status: Safe to breathe │
│ │
│ [RECYCLE] [TRASH] [SAVE] │
│ [VIEW DETAILS] │
└─────────────────────────────────┘
┌─────────────────────────────────┐
│ Air Quality Monitor │
├─────────────────────────────────┤
│ │
│ Live Reading: │
│ 45 ppm │
│ [Green Indicator] GOOD │
│ │
│ Status: Safe to breathe │
│ Trend: Improving ↓ (-5 ppm) │
│ │
│ 24-Hour History: │
│ [Graph showing CO levels] │
│ Peak: 78 ppm (10:30 AM) │
│ Low: 32 ppm (3:45 PM) │
│ Average: 50 ppm │
│ │
│ Weekly Comparison: │
│ This week: ↓ 10% better │
│ vs City avg: ✓ 15% better │
│ │
│ [Settings] [Share] [History] │
└─────────────────────────────────┘
┌─────────────────────────────────┐
│ Weekly Report │
├─────────────────────────────────┤
│ │
│ Your Score: 45/100 │
│ Trend: ↑ UP 5 points │
│ │
│ Items Scanned: 47 │
│ Total CO₂: 9.8 kg │
│ Savings (recycling): 30% │
│ │
│ Air Quality: Improved 40% │
│ ■■■■■□□□□□ [Good] │
│ │
│ Badges Earned: │
│ [Recycler] [Eco Hero] │
│ │
│ Recommendations: │
│ 1. Keep recycling items │
│ 2. Use public transport │
│ 3. Buy less packaged food │
│ │
│ [Details] [Share] [Next Week] │
└─────────────────────────────────┘
- Hardware: MQ7 Gas Sensor + ESP8266/ESP32 microcontroller
- Connection: WiFi or Bluetooth to app
- Data Updates: Every 1 second
- Battery: 48+ hours
JavaScript Implementation:
// Connect to sensor stream
const connectToSensor = () => {
const socket = new WebSocket('ws://backend.local/api/sensor/stream');
socket.onmessage = (event) => {
const sensorData = JSON.parse(event.data);
updateAirQualityDisplay(sensorData);
};
socket.onerror = (error) => {
console.error('Sensor connection error:', error);
};
};
const updateAirQualityDisplay = (data) => {
// Update in real-time every second
const ppmElement = document.getElementById('co-ppm');
const statusElement = document.getElementById('status');
const trendElement = document.getElementById('trend');
ppmElement.textContent = data.co_ppm + ' ppm';
statusElement.textContent = data.status;
trendElement.textContent = (data.trend_percent > 0 ? '↑' : '↓') + ' ' + Math.abs(data.trend_percent) + '%';
// Update color based on status
const statusColor = {
'GOOD': 'green',
'FAIR': 'yellow',
'POOR': 'orange',
'DANGEROUS': 'red'
};
statusElement.style.color = statusColor[data.status];
};- Update air quality indicator every second
- Show trend (improving/worsening)
- Display 24-hour history as graph
- Alert user if dangerous levels detected (500+ ppm)
1. User captures photo
2. Frontend sends image to backend
3. Vision model detects objects (6.6ms)
4. For each detection:
- Send bbox to weight estimator
- Weight estimator returns weight (<1ms)
- Send weight to carbon calculator
- Carbon calculator returns CO₂ (instant)
5. Fetch current sensor data from MQ7
6. Display combined results to user
7. User chooses action (recycle/trash/save)
8. Log action to database
9. Update user score
10. Check if badge earned
1. Every scan logged with timestamp
2. Daily aggregation:
- Total items scanned
- Total CO₂ calculated
- Total weight
3. Weekly calculations:
- Score out of 100
- Comparison to previous week
- Comparison to average user
- Air quality improvements
4. Monthly report:
- Total carbon footprint
- Trees equivalent
- Impact visualization
5. Recommendations generated
6. Badges awarded
# Install dependencies
npm install
# For camera access (mobile/web)
# Ensure HTTPS or localhost for camera permissions
# Request permissions:
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
# For WebSocket (real-time sensor)
# Use ws:// (local) or wss:// (production, HTTPS)
# Build for production
npm run build# Clone repository
git clone <repo-url>
# Install Python dependencies
pip install -r requirements.txt
# Place model files in correct folders:
# vision_model/best.pt (6.2 MB)
# weight_model/weight_estimator.pkl
# weight_model/weight_estimator_config.json
# lifestyle_model/best_ml_model.joblib
# Run server
python app.py
# Server runs on localhost:5000 (or your port)REACT_APP_API_URL=http://localhost:5000
REACT_APP_SENSOR_WS=ws://localhost:5000/api/sensor/stream
REACT_APP_API_TIMEOUT=30000
- Test with various light conditions
- Test with different waste types (all 6 classes)
- Verify 96.1% accuracy on test images
- Check confidence scores (should be 0.25+ for good detections)
- Test with multiple items in photo
- Performance: Should be <7ms per image
- Test with different bbox sizes
- Verify weight calculations match formula
- Test all 6 material types
- Check output: 2g min, 500g max
- Verify explanation text is clear
- Verify emission factors are correct
- Calculate recycling reduction (70%)
- Test with various weights
- Check decimal precision
- Verify WiFi/Bluetooth connection
- Test real-time data updates (every 1 second)
- Check alert system for dangerous levels (500+ ppm)
- Verify 24-hour data retention
- Test with different locations (indoor/outdoor)
- Camera capture works on mobile
- Results display correctly
- Real-time sensor updates visible
- No lag or freezing
- Responsive design (mobile/tablet/desktop)
- User actions (recycle/trash) are logged
- Full pipeline: photo → detection → weight → carbon → display
- Sensor data displayed alongside results
- Real-time updates don't block UI
- Error handling for failed requests
- Offline mode (if applicable)
Problem: Low detection accuracy (<80%)
- Solution: Verify image quality and lighting
- Solution: Check bbox coordinates are valid
- Solution: Ensure model file best.pt is not corrupted
Problem: Slow processing (>20ms)
- Solution: Check if GPU is being used
- Solution: Verify image size (should be normalized)
- Solution: Check server CPU/memory usage
Problem: Unrealistic weight values
- Solution: Verify bbox coordinates are in image bounds
- Solution: Check image shape matches actual image
- Solution: Verify material class is correct (0-5)
Problem: "Weight out of range"
- Solution: Bbox might be too small or too large
- Solution: Verify reference_area_ratio in config (default 0.3)
Problem: WebSocket connection fails
- Solution: Check if backend is running
- Solution: Verify correct WebSocket URL
- Solution: Check CORS settings (wss:// for HTTPS)
Problem: Sensor not updating
- Solution: Check WiFi/Bluetooth connection
- Solution: Verify sensor battery level
- Solution: Check sensor is within range (10-50m)
Problem: Dangerous CO levels not alerting
- Solution: Verify alert threshold is set to 500+ ppm
- Solution: Check notification permissions enabled
- Solution: Verify sound/vibration settings
Problem: User data not persisting
- Solution: Check database connection
- Solution: Verify write permissions
- Solution: Check disk space
Problem: Historical data not loading
- Solution: Verify query filters are correct
- Solution: Check timestamp format consistency
- Solution: Ensure data has not expired
Vision: POST /api/vision/detect
Weight: POST /api/weight/estimate
Carbon: POST /api/carbon/calculate
Lifestyle: POST /api/lifestyle/predict
Sensor Stream: WS /api/sensor/stream
User Logs: POST /api/user/log-action
Get History: GET /api/user/history?days=7
Get Report: GET /api/user/report?period=weekly
Model Files:
- vision_model/best.pt: 6.2 MB
- weight_model/weight_estimator.pkl: ~50 KB
- lifestyle_model/best_ml_model.joblib: ~500 KB
- Config files: ~10 KB
Total Backend Size: ~6.8 MB
Frontend Bundle: ~500 KB (optimized)
Database Per User: ~10 MB/year
For questions or issues:
- Check TROUBLESHOOTING section above
- Review API response codes (200, 400, 500)
- Check server logs for detailed errors
- Verify all model files are present and uncorrupted
Document Version: 1.0
Created: March 2026
For: Frontend Integration Team
Last Updated: March 27, 2026