You are on page 1of 13

Soil NPK and Moisture Prediction for Fog

Assisted Smart Agriculture System


Niva Tripathy,Sampa Sahoo
May 2022

1 Abstract
Smart agriculture is an emerging concept that allows the management of farms
with the latest technologies such as IoT, AI, robotics and drones, etc. The
intent is to increase the quantity and quality of crop production while optimizing
the available resources. To achieve the goal of growth in crop production, soil
fertility and moisture level play an important role. Earlier, various fertilizers
are added to improve the soil nutrients which requires human labor and time.
Later on, with the advent of technologies cloud computing was used to process
the data collected from IoT devices. The remote placement of cloud servers
suffers from high latency, which is overcome by fog computing. This paper
presents a fog-assisted smart agriculture system model to monitor soil fertility,
pH, soil moisture, and temperature data. In the fog layer, the collected data are
analyzed, and an intelligent recommendation is generated for soil fertilizer level
to improve the quality of soil and hence crop growth. Soil NPK value data set is
used for the analysis. The proposed model takes NPK value and soil moisture,
and water level data from the sensor, and prediction is performed using the
IFogsim platform.

2 Introduction
Agriculture is the most vital part of society to provide food, grains, and other
raw materials. With the advancement of technology, the production of the agri-
cultural field has been enhanced. There are several mechanisms used for smart
farming. Internet of Things (IoT) has opened up a suitable solution for smart
farming and agriculture domains [16]. It uses different methods for collection
of weather data, monitoring of crop growth, early detection of crops diseases,
prevention of crops wastage dues to effective harvesting of crops, monitoring of
livestock’s behavioral patterns, animal location within and outside the farms,
increase of production for both crops and livestock.
There are fourteen essential plant nutrients required for crop production.
Among that nitrogen (N), phosphorus (P), and potassium (K) are needed in

1
large amounts. For that reason, they are often considered the most important
nutrients. The main functions of N and P are that they are constituents of
proteins and nucleic acids, which are important components of plant tissue.
K is the only nutrient that is not a constituent of organic plant compounds
but is mainly of importance in the regulation of processes in the plant, such
as osmosis and enzyme activities. K is generally playing an important role in
the quality of harvested plant products. Soils will contain different amounts of
available nutrients, depending on the parent material (e.g. sand, clay, peat), and
differences in the management history such as preceding crops, management of
crop residues, and use of manure and fertilizers in the past. Also, differences in
climatic conditions may alter the available nutrients[18]. For that reason, it is of
importance for farmers to know the NPK content of their soil, so that they know
how much N, P, and/or K they should add with organic or mineral fertilizers, to
optimize crop growth, production and yield. The use of IoT for measuring soil
parameters like soil NPK, moisture, ph, humidity, and temperature meets the
ongoing demand for crops. With low cost and less manpower, the crop quality
and production has been increased.
As the IoT allows users to automate and control their daily tasks without
human intervention that leads to uniformity in the task. Fog computing ap-
proaches are used to bring cloud services closer to the network’s edge with a
highly virtualized and distributed platform with storage and compute capabil-
ities. Before approaching the cloud layer, the fog layer will analyze a massive
amount of data which saves a lot of bandwidth and convenience for faster de-
cision making. IoT sensors are transferring data to Fog devices making free
efficient sensor data transfer. The Fog device will provide real-time analysis in-
clusive of computation, storage, and network services at the network edge. This
paper proposed a methodology for predicting soil NPK and moisture content
for enhancement and strengthening of crop value. The proposed system model
collects the soil NPK value and moisture content and intelligently predict the
quantity of water and fertilizer by using two Machine learning algorithm[17]
i.e Random forest and Decision tree. The prediction model is designed using
several parameters and model is trained using historical data.

3 Related Work
The existing article for smart agriculture mostly discussed some climatic pa-
rameters like temperature, humidity, rainfall some agronomical parameters like
soil, nutrient contents like NPK and pesticides, etc. some of the articles are
projected in this section to show the working pattern and finding out where the
enhancement is required for better production rate in agriculture.
B. Liu et al.[1] proposed a IoT based agriculture system to recognize soil
type and suitable crops identification . J.D. Zhang et al.[2] proposed a projects
on the management issues in IoT based agricultural systems based on the geo-
graphical locations and the climatic conditions in the specified locations which
offers benefit to the users .

2
Pandiyaraju et al.[3] discussed a system for using probable variation in the
weather conditions to predict the suitability of crop production for the specified
geographical location in the particular season. The proposed model uses the
probabilistic factor model to analyze the soil nutrients level and associated crop
with the given soil content. It helps the farmers in a real manner to increase
the cultivation of any crop.
Keswani, Bright et al.[4] recommend a geographical based personalized crop
monitoring system. Inputs for the model has been collected from the user and
develop a personalized crop monitoring for agricultural field which relevant to
their location and their previous cultivation. Khat tab et al[5] proposed the
smart terrace gardening process which shows the efficient techniques used for
water conservation. Intelligent rules are designed and implemented in this sys-
tem to facilitate less consumption and improve plant growth.
Akshay Badhe et al[6] mentioned a technique to examines the current weather
condition and moisture level of the soil to provide recommendation for requiring
water level and weather conditions. it uses IoT based project which supports
smart and precision agriculture. Muthunoori Naresh et al.In [7], designed a
cloud-based IoT scheme for precision agriculture. This system provided the
evaluated numbers from the sensors to the user’s mobile or the system through
cloud computing technology.
P.R.Harshani et al[8] designed a model for monitoring the soil parameters
like temperature, moisture, pH, humidity and light using various sensors . The
values obtained are converted to digital using an Analog to Digital Converter
and serially sent to the cloud through a Raspberry pi. Finally, the output is
displayed in the laptop or in a mobile application.
Marianah Masrie et al.[9-10] proposed a system to supervises the overall soil
characteristics using IoT . For efficient crop production, soil parameters like:
pH level, soil moisture, temperature and humidity are continuously monitored
using sensors.
Madhumathi, R et al[10] Designed a system in which the fertility of soil has
been improved, and the quality of the soil can be increased by the development
of optical transducer . The amounts of NPK are determined by index as low,
medium and high. Goap et al. [11] proposed IoT based agriculture system
which uses Machine Learning approaches for soil classification.
As found from the literature study many of the machine learning prediction
algorithm has been implemented in cloud layer.They have discuss the accuracy
of the machine learning algorithm like SVM, GD,Naive Bayes and Decision Tree
for soil NPK and Moisture prediction purpose. To over come the drawback of
cloud layer in our proposed model we have introduced a highly virtualized com-
puting platform for compute, storage and network services. In this model fog
nodes are placed between IoT and cloud layer towards the edge of the network.
Fog layer act as bridge between cloud and Cloud and Edge by enabling comput-
ing, storage, networking, and data management on network nodes within the
proximity of IoT devices.We have compared two machine learning prediction
algorithms i.e Decision tree and random forest for better soil property predic-
tion and recommendation. previously no work has been performed with random

3
forest prediction algorithm.

4 Methodology
4.1 Proposed System Architecture
The overall architecture of IoT enabled fog based smart agriculture is described
in Fig. 1.
The proposed system model is for efficient prediction of soil NPK and mois-
ture value. A generalized fog computing model has been introduced. Consid-
ering the opportunities available in fog computing an IoT-enabled environment
has been set for development and analysis purposes.The proposed model is tak-
ing agricultural data sets which contain information on soil properties. That
data will be stored in the Agri data base. Two different ML algorithm that is
decision tree and random forest has been used for the soil properties prediction
and recommendation.
The proposed recommendation model is feed to the fog layer and the pre-
diction result will be send to the cloud layer for approximate recommendation
of soil NPK and moisture. In this paper we have used iFogsim simulator for im-
plementing the prediction algorithm. The details of each layer of the proposed
model has been described below.
The proposed system model architecture may have the following layers:
• Innermost IoT layer (Sensor Layer):
Sensor Layer is called the IoT layer and it is the most important layer
of the smart farming architecture. Different sensors are placed in this
layer for data collection. These sensors will keep tracking the various soil
properties like moisture, soil chemical properties, ph level, and many more
important data.
• Middle Fog layer (Network Layer and Service Layer):
contains a large number of devices called fog nodes which includes EU
devices, access points, gateways, routers, switches, etc. the main objective
of the fog node is to enable the uploading and downloading of various data
near data sources. It will develop a direct communication link between
the devices in that layer. Information management is also done here

• Cloud layer (Application Layer):


The top most layers that are cloud layer produces a visualization result
after successful computation of collected data.

4
Fig 1 Proposed framework in fog computing paradigm

4.2 Recommendation Model


Fig 2 represents the block diagram of the proposed recommendation model
for an IoT-enabled fog computing for the efficient prediction of soil NPK and
moisture value. It gives a detailed flow of each process and step. For that
model, input has been taken from the UCI machine learning data repository.
These are the historical data. Users can easily predict the soil parameters
after extracting the features from the inputted information. To approximately
calculate the efficiency and effectiveness of our experiments we have taken two
machine learning classification algorithms i.e Random forest and Decision Tree.
By executing the algorithm with the given data set value the system will produce
the accuracy and error rate. A graph will be generated on the accuracy value of
the algorithm. This graph will be sent to the user for reference. Each time the
updated value of the soil parameter will be updated to the database for future
use. This system will give output as different soil parameters and recommend
the quantity of fertilizer and water needed. This will reduce the use of excess
fertilizer and water thereby maximizing crop production. With the use of the
ML algorithm the accurate results are obtained which increase the cultivation
by providing real-time responsive data[18].

5
Fig 2 Block Diagram of Recommendation System

4.3 Pre-Processing

Fig 3 iFogsim Topology

A large data set is needed for the prediction purpose.The information gathered
from different sources is often in raw form. It could include information that is
incomplete, obsolete, or inconsistent. As a result, such redundant data should
be filtered in this process.The information should be normalized.The provided
data collection has many ’NA’ values, which are filtered in iFogsim.In the pre-
processing step data set will be divided into training data set and testing data
set.This is the important step while creating model. The training data set is
used to train a model and testing data set is used to evaluate the model. So,
we fit the model with training data and test it with testing data.

6
4.4 Proposed Prediction Algorithm
Here we are using Random Forest algorithm which is well known supervised
learning algorithm that works on bagging technique. Random Forest Algorithm
is a combination of number of decision tree. This algorithm is a classification
algorithm based on ensemble classifier. It will divide the data set into Training
data and testing data. Further training data set is used to build the decision
tree. Model will build a decision tree by considering training data and separates
the weaker node from training data to get a better model. Each and individual
training data set will generate a decision tree and then generate random forest.
The general idea of the bagging method is that an aggregate of mastering output
will increase the overall result. Random forest algorithm builds multiple deci-
sion trees during training. Predictions made from these decision trees will be
collected and the final output will be the one which is having maximum votes.

Algorithm 1 Prediction Algorithm


1: function GenDecTreeForSoil(sample, featur)
2: if stoppingcond = true then
3: leafsoil = createNode
4: leaflabel = classify
5: end if
6: return leafsoil
7: root = createNode
8: root.testcondition = findBestSpilt
9: V = testcondition
10: for all v ∈ V do
11: Child = TreeGrowth
12: Add child as descent of root and label the edge root →child as v
13: return root
14: accuracy(leafNode/child)
15: if accuracy = 0.5 then i = 1 to c
16: Randomly sample the training data S with feature F
17: Create a root node N
18: Call BuildTree(N)
19: BuildTree(N)
20: if if N contains instance of only one class then
21: randomly select x of the possible splitting features in N
22: return the feature F with the highest information gain to
split
23: end if
24: end if

7
4.5 Accuracy and Error Rate
Accuracy is the one of the metrics uses for evaluating classification model. Ac-
curacy is calculated by dividing number of correct predictions by total number
of predictions.
Accuracy = (Number of correct predictions/Total number of Predictions)
Error Rate= [(exact value - approximate value)/exact value] x 100
We have achieved the 96 percent accuracy and 3.68 error rate which means
this model is good for predicting soil NPK and moisture

4.6 Comparison with different model


By considering the different algorithm used before in cloud layer for soil NPK
and moisture prediction, we found that decision tree algorithm has given better
accuracy and less error rate as compared to other. We have executed decision
tree and random forest algorithm in fog layer. The prediction result we got
having high accuracy and less error rate for random forest algorithm. This is
because the Random forest will construct the decision tree for individual set of
training dataset and then combine the multiple decision trees into to a single
decision tree and it will predict the yield by considering the Average value of
the Tree [8]. Analysis of two different algorithms is considered in Table 1 with
respect to accuracy and error rate in cloud layer and fog layer.

5 Result and Discussion


In this paper, an effort is made to approximately predict the soil NPK and
moisture for improving the cultivation. For this work, 70 percent of data is
used for training the model and 30 percent of data is used for testing. After the
successful training and testing of the model with two classification algorithms,
we have compared the accuracy and execution time of the model against each
algorithm in the fog layer.

5.1 Algorithm Comparison


Other work that proposes the prediction model and algorithm in cloud comput-
ing provides high error rate, CPU utilization, and latency. Many prior works
[8,9,10 ]do not leverage resources close to the edge of the network.In the fog
layer our proposed model will predict the soil NPK and moisture level in an
efficient manner than the model proposed in related work[5].For approximate
evaluation of the efficiency and effectiveness of our model, we compare random
forest and decision tree classification algorithms for soil parameter prediction.
Table 1 below represents the values.

8
Table 1: Accuracy comparison of algorithm
Parameter Random Forest Decision Tree
Error Rate 3.68 5.86
Accuracy 0.96 0.68

Fig 4 Accuracy comparison of algorithm

Fig 4 represents the graph between input data and accuracy in Random
forest algorithm in contrast to Decision tree algorithm.

Fig 5 Error Rate comparison of algorithm

Fig 5 represents the error rate of both the classification algorithm. In the
time period of execution of random forest algorithm with given data set gives
less percentage of error as compared to decision tree.

9
5.2 Performance comparison
In this paper we have also performed a comparison of the performance param-
eters such as the,Execution time,CPU utilization,Energy consumption and La-
tency, when executed in Fog and Cloud to measure the efficiency of model.Table
2 represent the comparison of performance in cloud and fog environment.
Table 2: Comparison of Performance Parameter
Layer Execution Time(MS) CPU Utilization(IMPS) Energy Consumption Latency
Cloud 75.56 44.8 98.45 200.45
Fog 20.783 22.8 45.67 80.43

Fig 6 Performance Comparison Of Cloud Fog Layer

Fig 6 represent the comparison of performance factor of a process in cloud


and fog layer.Its shows processes executed in fog layer will have less execution
time, CPU utilization ,Energy consumption and Latency than process executed
in cloud layer[23].

6 Conclusion
This work presents an effective monitoring of soil NPK and moisture value of
soil by using past data.. Based on these parameters analysis will be made to get
a suitable soil parameter. The random forest and decision tree ML classification
algorithm is used to predict soil parameters. The computation has been done
in the Fog layer and the results of the computation are successfully stored in
the cloud layer for future use and can be accessed remotely. This work may be
extended by using load balancing and resource utilization in the fog layer for
increasing the energy minimization in future.

10
7 References
1 B. Liu, H. Xiong, S. P apadimit riou, Y. Fu, and Z. Yao, “ A general
geographical probabilist ic factor model for point of interest recommendat
ion,” IEEE T ransact ions on Knowledge and Dat a Engineering, vol. 27,
no. 5, pp. 1167–1179, 2015.
2 J.D. Zhang, C.Y. Chow, and Y. Li, “ igeorec: A personalized and efficient
geographical locat ion recommendat ion framework,” IEEE Transactions
on Services Comput ing, vol. 8, no. 5, pp. 701–714, 2015.
3 Pandiyaraju, V., P. Shunmuga Perumal, A. Kannan, and L. Sai Ramesh.
”Smart terrace gardening with intelligent roof control algorithm for water
conservation.” Pak. J. Agri. Science, vol. 54, no. 2, pp. 451-455, 2017.

4 Keswani, Bright , Ambarish G. Mohapatra, Amarjeet Mohanty, Ashish


Khanna, Joel JPC Rodrigues, Deepak Gupta, and Victor Hugo C. de
Albuquerque. ”Adapt ing weather condit ions based IoT enabled smart
irrigat ion technique in precision agriculture mechanisms.” Neural Comput
ing and Applicat ions, vol. 31, no. 1, pp. 277-292, 2019.

5 Khat tab, Ahmed, Ahmed Abdelgawad, and Kumar Yelmarthi. ”Design


and implementat ion of a cloud-based IoT scheme for precision agricul-
ture.” In 2016 28th International Conference on Microelectronics (ICM),
pp. 201-204. IEEE, 2016.
6 Akshay Badhe, Sandeep Kharadkar, Rushikesh Ware,Pratik Kamble Prof.
Shilpa Chavan, “IOT Based Smart Agriculture and Soil Nutrient Detec-
tion System”, International Journal on Future Revolution in Computer
Science Communication Engineering, Vol. 4, Issue 4,pp.774 – 777, 2018.
7 Muthunoori Naresh, P Munaswamy, “Smart AgricultureSystem using IoT
Technology”, International Journal of Recent Technology and Engineering
(IJRTE), Volume-7Issue-5, pp.98-102, 2019.
8 P.R.Harshani, T.Umamaheswari,R.Tharani,S.Rajalakshmi, J.Dharani, “Ef-
fective crop productivity and nutrient level monitoring in agriculture soil
using IoT”, International Conference on Soft Computing and Network
Security (ICSNS), IEEE, 2018.

9 Marianah Masrie, Mohamad Syamim, AizuddinRosman, Rosidah Sam and


ZuriatiJanin, “Detection of Nitrogen, Phosphorus, and Potassium (NPK)
nutrients of soil using Optical Transducer”, 4th International Conference
on Smart Instrumentation IEEE, 2017.
10 Madhumathi, R., T. Arumuganathan, and R. Shruthi. ”Soil NPK and
Moisture analysis using Wireless Sensor Networks.” 2020 11th Interna-
tional Conference on Computing, Communication and Networking Tech-
nologies (ICCCNT). IEEE, 2020.

11
11 A. Goap, D. Sharma, A.K. Shukla, C.R. Krishna, An IoT based smart
irrigation management system using Machine learning and open source
technologies, Elsevier, 2019 doi:10.1007/978-3-030-267636.
12 Mekala, Mahammad Shareef, and P. Viswanathan. ”A Survey: Smart
agriculture IoT with cloud computing.” 2017 international conference on
microelectronic devices, circuits and systems (ICMDCS). IEEE, 2017.
13 Suma, N., Samson, S. R., Saranya, S., Shanmugapriya, G., Subhashri,
R. (2017). IOT based smart agriculture monitoring system. International
Journal on Recent and Innovation Trends in computing and communica-
tion, 5(2), 177-181.

14 Guardo, E., Di Stefano, A., La Corte, A., Sapienza, M., Scatà, M. (2018).
A fog computing-based iot framework for precision agriculture. Journal
of Internet Technology, 19(5), 1401-1411.
15 Yang, X., Shu, L., Chen, J., Ferrag, M. A., Wu, J., Nurellari, E., Huang,
K. (2021). A survey on smart agriculture: Development modes, technolo-
gies, and security and privacy challenges. IEEE/CAA Journal of Auto-
matica Sinica, 8(2), 273-302.
16 Patil, K. A., Kale, N. R. (2016, December). A model for smart agriculture
using IoT. In 2016 international conference on global trends in signal pro-
cessing, information computing and communication (ICGTSPICC) (pp.
543-545). IEEE.
16 Ayaz, M., Ammad-Uddin, M., Sharif, Z., Mansour, A., Aggoune, E. H. M.
(2019). Internet-of-Things (IoT)-based smart agriculture: Toward making
the fields talk. IEEE access, 7, 129551-129583.

17 Jayadeva, G. S., Shanmugasundaram, S., Sharath, N., Sanju, C., Sid-


halinga, S. M. (2021). Smart Agricultural Crop Prediction Using Machine
Learning. International Journal of Recent Advances in Multidisciplinary
Topics, 2(7), 144-147.
18 Wankhede, D. S. (2020, January). Analysis and prediction of soil nutrients
pH, N, P, K for crop using machine learning classifier: a review. In In-
ternational Conference on Mobile Computing and Sustainable Informatics
(pp. 111-121). Springer, Cham.
19 Sucharitha, V., Prakash, P., Ganesh Neelakanta, I. (2019). AgriFog-A Fog
Computing based IoT for Smart Agriculture. IJRTE, ISSN, 2277-3878.

20 IoT based Classification Techniques for Soil Content Analysis and Crop
Yield Prediction
21 Soil NPK and Moisture analysis using Wireless Sensor Networks

12
22 Kapse, S., Kale, S., Bhongade, S., Sangamnerkar, S., Gotmare, Y. (2020).
IOT Enable Soil Testing NPK Nutrient Detection. 9.
23 Patil, P., Panpatil, V., Kokate, S. (2020). Crop prediction system using
machine learning algorithms. Int. Res. J. Eng. Technol.(IRJET), 7(02).

13

You might also like