SoilSense AI – Intelligent Soil Monitoring and Crop Recommendation

Inspiration

Agriculture plays an important role in our lives, but choosing the right crop is not always easy. Soil conditions, nutrient levels, temperature, humidity, seasonal changes and water availability all influence crop growth.

We wanted to explore how Artificial Intelligence and the Internet of Things (IoT) could help farmers make more informed cultivation decisions.

This inspired us to develop SoilSense AI, a smart farming solution that combines real-time soil monitoring with machine learning to recommend suitable crops based on soil and environmental conditions.

Our vision is to make agricultural decision-making more accessible, data-driven and intelligent.

What it does

SoilSense AI is an IoT-based soil monitoring and AI-powered crop recommendation system.

It collects six important soil and environmental parameters:

  • Nitrogen (N): Measures soil nitrogen levels.
  • Phosphorus (P): Measures soil phosphorus levels.
  • Potassium (K): Measures soil potassium levels.
  • Soil pH: Helps understand soil acidity and alkalinity.
  • Temperature: Tracks environmental temperature.
  • Humidity: Monitors relative humidity.

The collected readings are processed by a machine learning model, which recommends a suitable crop and provides additional cultivation information.

Key features

  1. Soil Monitoring: Displays NPK, pH, temperature and humidity readings.
  2. AI Crop Recommendation: Classifies the most suitable crop from 57 crop categories.
  3. Water Requirement Prediction: Estimates the crop's water requirement.
  4. Harvest Month Prediction: Estimates the expected harvesting month.
  5. Crop Duration Prediction: Estimates the crop growth duration in days.
  6. Web Dashboard: Presents sensor readings and prediction results through a user-friendly interface.

How we built it

We developed SoilSense AI by integrating hardware communication, backend development, machine learning and a web-based dashboard.

1. IoT and hardware integration

An Arduino-based soil monitoring setup collects sensor readings. The readings are transmitted through serial communication in the following format:

N, P, K, pH, Temperature, Humidity

A Python script (king.py) reads the serial data and sends the latest sensor values to our Flask backend using HTTP requests.

2. Machine Learning model

We developed a multi-output neural network using TensorFlow and Keras.

Our model uses:

  • 57,000 agricultural records for training.
  • 19 input features, including soil type, season, sowing month, water source, NPK values, pH, temperature and humidity.
  • One-hot encoding for categorical features.
  • StandardScaler for numerical feature preprocessing.

We trained the model using an 80:20 training and testing split for 40 epochs.

The neural network contains three hidden layers:

  • Dense layer: 128 neurons
  • Dense layer: 64 neurons
  • Dense layer: 32 neurons

It has two output branches:

  • Classification output: Uses Softmax to predict one of 57 crop categories.
  • Regression output: Estimates water requirement, harvesting month and crop duration.

We saved the trained model and preprocessing components so they can be reused by the application without retraining every time.

3. Backend development

We used Python and Flask to develop the backend.

The backend provides two important API endpoints:

  • /api/sensors – Receives and updates sensor readings.
  • /api/predict – Processes user-selected farming conditions and generates AI predictions.

4. Web dashboard

We developed a web interface using HTML, CSS, JavaScript and Bootstrap.

Users can select soil type, season, water source and sowing month. The dashboard displays the latest sensor readings and the resulting crop recommendation, estimated water requirement, harvest month and crop duration.

Challenges we faced

During development, we encountered several technical challenges:

  • Dataset preprocessing: Agricultural datasets contained inconsistent categorical values and formatting differences. We implemented text normalization and category matching to handle these inconsistencies.
  • Multiple prediction outputs: Predicting crop categories and numerical agricultural parameters required a multi-output neural network with separate classification and regression branches.
  • Hardware and software communication: We needed reliable serial communication between Arduino and Python, followed by HTTP communication with the Flask backend.
  • Model integration: Saving and loading the trained model, label encoder and preprocessing pipeline correctly was essential for consistent predictions.
  • Real-time data handling: We implemented a mechanism to process the latest available sensor reading rather than allowing old readings to accumulate in the serial buffer.

These challenges helped us understand how to integrate multiple technologies into one working prototype.

What we learned

Through this project, we gained practical experience in:

  • IoT and serial communication.
  • Soil parameter monitoring.
  • Machine learning and neural networks.
  • Multi-output classification and regression.
  • Data cleaning and preprocessing.
  • TensorFlow and Scikit-learn.
  • Flask API development.
  • Frontend and backend integration.
  • Connecting hardware data with AI applications.

Most importantly, we learned that building a useful AI solution requires more than training a model. Hardware integration, data quality, preprocessing and user experience are equally important.

Future improvements

We plan to improve SoilSense AI by adding:

  • More extensive testing with real agricultural field data.
  • Location-specific crop recommendations.
  • Weather forecast integration.
  • Improved fertilizer and irrigation suggestions.
  • Multilingual support for farmers.
Share this project:

Updates

Submission history