SmartSpray is an AI-powered precision agriculture system that detects plant diseases, recommends pesticide use, and controls spraying automatically via IoT.
- Problem: Farmers often spray pesticides uniformly, wasting chemicals and causing environmental harm. Disease identification in India requires sending images to agriculture departments, causing delays.
- Solution: SmartSpray uses a camera + ML to detect disease instantly, fetches recommended pesticide schedules, and uses an ESP32-controlled pump + servo to spray only when required. A mobile app lets farmers monitor plant health and manually control spraying.
-
ESP32 (IoT Controller)
- Controls pump & servo.
- Receives spray commands from Flask server.
- Communicates over Wi-Fi.
-
Webcam (Camera)
- Captures plant leaf images.
- Images are sent to Flask server for ML analysis.
-
Flask Server (Laptop/PC)
- Hosts ML model for plant disease classification.
- Manages communication between ESP32 & Flutter app.
- Stores logs & pesticide schedules in JSON.
-
ML Model (TensorFlow/Keras)
- CNN trained on tomato leaf disease dataset.
- Classifies disease and provides confidence.
- Maps disease → recommended pesticide schedule.
-
Flutter Mobile App
- Interfaces with Flask server via REST API.
- Displays logs, disease info, spray history.
- Allows manual override (trigger spray).
- ESP32 → Wi-Fi enabled microcontroller.
- Servo Motors → Rotate to select chemical bottles via tube-switching.
- Mini DC Pump → Sprays liquid pesticide/water.
- Relay Module → Switches pump ON/OFF.
- Power Supply → 5V PSU or Power Bank.
- Nozzles & Tubes → Deliver controlled spray.
- Multiple Bottles → Store different pesticide solutions. Servo + tubing select correct bottle.
-
Endpoints:
/detect→ Receive image, run ML, return disease + spray plan./command→ ESP32 polls to get latest spray command./override→ Flutter app sends manual spray command./logs→ Return spray/disease history.
-
Uses:
ml/model.py→ Loads trained CNN model (.keras).server/schedule.py→ Maps disease to chemical, spray time, servo index.server/logger.py→ Saves logs to JSON.
-
CNN trained on Tomato Leaf Disease Dataset (Kaggle).
-
Input: RGB leaf image (224×224).
-
Output: disease class + confidence.
-
Classes hardcoded :
- Tomato_Early_blight
- Tomato_Late_blight
- Tomato_Leaf_Mold
- Tomato_Septoria_leaf_spot
- Tomato_Yellow_Leaf_Curl_Virus
- Tomato_healthy
-
Defines pesticide recommendations for each disease:
{ "Tomato_Early_Blight": { "disease": "Early Blight", "spray": true, "spray_time": 3, "servo_index": 1, "chemical": "Copper Oxychloride" } } -
Returned by
/detect.
-
Stores all detections & actions in
logs.json. -
Example entry:
{ "timestamp": "2025-09-03T00:45:00", "disease": "Late Blight", "confidence": 0.92, "spray": true, "spray_time": 4, "servo_index": 2, "chemical": "Chlorothalonil" }
-
Connects to Flask server via REST (
http://10.0.2.2:5000for emulator). -
Screens:
- Home → Overview, quick actions.
- Logs → View detection & spray history.
- Control → Manual spray override.
- (Future: Camera capture & upload).
http(API calls)image_picker(optional, for camera uploads)
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>- ESP32 polls
/commandevery few seconds. - Activates relay → pump ON.
- Servo rotates → selects correct bottle.
- Pump sprays for
spray_timeseconds.
- Farmer takes picture (via camera or phone).
- Flask server runs ML → detects disease.
- Flask finds pesticide recommendation from schedule.
- Log entry saved (
logs.json). - ESP32 polls
/command→ executes spray. - Farmer monitors via mobile app.
- Multi-crop disease dataset.
- Real-time field deployment with drones.
- Cloud server for multi-farm monitoring.
- Auto-mixing multiple chemicals.
- Offline ML inference on ESP32-CAM with TensorFlow Lite.
SmartSpray/
│
├── ml/ # Machine Learning
│ ├── model.py
│ ├── best_model.keras
│ └── train_model.ipynb
│ └── model.py
│
├── server/ # Flask Server
│ ├── app.py
│ ├── logger.py
│ ├── schedule.py
│ └── gemini_client.py
│
├── flutter_app/ # Flutter Application
│ ├── lib/
│ │ ├── main.dart
│ │ ├── screens/
│ │ │ ├── home_screen.dart
│ │ │ ├── logs_screen.dart
│ │ │ └── control_screen.dart
│ └── android/...
│
├── logs.json # Detection + spray logs
POST /detect→ Upload image, return disease & spray recommendation.GET /command→ ESP32 polls spray command.POST /override→ App sends manual command.GET /logs→ Fetch detection & spray history.