Automation in Irrigation using IoT and ML based Crop Recommendation System

DOI : 10.17577/IJERTV12IS030112

Download Full-Text PDF Cite this Publication

Text Only Version

Automation in Irrigation using IoT and ML based Crop Recommendation System

Aditya Gor

Dept. of Computer Science & Engineering Parul Institute of Engineering & Technology Vadodara, India

Rushil Togadiya

Dept. of Computer Science & Engineering

Parul Institute of Engineering & Technology Vadodara, India

Kandarp Joshi

Dept. of Computer Science & Engineering Parul Institute of Engineering & Technology Vadodara,India

Dr. Warish Patel

Dept. of Computer Science & Engineering

Parul Institute of Engineering &Technology Vadodara, India

AbstractAgriculture is a capital and labor intensive business in India. Today the people employed in this sector have to go through tremendous hardship, just to perform mundane tasks. One of these tasks is to supply water to the field for irrigation. Until very recently farmers had to manually turn on or turn off the motor which supplies water to field. This is an outdated practice and can be improved upon through the introduction of technology which enables the farmer to remotely operate the motor through his own device. Due to the advancement in sensing technology, we can design and implement a system that makes it easier to operate the motor remotely. The domain of data exchange and communication between electronic devices facilitated by the internet which is commonly known as Internet of Things (IoT), greatly help us bring to life the solution to the problem the farmers face by automating some manual tasks. In addition to that we can harness the real time data gathered from IoT systems for performing wide range of analytic tasks to get more insights. The crucial data acquired from the sensing devices can be used in Machine Learning models to give results that may impact future objectives. An example of this would be the data gathered live from the field can be used to recommend the most suitable crop togrow.

Keywords Agriculture, Automation, Internet of Things, Analytics, Machine Learning.

  1. INTRODUCTION

    Agriculture employs about 60 % of the Indian population [1], however it is appalling to observe that it is one of the few sectors that is least impacted by the innovations brought forward by technological advancement. One of the major prob- lems faced by people working in agriculture is the problem of switching on/off the motor used for supplying water to the field. Manually switching on/off the motor is both time consuming and needs constant supervision. It is possible to automate this process by using sensor and microcontroller. In our system we have gotten soil moisture data in real time from capacitive soil moisture sensor. This data is transmitted using WiFi enabled microcontroller that is Node MCU (ESP8266). This live data is stored in a MySQL database and displayed on

    a website that is locally hosted. Users can log in and view soil moisture readings taken frequently and opt to send a signal to the microcontroller to turn the motor on/off depending on the moisture values. The current motor status is displayed to the users. In addition to that, temperature and humidity sensors have also been connected with the microcontroller and their output displayed to the user on the website. The data acquired from the sensors through the microcontroller is also sent to third party analytics service so that real time graph plotting can be done via a webpage which shows live sensor value vs timestamp which is displayed to the user. Users can also download the live data captured in CSV (Comma Separated Values) format. The system also features a Machine Learning based crop recommendation system that is integrated into the main website. Upon giving the required environmental and soil parameters, the program recommends most suitable crop that could be grown by running a highly accurate Machine Learning Model. This helps the farmer to choose crops that may give maximum yield. As India is a huge country impacted by the vagaries of climate, appropriate crop selection becomes a question of utmost importance.

  2. LITERATURE REVIEW

    Ashwini proposes a Bluetooth based microcontroller system through which we can remotely operate a servo motor that is used in irrigation [2]. The system consists of an Arduino Microcontroller along with low cost temperature and humidity and soil moisture sensors which can keep track of change in temperature and humidity and soil moisture levels in real time, it also consists of an android application through which a user can view the status in real time. The user can set a threshold value for temperature, humidity and soil moisture below which a signal is sent from the users phone to the microcontroller which in turn signals the servo motor to rotate in order to provide water for irrigation. The decision to switch the motor on/off is automatic and does not involve the user however this

    can easily be converted to be manual. The values collected by the sensors can be stored and displayed to the user on his/her phone. The decision to switch the motor on/off is dependent on Na¨ve Bayes Algorithm which makes decision based on frequently occurring attribute not being zero.

    Anitha, Sampath & Jerlin propose a WiFi enabled system through which Temperature, Humidity and Soil Moisture val- ues are collected through Arduino [3]. Node MCU (ESP8266) is connected to Arduino for networking purpose. The values gathered by the sensors are sent to a third analytics service ThingSpeak which plots graphs in real time and is useful as data storage platform. This system also makes use for water level sensor which can be used to detect dampness in the soil . If soil moisture is low and water level sensor detects dampness then the Arduino module sends a signal through Node MCU to on the motor.

    Naik, Katti, Kumbi & Telkar propose an IoT system that collects temperature, humidity and soil moisture values with the help of DHT11 and Soil Moisture sensor and sends these values to an android application on the users phone using Arduino microcontroller [4]. When the Moisture level is less than some predetermined threshold value then the Arduino microcontroller sends a signal to the relay attached to it to switch the motor on. The user can view the motor status as well as temperature, humidity and soil moisture values in real time using an android application.

    Mishra, Khan, Tiwari & Upadhyay propose a system con- sisting of a soil moisture sensor and Arduino microcontroller [5]. The soil moisture sensor measures humidity present in the soil and if it is found to be less than some predetermined value then pump is turned on. The soil moisture value considered as threshold can be changed depending on the crop required to be produced.

    Rawal has proposed an IoT system consisting of soil mois- ture sensor, Arduino microcontroller and GSM GPRS module for internet connectivity [6]. In this system the soil moisture sensor collects soil moisture values in real time and posts this data on a webpage. If the soil moisture value recorded is less than some predetermined threshold value then the Arduino microcontroller sends a signal to the relay module to switch the motor on. If the moisture level has been the restored Arduino microcontroller sends a signal to turn the motor off. Soil moisture and motor status can be viewed on a webpage. Real time data is also transmitted to ThingSpeak server a third party analytics service for plotting of real time graphs.

    Doshi, Agarwal, Nadkarni & Shah propose a crop suitability system based on machine learning that intends to solve the problem of accurate crop selection given by environmetal parameters [7]. This system also includes a rainfall prediction system that is based on linear regression which predicts the amount of rainfall falling in the farmers district in every month of the year. The system makes use of Neural Networks as it was experimentally found to be the most accurate machine learning model for the crop suitability. The system takes input parameters soil type, aquifer, soil pH, soil characteristics and season. Based on these parameters the model is trained

    and appropriate crop recommendations are made. This system makes 20 different type of crop recommendation. It also shows the geographical area that is most suitable for growing the recommended crop.

    Vaishnavi, Shobana, Sabitha & Karthik propose a crop recommendation system that recommends a crop for particular season or year based on historical data about crop production [8]. In this system the authors analyzed the records of district wise production of crops and employed machine learning model to predict the best suitable crop for a particular year which may lead to maximum profit. For example it was found that in Coimbatore district of Tamil Nadu if the farmer decides to grow banana the chances of him incurring a loss is minimal. Jadhav, Riswadkar, Jadhav & Gogawale have proposed crop recommendation system based on machine learning that takes in environmental and soil parameters in the dataset as input and recommends the most suitable for that particular climate and soil [9]. The system makes use of Random Forest algorithm as it was found to be the most accurate with respect to other machine learning algorithms. The authors have also

    developed a web interface for using this system.

    Gosai, Raval, Nayak, Jayswal & Patel have proposed a crop recommendation system based on machine learning algorithms that recommends the best suitable crop depending on a variety of soil an environmental parameters [10]. The system takes soil and environmental factors as input and recommends crop by applying a particular machine learning model. In this system the authors have utilized Decision Tree, Na¨ve Bayes, SVM, Logistic Regression, RF and XGBoost. By training and testing the dataset on these algorithms it was found that XGBoost algorithm gave the most accurate result.

    Parikh, Jain, Gupta & Dabhade propose a machine learning system that recommends the best suitable crop to grow on the basis of a variety of soil and environmental parameters [11]. The model is trained and tested on a dataset consisting of the aforementioned parameters. Algorithm such as Support Vector Machines (SVM), Random Forest and Logistic Regression have been trained and tested on the dataset and their accuracies compared. Experimentally it was found that Random Forest algorithm gives the highest accuracy. Hence it was used in the application of the system.

  3. APPROACH

    The project consists of hardware circuit which has an ESP8266 microcontroller connected with DHT11 and Ca- pacitive Soil Moisture sensors. Both of these sensors are relatively inexpensive and provide fairly accurate values. The ESP8266 microcontroller also known as Node MCU is useful for enabling WiFi connectivity. Users can easily connect to the Node MCU via their mobile phone. Similarly they can connect their computer to the phone WiFi and hence data exchange and communication will be facilitated. The Node MCU transmits the command to switch on/off the motor through relay. As the data recorded from the sensors is stored in locally hosted database there is no additional cost to the user. The third party analytics service that is used in this project i.e. ThingSpeak

    limits the free tier version of its service to 3 million messages per year and message update interval time to 15 seconds [12]. The feature of downloading sensor data into a CSV format requires MS Excel or any other application that can read file stored in this format. The crop recommendation system here is built on top of open source technologies and does not require any additional cost, the modules and libraries can be installed freely from the internet without any licensing issues. In summary apart from ThingSpeak service (free version) used here for real time analytics all of the software used here is open source and free to use.

    1. UML Diagrams

      UML Diagrams explaining the flow of the project have been provided in Fig. 1 & Fig. 2.

      Fig. 2. Sequence Diagram

      • Humidity & Temperature sensor (DHT11 / DHT22).

      • Connecting wires and USB to micro USB cable.

        2) Software Requirements: The software requirements are mentioned below:

      • Arduino IDE.

      • Apache server.

      • MySQL database.

      • MS Excel, Google sheets or any other application to view CSV file.

      • Python libraries and modules for performing machine learning,

      • Web browser for running the web application.

    System has been tested on a Windows 11 PC with intel CORE i5 8th Gen processor and 8GB RAM.

  4. METHODOLOGY

    The project methodology has been given below:

    1. Node MCU connectivity

      Users have to first connect their mobile phone to the Node MCU. This is required to establish stable connection. Users should also have their device connected to their computer.

    2. Project Modules

    Fig. 1. Flowchart

    1. Data acquisition from sensors

      The values returned by the soil moisture sensor and DHT11 sensor in real time are sent to a locally hosted Apache server and are stored in MySQL database. The same data is also sent to third party analytics service ThingSpeak, in which a channel has been created to record and display real time change in

      The project consists of hardware and software modules which facilitate the smooth and error free functioning of the system. Libraries and dependencies are needed to be configured prior to running the project.

      1. Hardware Requirements: The hardware requirements are mentioned below:

        • Node MCU (ESP8266).

        • Soil Moisture sensor (Resistive / Capacitive).

        sensor values by plotting a value vs timestamp graph.

    2. Login page

      A login page has been created that needs user name and password for authentication. In order to login to the system to view the main webpage users need to provide their email ID as username and a 6 letter password. Authentication has been achieved by writing a code snippet in JavaScript.

    3. Sensor Data

      Fig. 3. Status page

      Fig. 5. Data Collection Dashboard

      The real time values stored in the database are being constantly updated and are displayed on an automatically updating web page. The web page shows data such as date and time, location and sensor values. This interface has been developed with HTML and CSS and PHP has been used in the backend to fetch data from the database. The web interface links to all the features provided by the system.

    4. Motor Status

    G. Export as CSV

    Fig. 6. Export as CSV page

    Fig. 4. Motor Status page

    If the user notices that the soil moisture level readings taken in real time are somehow less than what is predetermined than the user can click on motor status link which will take the user to a new page where he/she will be provided with a button through which an on command can be sent to the microcontroller. The microcontroller which receives the command can transmit it to a relay. The relay sends the signal to motor which is finally turned on. After sometime when moisture level has been restored the user can press the same button on the motor status webpage that could send an off signal to the microcontroller. The microcontroller passes this signal to the motor through relay and the motor is finally turned off.

    F. Data Collection Dashboard

    The data collection dashboard shows a webpage that dis- plays the frequently updating values from the ThingSpeak chanel. Users have not been granted direct access to ThingS- peak channel due to privacy and security concerns related to API keys.

    If the user wants to download a snapshot of the sensor readings taken during any particular time, he/she can do so by going to the export as CSV page here the sensor readings along with the timestamp (in GMT) have been made available. Uses can download the CSV file and open it by using an appropriate application like MS Excel or Google Sheets. This is useful if the user wants to run his/her own analytics locally such as generating descriptive statistics on the sensor data. This feature has been developed using Express.js and makes use of EJS for generating HTML markup.

    1. Crop Recommendation System

      Fig. 7. Crop Recommendation System

      A crop recommendation system has been developed which predicts the most suitable crop based on a variety of envi-

      ronmental and soil parameters. 22 different types of crops are recommended by this system. The parameters used in this system are Nitrogen, Phosphorus and Potassium content and pH value of the soil, Temperature, Humidity and average Rainfall in mm. Some of the data is collected i.e. Temperature and Humidity has been collected from the sensors earlier. NPK content and pH of the soil can be obtained from district wise government soil testing laboratory and average rainfall of every district can be obtained from Indian Meteorological De- partment (IMD) website. After satisfying the input constraints of the application, the program outputs the recommended crop after running a Machine Learning model. The model used in this application is K Nearest Neighbours, which gives a highly accurate result. This feature has been developed mainly using Python library Scikit-learn for machine learning tasks and PySimpleGUIWeb for user interface.

      KNN: It is a non-parametric method used for making predic- tions. In this, the predicted value is a class membership. The first step of the K-NN algorithm is to identify the k nearest neighbors for each incoming new instance. The instance is classified by a majority vote of these neighbors. In the second step, depending on the label sets of the k neighbors, a label is predicted for the new instance [13].

      1. Acquisition of dataset: The dataset acquired from https://www.kaggle.com/datasets/atharvaingle/crop- recommendation- dataset [14].

      2. Data Preprocessing: Removal of null values has been done in data preprocessing.

      3. Training & Testing: Training and testing by various machine learning models takes place. Here 75 % of the dataset is used for training the model while remaining 25 % is used for testing.

      4. Comparison of accuracies of various Machine Learning models: The accuracies of 5 different machine learning models has been compared, the result of which is shown in Fig. 9.

    Fig. 8. Accuracy comparison

  5. CONCLUSION & FUTURE WORK

  1. Conclusion

    In this paper we have proposed and implemented a WiFi enabled system consisting of a web interface through which farmers can remotely give command to turn on/off the motor

    based on the soil moisture readings captured live, tempera- ture and humidity data has also been recorded and stored in real time. The system also includes real time graphs to detect sudden or gradual change in sensor values. The option of downloading the sensor readings from the database has also been provided so that personalized analytics such as descriptive statistics can be done offline. Finally a crop recommendation system has been developed so that suitable crops can be recommended to the farmer based on pertinent environmental and soil parameters.

  2. Future Work

Future work may be undertaken to fully automate the whole motor switching part of the system based on some threshold value of the soil moisture provided. If the threshold value is less than some predetermined value then signal may be sent automatically to switch on the motor. Once moisture levels have been restored a signal to turn off the motor can also be sent. If NPK sensor and pH sensor is also added to the existing system then crop recommendation in real time can be achieved. A fertilizer recommendation system can developed by acquiring the required soil data. Yield prediction and crop profitability are also some noteworthy features that may be integrated with the existing system.

REFERENCES

[1] Agriculture in India – statistics & facts, available at https://www.statista.com/topics/4868/agricultural-sector-in-india/, visited in February 2023.

[2] Ashwini, B.V., Study on Smart Irrigation System Using IoT for Surveillance of Crop- Field, International Journal of Engineering & Technology (IJET), vol. 7, no. 4.5, 2018.

[3] Anitha, A; Sampath, Nithya & Jerlin, Asha, Smart Irrigation system using Internet of Things, 2020 International Conference on Emerging Trends in Information Technology and Engineering (ic-ETITE), Vellore, India.

[4] Naik, Pavankumar; Katti, Kirthishree; Kumbi, Arun & Telkar, Nagraj, Automation Of Irrigation System Using IoT, International Journal of Engineering and Manufacturing Science (IJEMS), vol. 8, no. 1, 2018.

[5] Mishra, Dweepayan; Khan, Arzeena; Tiwari, Rajeev & Upadhyay, Shuchi, Automated Irrigation System-IoT Based Approach, 3rd In- ternational Conference On Internet of Things: Smart Innovation and Usages (IoT-SIU), Bhimtal, India, 2018.

[6] Rawal, Srishti, IOT based Smart Irrigation System, International Journal of Computer Applications (IJCA), vol. 159, no. 8, 2017.

[7] Doshi, Zeel; Agarwal, Rashi; Nadkarni, Subhash & Shah, Neepa, Agro- Consultant: Intelligent Crop Recommendation System Using Machine Learning Algorithms, Fourth International Conference on Computing Communication Control and Automation (ICCUBEA), Pune, India, 2018.

[8] Vaishnavi, S; Shobana, M; Sabitha, R. & Karthik, S., Agricultural Crop Recommendations based on Productivity and Season, 7th Interna- tional Conference on Advanced Computing & Communication Systems (ICACCS), Coimbatore, India, 2021.

[9] Jadhav, Atharva; Riswadkar, Nihar; Jadhav, Pranay & Gogawale, Yash, Crop Recommendation System Using Machine Learning Algorithms, International Research Journal of Engineering and Technology (IRJET), vol. 9, no. 4, 2022.

[10] Gosai, Dhruvi; Raval, Chintan; Nayak, Rikin; Jayswal, Hardik & Patel, Axat, Crop Recommendation System using Machine Learning, Inter- national Journal of Scientific Research in Computer Science Engineering and Information Technology (IJSRCSEIT), vol. 7, no. 3, 2021.

[11] Parikh, Dhruv; Jain, Jugal; Gupta, Tanishq & Dabhade, Rishit, Machine Learning Based Crop Recommendation System, International Journal of Advanced Research in Science, Communication and Technology (IJARSCT), vol. 6, no. 1, 2021.

[12] ThingSpeak Licensing FAQ, available at https://thingspeak.com/pages/license faq, visited in February 2023.

[13] k-nearest neighbors algorithm-Wikipedia, available at https://en.wikipedia.org/wiki/K-nearest neighbors algorithm, visited in February 2023.

[14] Crop Recommendation Dataset, available at https://www.kaggle.com/datasets/atharvaingle/crop-recommendation- dataset, visited in February 2023.