Design and Development of Soil Nutrients Level Detection System based on Soil Color and pH for Crop Recommendations using Fuzzy Algorithms

In recent years, modern farmers usually taking a soil sample to the laboratory or using a soil test kit to identify and measure soil macronutrients, i.e., nitrogen (N), phosphorus (P), and potassium (K), and pH to determine what kind of crop plant is suitable for their agriculture land. However, these manual methods are costly and time consuming. The characteristic of soil samples also possibly changing by time or contact during transport. This paper presents the design and development of a portable integrated soil macronutrient level and pH detection system that can analyze soil samples quickly. To give crop recommendations, IoT components and cloud-based fuzzy inference systems are used. The fuzzy algorithm decides the crop recommendation from the soil pH and level content of N, P, and K. The user can receive the crop recommendation via the android application. Data are sent from the portable system to the cloud system and vice versa using the internet network with HTTP request protocol. The accuracy test results of system plant decision on agricultural land were compared with the fuzzy logic method have a quite uniform crop output with a small error rate of 1.66%.


INTRODUCTION 
Every agricultural land must contain sufficient nutrients, which consists of Nitrogen (N), Phosphorus (P), and Potassium (K) [1]. The varying levels of minerals, water, etc., can affect the color of the soil. The color of soil helps agronomists understand soil composition and classify it to produce optimum crops.
Soil color tells agronomists if the soil lacks essential nutrients such as nitrogen, phosphorus, and potassium [2]. The availability of soil nutrients is related to the level of Soil pH (potential of hydrogen), a parameter that can determine soil fertility quality [3]. Hence knowing the soil nutrients and soil pH before planting in a random area has become necessary.
So far, Indonesian farmers have not paid attention to the condition of soil pH and essential nutrients on their land. The local Agriculture Service only tests both those parameters by taking soil samples to be measured from a field, then measurements taking place in the laboratory with different steps between detecting soil pH and each essential nutrient. That method would take a long time to get each parameter data, and it needs additional time to match with the appropriate crop recommendation.
Using the detecting method for soil essential nutrients and soil pH measurements systems on Author Correspondence Address: Novanna Rahma Zani Email : novannarahmazani@gmail.com Address : Politeknik Elektronika Negeri Surabaya agricultural land, a portable tool can be used to record the level of each essential nutrient and soil pH of the soil sample and process the data to generate crop recommendations. The nutrition level (high, medium, and low) detection method is based on the principle of absorption and reflection. The N, P and K level of the sample is determined by absorption light (RGB) of each nutrient. The light transmission system that is four LEDs of color sensor utilizes three different color's wavelengths: red, green, and blue, which is related to nitrogen, potassium, and phosphorus value. The difference between standard absorption wavelength and the sample absorption wavelength of a particular color gives the amount of nutrients. Photodiode receives the light reflected from soil, whereas soil receives the light from LEDs as a light-transmitting source [4]. Table I. illustrates different wavelengths. Using a Color sensor TCS3200, Soil pH sensor and processed with a microcontroller, recorded data parameters will automatically upload to the cloud station and integrated with the mobile apps for assisting observations about the soil condition. The cloud system also processes appropriate crops planted on the land recommendation using fuzzy logic algorithms based on the soil pH values and nutrients level.

EXPERIMENTAL METHOD Hardware System
The hardware in the system functions as a data acquisition unit to record soil pH and detect soil NPK nutrient levels which are controlled by the main WiFi-based microcontroller, NodeMCU ESP32 which will send the data recording results to the Cloud station via the internet network.

Electronic System Hardware
The main components consist of Soil pH electrode and Color recognition sensor TCS3200, ESP32, logic level converter, and voltage regulator. Shield controller ESP32 is a circuit that combines the voltage regulator, sensors, LCD, and button, which is replaced with a pin on ESP32 as a microcontroller and the transmitter of data to be more compact and well kept.

Mechanical Design
Mechanical design is equipped with a soil sample container, hardware box, and sensors position to facilitate the recording of soil parameters.

The Accuracy Value of Color Sensor for Level of Soil Nutrients Detection
The Output of color sensors R, G, and B has been set to represent Soil macronutrients N, P, and K levels (high, medium, and low) compared to the Soil test device. Some samples in the different 3 area are tested with the soil test devices and Table II. shows high medium or low levels for NPK soils in three different samples.  Measurement of soil color in the soil samples used a soil test device to fit the range of each soil essential nutrients level. After being tested with a soil test device, all soil samples are retested with a color sensor to check the output of each level nutrient and obtain accuracy ± 2.73%. The Accuracy Value of Soil pH For soil pH in the sample soil in the agricultural land layer used electrode soil pH with soil pH range 0-10 with accuracy 0.10pH. From the results of the calibration of the ADC reading to pH change, an equation is obtained to determine the soil pH value as follows: Figure 6. Graph of Calibration Soil pH Sensor y = 0.0137x + 0.2588 Figure 6. Shows that the soil pH has characteristic in taking data. Soil pH sensors measuring soil pH have a response time to achieve stable measurement results, and the error value is getting smaller. So that every time the measurement of the soil pH sensor requires a response time of ± 1 minute concerning the soil pH sensor datasheet. While the relationship between the measured soil pH value and the resulting ADC value, it can be seen from the above curve that the greater the ADC value, the greater the measured soil pH value, meaning the ADC value is thinly proportional to the soil pH value. From the graph above, the equation is y = 0.0137x -0.2588; this equation is used in the hardware program to determine the soil's pH value.

Software System
The function of the software system is a receiver, storage, and visualization of sensor data. The software system consists of 2 parts as follows:

Cloud Station
Cloud Station is a data storage unit received from the transmitter (hardware device). In the cloud station as a database using one of the Google databases, Google spreadsheets with Google's servers.    (Zani, et al.) then processed with Google Apps Script. The data will be processed with a fuzzy logic algorithm embedded in the Google Apps Script to determine which plants are match with the soil, and all recorded data obtained is displayed in real-time with a google spreadsheet. The fuzzy logic algorithm is used to process sensor data that has been received by the server (Google Spreadsheets) to find out which plants are suitable for the soil sample. Figure 8. Explain about the design of fuzzy logic in the system. Membership input consists of membership input pH, content level of N, P, and K with membership output in the form of soil level that will define food crop recommendation.

Android Application
Android application functions as a client in the system. All Data has been stored and processed on Google spreadsheets and also can be accessed through the Android application as a client. Making this android application uses android studio with flutter programming language. In data acquisition from the server-side, there is an algorithm for data acquisition on the client-side (Android Application). The following data acquisition flowchart is on the client-side. Figure 9. Shows the flowchart of the data acquisition system that is on the client-side. Starting with the login system. After user success login, the system reads the spreadsheet data; if there is abnormal data on Google spreadsheet, the data must be normalized again on the server. Whereas when the data on Google spreadsheet is normal, or there are no unwanted characters, the application will do an API spreadsheet calling so that the recording data results can be displayed in the form of historical data. History data is displayed according to the time of data collection with the date-month format and the amount of data. After that, click on the history data list, the results will appear of the sample land tested. The following is the Android application interface.

RESULT AND DISCUSSION
This performance decision-making test is to test the fuzzy algorithm system applied to the server by taking 5 sample points from 3 areas of agricultural land at ± 7 x 4 square meters. This test was carried out for two days to see the output of plant decision-making and test the accuracy of sensor readings. The following is the results curve of the system decision-making plant decision using the fuzzy method. RMSE is an alternative method for evaluating forecasting techniques used to measure the accuracy of a model's forecast results. RMSE is the average value of the number of squared errors, and it can also state the size of the error produced by a forecast model. The low RMSE value indicates that the variation in the value produced by a forecast model is close to the variation in the value of its observations. In Figure 12., the Graph of Root Mean Square Error from the System shows the average fuzzy calculation error of 6 samples at each point, the average error of the whole sample is around 1.66 %. This standard deviation was used to determine the value of the distribution of error data in a sample of data and how close each individual data point is to the average value of the data error. It can be seen the standard deviation graph of the system from the five sample points that get one standard deviation value that is equal to 0.1596; thus, it can be concluded that the distance of each data point is quite small with an average value, it shows that the crop decision-making system is sufficiently stable and has worked well.
Fuzzy methods for decision-making that have been designed need to be tested and validated to ensure that they are in accordance with the correct algorithm. Validation is done by comparing the results of fuzzy controls derived from Matlab software with the results of fuzzy controls made on the server. Matlab software is chosen because it has become a standard in simulations conducted in world education institutions. If the comparison results are the same or close, the fuzzy system that is designed is correct. The test results can be seen in the following table.

Design and Development of Soil Nutrients Level Detection System based on Soil Color and pH for Crop
Recommendations using Fuzzy Algorithms (Zani, et al.) When compared with the results of system testing on the first day, area 1 produces a different recommendation output. This is due to the detection of different levels of nutrients due to the values of R, G, and B, which tend to be different on the first and second days. On the first day, the system testing was carried out in the afternoon with sunny but not hot weather so that the light from outside did not affect the output of R, G, and B. While on the second day, the system was tested in the afternoon with the sun shining and making the sensor output is affected and produce different recommendations. In Area 2, compared with the results of system testing on the first day, area 2 produces the same recommendation output, peanuts. This is due to the detection of nutrient levels carried out in sunny with no sunlight so that the light from outside does not affect the output of R, G, and B. Likewise on the second day, the system testing was carried out in the afternoon with the sun not scorching hence the output of R, G, and B are stable and produce the same recommendation output. When compared with the results of system testing on the first day, area 3 produces the same recommendation output. This is due to the detection of nutrient levels carried out in sunny but not hot weather so that the light from outside does not affect the output of R, G, and B. Likewise, on the second day, the system testing was carried out in the afternoon with the sun not scorching so that the output R, G, and B are stable and produce the same recommendation output as the first day. All tested data shows that the system is quite as expected and has a quite small error (1.66 %) compared to the MATLAB simulation. On the above is a curve that shows the performance error of decision-making using the fuzzy logic method. . shows a comparison of the soil pH measurements results in 3 test areas carried out for two days by taking five different sample points in agricultural land areas. The chart above shows that the soil pH conditions on agricultural land in Tangerang, Indonesia are included in soil conditions with medium acidity levels, which in the system are marked as Acid2, which is the range of soil pH values from 5.5 to 6.5.  Figure 23. shows a comparison of the color sensor measurement results on a red value for detecting soil K nutrient levels in 3 test areas carried out for two days by taking five different sample points in agricultural land areas. System testing on agricultural land in Tangerang, Indonesia, showed that the level of content in the land had the same level of K nutrients, namely in area 1, area 2, and area 3 it was detected at the level of Medium K content. Figure 24. Comparison chart of G value from Color sensor output Figure 24. shows a comparison of the color sensor measurement results on a green value for detecting soil P nutrient levels in 3 test areas carried out for two days by taking five different sample points in agricultural land areas. System testing on agricultural land in Tangerang, Indonesia, showed that the same level of P nutrient content, these three areas were detected at high levels of P content.   (Zani, et al.) detected, in area 2, low N content was detected, and area 3 N content in the high level.

CONCLUSION
The result of this system is a mechanism that records the soil's pH and color of the soil to identify the plant recommendation based on the pH condition and level of nutrition content N, P and K. All data were recorded and sent to Google Spreadsheets, integrated with the software for visualizing results as each level of nutrients, pH conditions and food plant recommendation. User could access on the Android applications. The test results of farmland sample plant decision making by fuzzy logic have a very uniform crop output according to the input of the sensor data readings at a small error rate of 1.66%. Therefore, the determination result of the plant is very accurate because the accuracy of the soil pH sensor is 0.1 pH, and the color output of the soil for detecting the accuracy of the content level of N, P and K is 2.73%. Therefore, the prototype of this tool is expected to be useful and applicable to the wider community, especially farms, where farmers can easily know the level of key nutrients in each sample, know crop recommendations, and control agricultural input variables.