Sustainable Crop Recommendation System Using Soil NPK Sensor

The effective management of nutrient resources in agricultural practices is crucial for optimizing crop yields and ensuring sustainable farming. Traditionally, farmers have relied on manual methods or expert knowledge to determine the appropriate amount and type of nutrients required by crops. However, these methods often lack precision and can lead to suboptimal fertilization, resulting in reduced productivity and environmental degradation. In recent years, advancements in sensor technology have paved the way for more accurate and efficient crop management systems. One such innovation is the NPK sensor, which enables real-time monitoring of soil nutrient levels. Our proposed system utilizes NPK sensor data to offer personalized fertilization recommendations to farmers. The system integrates sensor technology, machine learning algorithms, and agronomic expertise to provide precise and tailored nutrient recommendations based on the specific requirements of different crops and soil conditions. The system collects data from NPK sensors deployed in the field that includes soil nutrient levels. Machine learning algorithms analyze this data to identify patterns and correlation between nutrient levels and crop performance. By leveraging historical data and agronomic knowledge, the system can generate accurate and timely recommendations for nutrient application. In conclusion, the crop recommendation system presented here offers a novel approach to crop management by leveraging NPK sensor technology and machine learning. By providing accurate and personalized nutrient recommendations, the system has the potential to revolutionize modern agriculture, enhancing productivity while promoting environmental stewardship. Further research and field trials are needed to validate and refine the system’s performance and usability, but the preliminary results show promising potential for the adoption of such system in real-world agricultural settings.


Introduction
The proposed paper aims to develop a crop recommendation system using information from NPK sensors.To find out more about the nutritional composition of the soil, the system will use sensor data from NPK (nitrogen, phosphorus, and potassium) sensors.With the use of machine learning algorithms, this data will be utilized to recommend crops that are likely to flourish in the specific soil conditions.To achieve this goal, the paper will need to take several essential steps.To train and test the model, data collecting is the initial stage.Utilizing the current dataset allows for this.This stage could also include dealing with missing numbers, removing outliers, and normalizing to ensure the accuracy and consistency of the data.The following phase is reading information from the soil using an NPK sensor.

Fig. 1. Instruction for usage of NPK sensor
The machine learning techniques will then be used to build a crop recommendation model utilizing the pre-processed and selected features.These algorithms will follow the success of different crops as they identify patterns and links between those outcomes and the nutrient level of the soil.The model will then be used to recommend the crops that are most suited for a particular field considering the composition of the soil's nutrients.The suggested strategy holds a lot of promise for assisting farmers and agricultural researchers.By providing crop recommendations based on information on soil nutrients, it can help farmers choose crops that are more likely to thrive and yield superior outcomes.This could increase agricultural output and reduce crop failure because of nutrient deficiencies in the soil.A great opportunity to learn about and gain expertise with data processing, feature selection, and machine learning approaches is also provided by the current paper.These techniques can be used in the field of agriculture to boost crop production and assist in resolving issues that affect farmers and the industry.

Literature Survey
Navod Neranjan Thilakarathne, Muhammad Saifullah Abu Bakar, Pg Emerolyariffion Abas, Hayati Yassin, used a cloud-enabled crop recommendation software for machine learningdriven precision farming to make informed decisions on the farms.Machine learning, a subfield of artificial intelligence (AI), is employed to assist people in learning from their experience and afterwards recommending crops.The data are split into training and testing data sets at a ratio of 70:30.This was done using the Random Forest classifier, and the accuracy was 87.23% [1-3].
Machine learning was used by Anguraj.K, Thiyaneswaran.B, Megashree.G, Preetha Shri.J. G, Navya.S, Jayanthi.J. to do crop recommendation on soil analysis.Here, they employed an IoT system to collect real-time data, which was then used to train a model and make predictions.The model's output significantly aids in planting the right crops in certain field locations.This technique was developed with an accuracy of about 80.34% [4].
Crop monitoring and recommendation systems were created utilizing machine learning and IoT by R. Pallavi Reddy, B. Vinitha, K. Rishitha, K. Pranavi.Sensors are utilized to gather the data, which is then delivered to NodeMCU, an android app that is used to train the model and subsequently make predictions.The algorithm utilized in this system, together with key elements like sensors and an Arduino, are used to create the modules.The created system offers appropriate advice and is user-friendly [5].
Using data mining techniques, Aakunuri Manjula, Dr. G. Narsimha created a crop recommendation and yield forecast for agriculture.Data collection, feature selection, employing classification techniques, and crop suggestion using ensembling algorithms are all steps in the methodology.The system's accuracy and precision had been constrained by the use of data mining techniques [7].
For precision agriculture, Mahendra Choudhary, Rohit Sartandel, Anish Arun, Leena used machine learning to produce crop recommendation system and plant disease classification.The technique of the system includes the classification of agricultural diseased and the phases of collecting, exploration, splitting, and implementation.For dividing the primary dataset into the training dataset, valid dataset, and testing datasets, they utilized a 60:20:20 ratio.For predicting the crops, they have employed the Random Forest Classifier [8].

Methodology
The proposed methodology mainly consists of two phases and many sub-phases.The first phase includes reading nutrient values from soil.The second phase of the methodology gives crop recommendations by the developed model using the values obtained from the soil.Figure 2 represents the architecture diagram that shows the actual flow of execution of the methodology [9][10][11][12][13].

A. Hardware Components
The Arduino Uno board, NPK sensor, and MAX485 module are the three main components required for system development.A popular microcontroller board based on the Atmega328P microcontroller is called the Arduino Uno.The board has 6 analog input pins, 6 PWM output pins, and 14 digital input/output pins, including 6 that can be used as PWM outputs.Both 3.3V and 5V logic levels are supported via the I/O pins, which are used by the board to function at 5V.For programming and communication, the Arduino board can be connected to a computer using its built-in USB port [14][15][16][17][18].When seen on a PC, it appears as a virtual COM port.In order to communicate serially with external devices using the USB interface, the board contains a hardware serial port (USART).

B. K -Nearest Neighbors (KNN)
The KNN algorithm is used in the suggested system.The popular supervised machine learning technique K-nearest neighbors can be utilized for both classification and regression tasks.KNN is a non-parametric method since it makes no assumptions about the data distribution, in contrast to parametric algorithms.When utilizing KNN, the training dataset is made up of labeled samples, each of which has a class or target value as well as a set of characteristics.The method analyzes the distance between the new example and each of the examples in the training dataset to create predictions for unobserved examples.Even though the Euclidean distance is frequently used as the distance metric, alternative metrics may be utilized depending on the data's features.The approach determines the K closest neighbors to the new sample after computing the distances, where K stands for a user-defined parameter.KNN assigns the new example in classification tasks the class that is most common among the K neighbors.On the other hand, for regression tasks, KNN calculates the average or median of the target , 011 (2023) E3S Web of Conferences ICMPC 2023 https://doi.org/10.1051/e3sconf/20234300110000 430 values of its K-nearest neighbors to estimate the target value for the new case.The effectiveness of the algorithm is significantly influenced by the value of K. Larger values of K can add more bias into the predictions, whereas smaller values of K may result in more flexible decision limits that are more susceptible to over fitting.Furthermore, since KNN treats all characteristics equally, it is essential to make sure that they are all scaled evenly to avoid any one feature from predominating the distance calculations.In these circumstances, scaling or normalizing techniques can be required.

C. Working
The initial phase of reading nutrient values from the soil requires interfacing of NPK sensor with Arduino board.The semantic diagram for interfacing between the hardware components is shown in figure 6.

D. Model Training
• Firstly, the dataset that is being used is preprocessed by removing the redundant columns and duplicate values that are present.• Secondly, the data and the labels are to be initialized.
• Divide the processed dataset 75:25 into training and testing datasets.
• Now, create a KNN classifier with k=3 as nearest neighbors.
• Once the model is created, train the model with train dataset and save it to the disk.Metrics like confusion matrix, accuracy, train and test set score, and classification report are shown in figure 7.

E. Model Classification and Recommendations
• The data collected from the soil using NPK sensor and Arduino board are supplied to the trained model.• The input data is then classified into labels based on existing dataset.

•
Recommendations are then made with an average accuracy of 99.67% that are displayed using a web application developed using python-based web development framework, flask.

Results
The developed web page is shown in fig.8. On providing the soil nutrient values obtained using NPK sensor, the recommendation of the suitable crop is displayed.

Fig. 9. Crop Recommendations
The proposed system takes nitrogen, phosphorus, potassium values from the soil and recommends crop that best suitable for the soil as shown in figure 9.

Conclusion
According to our research, crop recommendation systems with NPK sensors are crucial to changing the agricultural industry.The Crop Recommendation System described in this work serves as an example of how data-driven solutions have the ability to tackle the urgent problems of feeding a growing global population while minimizing environmental effects.The system helps farmers to implement precision agriculture practices, resulting in

Fig. 3 .
Fig. 3. Arduino Uno BoardNitrogen, phosphorus and potassium, three crucial elements in soil, are measured using an NPK sensor.These essential nutrients are frequently present in commercial fertilizers and are necessary for plant growth.In order to ascertain nutrient contents, NPK sensors examine the electrical conductivity or spectral characteristics of the soil.The sensor is often made up of soil-based probes that can monitor NPK levels in real time or very close to real time.NPK sensors are available in a variety of configurations, including portable

Fig. 4 .
Fig. 4. NPK Sensor The MAX485 module, enables a two-way communication between devices that use TTL-level signals and those that use RS485 signals.The MAX485 integrated circuit, a lowpower transceiver for RS485 and RS422 communication, is the foundation of the MAX485 module.The module supports a half-duplex communication that changes TTLlevel signals into differential voltage signaling RS485-level signals.This enables longer-distance communication with improved noise immunity.This module is normally compatible with development boards and microcontrollers that operate in the 3.3V to 5.5V supply voltage range [26-31].

Fig. 6 .
Fig. 6.Arduino -NPK interfacing [2] • The NPK sensor has four wires.The brown power line needs to be attached to the 5V-30V power supply.The black ground wire needs to be attached to a common ground.• The RS485 module's A pin should have the yellow wire of the NPK sensor connected, and the B pin should have the blue wire connected.• The digital pins 2 and 3 of the Arduino should be connected to the RS485 module's R0 and DI pins.• The DE and RE pins should be linked to digital pins 7 and 8, respectively, and the VCC pin of the RS485 module should be connected to the Arduino's 5V output.• Finally, the Arduino and the circuit should have a common ground.

Fig. 7 .
Fig. 7. Metrics Graphs for train set and test set are plotted.