Software Project

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

MULTIMEDIA UNIVERSITY OF KENYA FACULTY OF COMPUTING &

INFORMATION TECHNOLOGY

USING MACHINE LEARNING AND IOT IN AGRICULTURE TO IMPROVE


YIELDS AND MINIMIZE WASTAGES

A PROJECT BY
TULEL YEGO JUDE
CIT-227-023/2021

UNDER THE SUPERVISION OF:


YVETTE OTUKANA

List of Abbreviations
IoT - Internet of Things

IOT - Internet of Things (alternative capitalization)

Wi-Fi - Wireless Fidelity


MALF - Ministry of Agriculture Lands and Fisheries

GoK - Government of Kenya

AI - Artificial Intelligence

pH - Potential of Hydrogen

Firebase - A cloud-based platform

GPS - Global Positioning System


Abstract

Agriculture is the basic economic activity for many nations and Kenya is no exception. With

the population of Kenya expanding so rapidly, the agricultural output must increase to meet

this demand. However, agriculture in Kenya is still lowly mechanized and there is room for

technology enter this sector.

My project Aims to streamline the process of agricultural production by reducing if not

minimizing all wastage of inputs for instance irrigation water and fertilizer, it also aims to put

idle arable land to use. By keeping crops at optimum conditions, I hope this project will

improve agricultural yields and as a result bolster food security in the nation.

Maintaining crops at optimum conditions can be achieved by means of IOT devices that

gather information through sensors and communicate over Wi-Fi to a gateway that uploads

this data to a cloud server (firebase real time database) and this information can be viewed on

a mobile application. The mobile application will have module which land owners can rent

arable land so there can be a reduction of idle lands.


Table of Contents
CHAPTER 1 INTRODUCTION...............................................................................................6
1.1 Background of the study...................................................................................................6
1.2 Problem statement............................................................................................................7
1.2.1 Proposed solution.......................................................................................................7
1.3 Aim of the project.............................................................................................................8
1.4 Research Objectives.........................................................................................................8
CHAPTER 2: LITRATURE REVIEW......................................................................................9
2.1 Introduction......................................................................................................................9
2.2 Related systems................................................................................................................9
2.3 Limitations of related systems.....................................................................................12
2.4 How yagriculture will address these issues................................................................12
CHAPTER 3 – METHODOLOGY.........................................................................................13
3.1 INTRODUCTION..........................................................................................................13
3.2 Data collections Methods and tools................................................................................13
3.3 Project resources.............................................................................................................13
CHAPTER 4 SYSTEM ANALYSIS...................................................................................13
4.1 System models................................................................................................................14
4.1.1 Context Diagram......................................................................................................14
4.1.2 Interaction models....................................................................................................15
4.2 Requirements..............................................................................................................17
CHAPTER 5 SYSTEM MODEL.............................................................................................19
The Model:...........................................................................................................................19
The View:.............................................................................................................................19
The Controller:.....................................................................................................................19
CHAPTER 6 IMPLEMENTATION........................................................................................20
6.1 Development Environment.............................................................................................20
6.1 System components........................................................................................................20
CHAPTER 7: CONCLUSION.................................................................................................22
7.1 Achievements.................................................................................................................22
7.2 Lessons Learned.............................................................................................................22
7.3 Conclusions....................................................................................................................22
7.4 Recommendations..........................................................................................................22
List of figures
Figure 1 ESP32 WiFi gateway.................................................................................................10
Figure 2 Sensor module...........................................................................................................10
Figure 3 Yara Agriculture App................................................................................................11
Figure 4 Level 0 Context Diagram...........................................................................................14
Figure 5 User sign Up..............................................................................................................15
Figure 6 User login...................................................................................................................16
Figure 7 User get recommendation..........................................................................................17
CHAPTER 1 INTRODUCTION
1.1 Background of the study
Arable land is a limited resource hence the need to manage it effectively In Kenya, the
percentage of arable land (land suitable for agriculture) is approximately 10.19% of the total
land area as of 20211. This means that out of Kenya’s vast expanse, only a relatively small
portion is suitable for cultivation.

To put it in perspective, Kenya had nearly 28 million hectares of agricultural land in 2019,
which corresponds to over 48% of the country’s total land area2. However, not all of this land
is arable; some areas are used for grazing, forests, or other purposes.

Despite the limited arable land, Kenya has made significant strides in agriculture, with a
focus on sustainable practices and crop diversification. Farmers in Kenya cultivate a variety
of crops, including maize, tea, coffee, sugarcane, and horticultural products. Efforts are also
being made to improve soil fertility, irrigation systems, and crop yields.

Though percentage of arable land may seem small, it plays a pivotal role in supporting
livelihoods, food security, and economic development in Kenyans. That is why it is important
to optimize the use of this valuable resource.

Another challenge is the access to capital for agricultural projects. Banks and other lenders
classify agriculture as high risk due to its dependence on weather conditions this impedes
development in the sector especially where capital intensive project like irrigation which are
sure to pay dividends are foregone for the lack of capital.

Irrigation is widely recognized by both private and public actors as a key means to improve
food security and livelihoods and foster agricultural transformation in Kenya. The technology
is accordingly part of several recent visions and strategies, including Kenya's Vision 2030,
the BIG4Agenda, and the Agricultural Sector Transformation and Growth Strategy (Ministry
of Agriculture Lands and Fisheries-MALF- 2019). Irrigation is also seen as a technology for
reducing vulnerability to climate change (MALF 2017; GoK 2013; 2010). Hence, efforts to
develop irrigation in Kenya are likely to receive support from a broad range of stakeholders.

Irrigation has a big environmental footprint if too much water is drawn from a source it is
therefore prudent to manage water resources effectively

Soil forms the basis of agriculture as it retains and supplies water and nutrients for plant
growth, is a critical supplier for nutrient such as potassium, nitrogen and phosphorus.
In the words of Francis Tetteh, Ghana Soil Information Service (GhaSIS) “Soil is
fundamental to life, yet for a long time, soil information in Africa has been incomplete and
inadequate for proper agricultural and scientific use.”

Soil data is important not only to largescale but also to small-scale farmers and other
stakeholders in the sector such as governments. It informs decisions on fertilizer application
and pH management.

1.2 Problem statement


There is need to integrate Internet of Things and Artificial Intelligence into agriculture to
improve yields to meet the needs of the ever growing population

1.2.1 Proposed solution


The solution can be split to the following segments

Sensor Deployment (IoT):

 Install soil sensors in the farmland to measure nutrient levels (such as nitrogen,
phosphorus, and potassium) and moisture content. These sensors can be buried in the
soil or placed at different depths.

 Connect the sensors to a central gateway (IoT device) and using wireless protocols
upload the data to the cloud

Data Collection and Storage (IoT):

 Set up a cloud-based firebase real-time database to receive and store sensor data.

 The cloud platform should handle data ingestion, authentication, and security.

Data Analysis

 Using classification algorithms to classify the soils and give crop and fertilizer
recommendations to farmers.

Mobile application

 Using a mobile app serve the sensor data via dashboards to the farmer
 The farmer if in need of capital can also be funded by other users of the app and a
contract on profit sharing drawn up.
 The app also gives fertilizer recommendations based on the data received

1.3 Aim of the project


This project aims to collect data on soil nutrient and moisture content and via a mobile
application advice the farmer on the best course of action to take based on the data.

1.4 Research Objectives


 To design and implement an IoT-based system that can monitor and control soil
nutritive metrics (such as moisture, temperature, pH, and nutrients) and provide real-
time data to farmers via a mobile app.

 To develop and deploy a machine learning model that can analyse soil data and
recommend suitable crops and fertilizers based on soil characteristics and crop
requirements.

 To create and integrate a module in the mobile app that can enable landowners to rent
out their idle arable land to potential farmers and facilitate transactions and
agreements.

 To evaluate the performance and impact of the IoT-based system on crop yield,
quality, and profitability, as well as on water and fertilizer consumption and
environmental impact.

 To disseminate the project results and findings to relevant stakeholders and promote
the adoption of smart agriculture practices in Kenya.
CHAPTER 2: LITRATURE REVIEW
2.1 Introduction
Data from previous census has shown that the Kenyan population has experienced significant

growth over the years. During the 2019 census, the population was reported to be 47.6

million, compared to 38.6 million inhabitants in 2009, 30.7 million in 1999, 21.4 million in

1989, and 15.3 million in 1979. This increase has led to the need to increase agricultural

output while still utilizing the already scarce resources.

This is where technology comes in to boost up production previous work has been done on

IOT application in agriculture and they have shown great promise.

2.2 Related systems

IoT in Agriculture

IoT technology has been increasingly adopted in agriculture for real-time monitoring and

management of various agricultural parameters. Wankhede (2021) highlights the utilization

of IoT devices, such as soil sensors deployed in farmlands, to measure nutrient levels and

moisture content. These sensors, when connected to central gateways and cloud-based

platforms, enable continuous data collection and storage, facilitating informed decision-

making for farmers regarding irrigation, fertilization, and crop management.

Soil Nutrient Monitoring

The significance of soil nutrient monitoring in agriculture cannot be overstated, as soil health

directly impacts crop growth and yield. IoT-based soil nutrient monitoring systems, as
demonstrated by Santos (2024) and How To Electronics (2023), demonstrated how soil

characteristics such as moisture, temperature, pH, and nutrient levels can be measured.

Figure 1 ESP32 WiFi gateway

Figure 2 Sensor module


These systems employ sensors capable of real-time data collection, which is then transmitted

to cloud databases for storage.


AI for Crop Recommendation

AI and machine learning algorithms play a crucial role in analyzing soil data and providing

tailored recommendations to farmers regarding crop selection and fertilizer application.

Wankhede (2021) emphasizes the development and deployment of machine learning models

for analyzing soil nutrient data and generating crop-specific recommendations based on soil

characteristics and crop requirements. Such AI-driven systems enable farmers to optimize

crop yields while minimizing resource usage and environmental impact.

Yara Agriculture (Mobile Applications for Farmer Decision Support)

Figure 3 Yara Agriculture App


Mobile applications serve as indispensable tools for delivering actionable insights to farmers

and facilitating communication and collaboration within the agricultural ecosystem.

Yara ariculture is an app developed by the fertilizer giant yara it offers fertilizer

recommendations based on locations. It also include a weather information.


2.3 Limitations of related systems
 The lack implementation of IoT, precision agriculture, and other advanced
technologies to make customised user info as in the case of yara agriculture.
 Where IoT is implemented AI recommendation based on sensor data is not
implemented as with the case of IoT-based soil nutrient monitoring systems, as
demonstrated by Santos (2024) and How To Electronics (2023).

2.4 How yagriculture will address these issues


 By integrating IoT data with mobile application to give farmers customised
recommendations based on the nutritive content of their soil.
 A machine learning algorithm to classify soils and offer fertilizer and crop
recommendation.
CHAPTER 3 – METHODOLOGY
3.1 INTRODUCTION
This project aims to bring IoT and ML technologies to the Kenyan farmer and leverage its
data collection and processing ability to serve farmers with customised recommendations.
This will take out all the guess work when it comes to agricultural production.
3.2 Data collections Methods and tools
Interviews
Face to face discussions with farmers in West Pokot County yielded a consensus that an app
that could prescribe agricultural inputs and recommend crops to grow would be amazing.
Interview was a good approach as I was able to gather from the enthusiasm of the
respondents that such an idea would be welcome.
Context Analysis
Context Analysis was used in cases of wanting to find if there are any related systems built.
A lot of work has been done on IoT in agriculture coupled with ml models for soil
classification by studying the works referenced I was able to get a deeper understanding of
IoT Systems and Machine Learning algorithims.
3.3 Project resources
The table below shows
Table 1. Resource against Function

Resource Function
Laptop -Used for development of ML models
-Programming of the ESP32 module
-Coding the mobile application
ESP32 DevModule -Interface with sensors providing them with
power and capturing their readings
-Send sensor data to server

Android Phone -Used for debugging the app during


development

Sensors -DSB temperature sensor


(Mesures Temprature)
-Resistive Moisture Sensor
(Mesures Moisture)
-NPK sensor
(Mesures N,P,K values)

CHAPTER 4 SYSTEM ANALYSIS


The yagriculture app utilizes cloud infrastructure to capture and store real-time sensor data
and the Machine learning model is also hosted on the Google Cloud Platform
4.1 System models
The models in this system are designed on draw.io. I included the context diagram [level 0],
the sequence diagrams, and the class diagrams.

4.1.1 Context Diagram

Crop and
fertilizer
reccomendation

Environment
data

Figure 4 Level 0 Context Diagram


4.1.2 Interaction models
Shows key scenarios and user stories in sequence diagrams.

4.1.1.2.1 User Registration


The user needs to register to get a one-time account through which they will be allowed
access to the services offered.

Figure 5 User sign Up


4.1.1.2.1 User Login

Figure 6 User login


4.1.1.2.1 User Read sensor data and get recommendation

Recommendations

Figure 7 User get recommendation

4.2 Requirements
Functional Requirements:
1. Sensor Integration: The system should integrate various sensors such as moisture
sensors, temperature sensors, and nutrient sensors to monitor the conditions of the
crops and soil.
2. Data Collection and Transmission: It should collect data from the sensors and
transmit it wirelessly to a central gateway using Wi-Fi connectivity.
3. Cloud Storage: The system should utilize a cloud-based storage solution (e.g.,
Firebase Realtime Database) to store the collected data securely.
4. Real-time Monitoring: Users should be able to monitor the status of their crops and
soil in real-time through a mobile application.
5. Alerts and Notifications: The system should send alerts and notifications to users in
case of any abnormalities detected in the crop or soil conditions.
Non-functional requirements
1. Reliability: The system should be highly reliable, ensuring minimal downtime and
accurate data collection.
2. Scalability: It should be scalable to accommodate a growing number of users and
devices as the project expands.
3. Security: Data transmission and storage should be encrypted to ensure the security
and privacy of users' information.
4. Usability: The mobile application interface should be intuitive and user-friendly,
catering to users with varying levels of technological proficiency.
5. Performance: The system should have low latency in data transmission and
processing to provide real-time monitoring and response.
6. Compatibility: The mobile application should be compatible with a wide range of
devices and operating systems to maximize accessibility for users.
7. Cost-effectiveness: The implementation and maintenance costs should be optimized
to ensure the project's sustainability and affordability for users
CHAPTER 5 SYSTEM MODEL
The Model:
In this context, the Model encompasses the data related to agricultural activities, including
information about crops, soil conditions, irrigation, fertilization, and land availability. It
interacts with external systems through APIs to securely access data from various sources
such as sensors, IoT devices, and cloud servers. For example, it retrieves data about crop
growth, soil moisture levels, and weather conditions from IoT devices via Wi-Fi connectivity.
Additionally, it may obtain information about land availability and rental options from
external databases or services. The Model ensures the integrity and security of the
agricultural data and facilitates seamless communication between different components of the
system.

The View:
The View component is responsible for presenting agricultural data and functionalities to
users through the mobile application interface. It provides users with access to various
features, including viewing crop and soil data, monitoring irrigation and fertilization
processes, and exploring available land for rent. The View components present query results
to users in a clear and user-friendly manner, allowing them to easily interpret and analyse
agricultural information. Users can interact with the View to access relevant data about their
agricultural activities and make informed decisions to optimize crop production and land
utilization.

The Controller:
The Controller acts as the backbone of the system, orchestrating the flow of data and actions
between the Model and the View. It handles user interactions and inputs, processing requests
for data retrieval, data entry, validation, and authorization. For example, when a user submits
a request to view crop statistics or rent arable land, the Controller coordinates with the Model
to fetch the necessary data and communicates with the View to present the information to the
user. The Controller ensures smooth communication between different system components,
facilitating a seamless user experience and ensuring customer satisfaction.
CHAPTER 6 IMPLEMENTATION
6.1 Development Environment
The implementation of the agricultural management system described in the abstract
leveraged a combination of technologies to ensure efficiency and effectiveness. The primary
development tools used were React Native for mobile application development, Flask for
hosting the machine learning API, and Firebase Realtime Database for data storage and
synchronization.
React Native served as the framework for developing the mobile application, providing a
robust platform for building cross-platform applications with a native look and feel. Its
extensive library of components and straightforward syntax facilitated rapid development and
deployment of the application.
The machine learning (ML) functionality of the system was implemented using Flask, a
lightweight web framework for Python. Flask allowed for the creation of RESTful APIs to
serve ML models, enabling the mobile application to interact with the ML functionality
seamlessly.
Firebase Realtime Database played a central role in managing and storing data related to
agricultural activities. Its real-time synchronization capabilities ensured that data updates
were reflected instantly across all devices, providing users with up-to-date information about
soil moisture and nutrient levels.
6.1 System components
1. Mobile Application: This is the primary interface through which users interact with
the system. It is developed using React Native and provides functionalities such as:
 Viewing soil data collected from sensors.
 Monitoring irrigation and fertilization processes.
 Renting arable land.
 Interacting with the machine learning features hosted on the Flask API.
2. Machine Learning API (Flask): This component hosts the machine learning models
responsible for analyzing agricultural data and providing insights or recommendations
to users. It exposes endpoints that allow the mobile application to send data for
analysis and receive predictions or recommendations in return. The Flask API handles
requests from the mobile application and processes them using the ML models before
sending back the results.
3. Firebase Realtime Database: This serves as the backend database for the system,
storing and synchronizing data related to agricultural activities. It stores information
such as crop growth data, soil moisture levels, irrigation schedules, user profiles, and
land rental details. The Firebase Realtime Database ensures real-time synchronization
of data across all devices, providing users with up-to-date information at all times.
4. IoT Devices and Sensors: These devices are deployed in the field to collect data on
various parameters such as soil moisture, temperature, Nitrogen Phosphorus and
Potassium. The sensors gather real-time data from the agricultural environment and
transmit it wirelessly to the system for analysis and monitoring. The data collected by
IoT devices is crucial for making informed decisions about irrigation, fertilization,
and crop management.
CHAPTER 7: CONCLUSION
7.1 Achievements
● A Farmer is able to create an account and log on to the application.
● A Farmer is able to add their field and register the sensors used on it.
● I was able to create Machine learning APIs and used dummy for the testing process.
● I configured the APIs for 2 bank systems to be used on the unified bank system
7.2 Lessons Learned
To efficiently share data across IoT devices Machine learning API the data has to be
marshalled to a form ingestible by all system components. JSON proved to be right for the
job as it is supported by nearly all platforms.
7.3 Conclusions
A centralized platform collecting live farm data and giving recommendations might what
Kenya needs to boost agricultural output.
7.4 Recommendations
There is need to invest in locally situated servers so as to prevent overreliance on google
cloud platform. This will help in preventing vendor lock in a situation where we are tied
down to google.
REFRENCES
Rui Santos. (2024, February 8). ESP32: Getting Started with Firebase (Realtime Database) 1.
Random Nerd Tutorials. https://randomnerdtutorials.com/esp32-firebase-realtime-database/

IoT Based Soil Nutrient Monitoring with Arduino & ESP3212. How To Electronics, 9 Sep. 2023,
https://how2electronics.com/iot-based-soil-nutrient-monitoring-with-arduino-esp32/. Accessed
8 Feb. 2024.

Wankhede, D. S. (2021). Analysis and prediction of soil nutrients pH,N,P,K for crop using machine
learning classifier: A review. In J. S. Raj (Ed.), International Conference on Mobile Computing and
Sustainable Informatics (pp. 111-122). Springer Nature. https://doi.org/10.1007/978-3-030-49795-
8_10

Meola, A. (2021, February 2). Smart farming in 2020: How IoT sensors are creating a more
efficient precision agriculture industry. Business Insider1
1
: https://www.businessinsider.com/smart-farming-iot-agriculture?r=US&IR=T

https://tradingeconomics.com/kenya/arable-land-percent-of-land-area-wb-data.html
https://tradingeconomics.com/kenya/arable-land-percent-of-land-area-wb-data.html

S. Sivakumar, V. Anuratha, and S. Gunasekaran, “Survey on Integration of Cloud Computing


and Internet of Things Using Application Perspective”, International

You might also like