Al Neelain University Graduate College M. Sc. Research in Electronic Engineering (Embedded Systems) Irrigation System via WiFi By: Dhuha Ismail Elazhary. Supervisor: Prof. Amin Babiker Abd El-Nabi. October 2020 i ــالآي ة ــــــ ى * وَأَنا سَعْيَهُ سَوْفَ يُرَى * ثُما يُجْزَاهُ الْجَزَاءَ الَْْوْفَىسَانِ إِلَّا مَا سَعَ وَأَنْ لَيْسَ لِلِْْنْ النجم سورة ii Acknowledgment with respect, I can only thank the supervisor of this project, Professor Amin Babiker Abd El-Nabi, for his patience and guidance. And thanks and gratitude to the family, friends and everyone who contributed and support to presented this work. I ask God to help us and grant them success. iii المستخلص إنعدام سبل الحياة في تلك المناطق , ووجود مصدر ثابت الماء هو المصدر الْساسي للحياة , إنعدام الماء يعني العذبة والجوفية , فلابد للمياه يساعد البشرية في عدة أصعدة الصعيد الإقتصادي والزراعي , يتميز السودان بتوفر المياة من الَّقتصاد في استهلاك هذه المياة وتوفيرها للمناطق ذات ندرة في المياه . الى المزارع بأقل التكاليف والحصول على أعلى عائد للمحصول عن التحكم في ضخ المياة يقوم هذا المشروع في ادر على مراقبة منسوب المياه والحفاظ على رطوبة طريق فتح وغلق الموتور المسؤول من ضخ المياه , فيكون المستخدم ق , وايضا قلل من المجهود المبذول في عملية الري . التربة راقب البيانات المرسلة من المزرعة ويعطي فرصة للمزارع بفتح وغلق تطبيق أندرويد ي يتكون المشروع من من المحصول . قدرةلحصول على أفضل المضخة في اي وقت . كما يزود المستخدم بعض الإقتراحات للمساعدة ل إلى تطبيق WiFiلمعالجة البايانات وإرسالها عن طريق Esp8266-12يستخدم مستشعر لرطوبة التربة متصل مع الْندرويد ليقوم المستخدم عن طريقه بالتحكم في المضخة ومراقبة رطوبة النباتات . بهذه الطريقة إستطاع المستخدم من أو النباتات بصورة منتظمة وبأقل مجهود , والْقتصاد في استهلاك المياه . ضمان ري المحصول iv Abstract Water is the main source of life, the lack of water means the lack of ways to life in those areas, and the presence of a stable source of water that helps humanity in several economic and agricultural levels, Sudan is characterized by the availability of fresh and groundwater, so it is necessary to economize in the consumption of this water and provide it to areas with scarcity of water. This project is based on controlling the pumping of water to the farms at the lowest costs and obtaining the highest yield of the crop by opening and closing the motor responsible for pumping the water, so that the user is able to monitor the water level and maintain the appropriate moisture for the soil, and also reduce the effort expended in the irrigation process. The project consists of an Android application that monitors the data sent from the farm and gives the farmer an opportunity to open and close the pump at any time. The user also provides some suggestions to help get the best capacity from the crop. A soil moisture sensor connected to the Esp8266-12 is used to process the data and send it via WiFi to the Android app so that the user can control the pump and monitor the plant's moisture through it. In this way, the user was able to ensure that the crop or plants were irrigated regularly and with minimal effort, and that water was saved. v CONTENTS ـــة ــ I..………………………………...…………………………………………………………الآيـــ ACKNOWLEDGMENT ............................................................................................... II III.……………………………………………………………………………………المستخلص ABSTRACT…………………………………………………………………………………. IV CONTENTS……………………………………………………………………….….………V TABLE OF FIGURES ............................................................................................. .VIII CHAPTER 1: INTRODUCTION ……………………………………………………………..1 1.1 INTRODUCTION .. ………………………………………………….……………………2 1.2 TYPES OF IRRIGATION:……………………………………...…….…………….……..2 1.3 IRRIGATION METHODS:……………………………...………………………………..2 1.4 PROBLEM:…………………………………………...……………………………...........3 1.5 OBJECTIVE:…………………………...…………………………………………………3 1.6METHODOLOGY:……………………………………………………….………………..3 CHAPTER 2: LITERATURE REVIEW……………………………………………………....4 2.1 INTRODUCTION:…………………………………...…………….……………………...5 2.1.1 IRRIGATION……………………………………………………………………………5 2.1.2 THE EFFECT OF IRRIGATION ON THE CROP:………………..…………………….5 2.1.3 WIFI…………………………………………………………………………………….6 vi 2.1.4 THE NATURE OF WIFI WORKS……………………………….….…………………..6 2.1.5 IP-ADDRESS:…………………………………………………………………………...7 2.1.6 HOW AN IP-ADDRESS WORKS………………………………………………………7 2.1.7 TYPES OF IP-ADDRESS……………………………………………………………….7 2.1.8 TCP PROTOCOL………………………………………………………………………..8 2.1.9 ANDROID OS…………………………………………………………………………...8 2.1.10 FEATURES OF ANDROID:………………………………….………………………..9 2.2 LITERATURE REVIEW:…………………………………...……………………………9 CHAPTER 3: METHODOLOGY …………………………………………………………...11 3.1INTRODUCTION:…………………………………………………………………….….12 3.2PROJECT NEEDS:…………………………………………………………….…………13 3.2.1INSTALL THE FOLLOWING:…………………………………………….………….13 3.2.2PREREQUISITES:…………………………………………………………….………..13 3.3 DEFINITIONS OF PREREQUISITES:…………………………………...….………….13 3.3.1 ESP8266-12E:………………………………………………………………………….13 3.3.2 5MM LED:……………………………………………………………………………..15 3.3.3 SOIL MOISTURE SENSOR FC-28:.………………………………………….……….15 3.3.4 BREADBOARD……………………….……………………………………………….16 3.4 PROJECT STEPS:………………………………………………………………………..17 3.5 INSTALLING ANDROID STUDIO V4………………………………………………...17 3.6 ESP8266 SIDE:……………………………...…………………………………………...22 vii 3.7 CIRCUIT DIAGRAM:……………………………………………….…...……………...26 CHAPTER 4: RESULTS & DISCUSSION…………………………………………………..27 4.1 RESULT:……………………………………………………….………...………………28 4.2 DISCUSSION:………………………………………………….……………..…………32 CHAPTER 5: CONCLUSIONS & RECOMMENDATIONS………………………………..35 5.1 CONCLUSION:………………………………………….…………………………...….36 5.2 RECOMMENDATION………………………………………………………………….37 REFERENCES……………………………………………………………………………….38 viii Table of figures FIGURE 1: ANDROID FEATURES ................................................................................... 9 FIGURE 2: BLOCK DIAGRAM OF THE SYSTEM ............................................................... 13 FIGURE 3: ESP8266-12E DATASHEET ....................................................................... 14 FIGURE 4: LED .......................................................................................................... 15 FIGURE 5: SOIL MOISTURE SENSOR FC-28 .................................................................. 15 FIGURE 6: BREADBOARD ........................................................................................... 16 FIGURE 7: CIRCUIT DIAGRAM .................................................................................... 26 1 CHAPTER 1: INTRODUCTION 2 Chapter 1 Introduction 1.1 Introduction Life goes on fast, and the world, like the small village, becomes more accessible after Internet access and wireless communication. This development included the world of electronics, which has witnessed a remarkable development in the past decade, the connection of smart devices to the network and control through the network. Water is the main reason for the survival of creatures, and people in the past relied on living in areas close to water sources for easy access for drinking and agriculture purposes, but with the development and the increase in population need to expand and move to drier areas. Here came the need to search for ways to easily pump water to reach these areas. One of these systems is the irrigation system, where the traditional methods used consume water and may be caused by the corruption of the crop either to increase or decrease water in addition to the loss of flexibility in controlling the orders given to the agency. In this research, I will propose a means to reduce water consumption, facilitate control over farms and reduce crop corruption. 1.2 Types of irrigation: 1. Natural irrigation It is the watering of plants without human interference and totally dependence on nature, such as rain, floods, or agriculture on the banks of rivers [15]. 2. Industrial irrigation It depends entirely on the interference of the human hand, using one of the most common irrigation methods [15]. 1.3 Irrigation methods: 1. Surface irrigation Water is pumped onto the surface of the soil. This method is preferred on flat lands, and it was chosen in this project due to its low cost types [16]. 2. Sprinkler irrigation The farmer installs water sprinklers that simulate rain, is characterized by homogeneity of irrigation throughout the basin [16]. 3 3. Drip irrigation It is considered one of the best irrigation methods suitable for all types of soil and all weather conditions, it reduces the growth of weeds around the plant, and maintains the required amount of water around the plants as it is of high cost [16]. 1.4 Problem: In countries like Sudan, they need to control the amount of water flowing to agricultural lands has passed. On the other hand, this water must be provided and pumped to areas where fresh water resources are scarce. Taking into account the preservation of water by using the least amount of it for irrigation without disturbing the plants 1.5 Objective: This project, provides the user with knowledge of the appropriate humidity of the soil in addition to reducing the effort exerted and reducing manpower. The farmer needs to control the amount of water flowing to the farm in order to obtain a high produce of the crop and preserve the amount of water, but the farmer finds it difficult to determine the appropriate amount of water for this crop. On the other hand Saving water and use it when needed, or deliver it to places most in need of irrigation. 1.6 Methodology: This project works to allow easy control of the flow of water to the farm while monitoring the moisture appropriate to the crop, using a soil moisture sensor and a motor to control the water pumping, all of this is done through an application on a mobile phone so the user can follow the status of the farm at any time. 4 CHAPTER 2: LITERATURE REVIEW 5 Chapter 2 Literature review 2.1 Introduction: 2.1.1 Irrigation "Irrigation, as it is known, is the addition of water to the soil in order to increase its moisture, as well as for the growth of various plants and crops. The methods used for irrigation of crops differ, some of which depend on irrigation with rainwater and irrigation using drip and spraying"[20]. The importance of irrigation Represented in: 1. Increasing soil fertility and thus giving plants the opportunity to absorb the basic elements necessary for their growth[20]. 2. Helps the soil get rid of harmful salts and substances[20]. 3. The soil helps stimulate the action of bacteria that aid in the growth of plants[20]. 4. Increase the percentage of production of agricultural crops[20]. 5. Eliminates agricultural pests[20]. "Irrigation is concerned with supplying agricultural areas with water necessary for agricultural uses, so water acts as the causative agent of nutrients, as it helps the activity of soil bacteria that work on analyzing organic matter and conserving soil temperature"[20]. 2.1.2 The effect of irrigation on the crop: Based on the research and published papers on the importance of irrigation, it was found that irrigation helps to increase the crop in different and noticeable degrees. Innovations in irrigation infrastructure have allowed humans to use previously inaccessible water resources, increasing water withdrawals for agriculture while increasing pressure on environmental flows and other human uses[21]. Crop production depends on water received from rain "green water" and irrigation of "blue water" from water bodies and aquifers. Through irrigation it is possible to reduce the exposure of crops to water stress, thus enhancing productivity and increasing worker profits[21]. The crop may increase or decrease depending on the amount of available water, for example the tomato plant needs water in large quantities, and when the amount of water is decreased, the roots take water from the fruit, which leads to the small size of the fruit, so the fruits cannot store water in the appropriate quantity and thus the inability to form carbohydrates and 6 proteins. While onions and potatoes produce early crops, it was observed that these early bulbs were not irrigated except with rainwater[22]. There is what is known as the critical period for plant growth, in this period the process of cell division inside the plant is rapid. This period varies from one plant to another. In a plant like tomato, its critical period is at the time of flowering, so it is not preferable for plants to thrive during this critical period. Irrigation is a key element for crop success in the dry and semi-arid regions, and it keeps plants from drying out[22]. 2.1.3 WiFi "WiFi is an acronym for Wireless Fidelity, which is a type of wireless technology, and a wireless network protocol that allows devices to connect to the Internet without need for Internet wires, and it is one of the most popular means of wirelessly transmitting data in a fixed location, and it is a trademark of the Wi-Fi Alliance, which is an international association of companies working in the field of wireless LAN technologies and products, and it operates at 2.4 GHz or 5 GHz wire frequencies ensures that cell phones broadcast radio, TV antenna, or two-way radios are not interfered with during the transmission process[19]. Wi-Fi technology is one of the technologies that work over long distances, and is longer than Bluetooth, or infrared, and it is low energy, so it is suitable for mobile devices"[19]. 2.1.4 The nature of WiFi works "The wireless network uses radio waves just like mobile phones, television, and radios. In fact, wireless communications are similar to two-way radio communications devices" [18]. "The wireless device connected to the computer performs the function of converting the data into a radio signal sends through a special antenna, the wireless router receives this signal and encrypts it, then it sends it to the Internet using an Ethernet connection. Information can be sent over 3 different frequency bands or by using frequency hop technology between the three different frequencies, the frequency navigation technology helps reduce the interference that causes a group of devices to use wireless communication at the same moment, this process works the other way around as the router receives information from the Internet, translates and converts into a radio signal and sends to the computer via the wireless device connected to it"[18]. " It should be clarified here that the WiFi radios have some characteristics that distinguish them from the rest of the radio waves used in other devices" [18]. 7 and these are: 1. The information is sent at 2.4GHz or 5GHz frequency. These high frequencies allow to download a larger amount of information, as the higher the frequency of the used wave, the greater value of the bandwidth, which allows downloading a larger amount of data[18]. 2. Wi-Fi uses 802.11 network standards, and it has several forms, including 802.11b, 802.11g, and 802.11a, and the last uses a system known as OFDM, an abbreviation for orthogonal frequency-division multiplexing, which helps separate the radio signal into several branches before it reaches the future and this technology it greatly reduces the interference that can occur due to the large number of devices running on the same network[18]. 3. In Wi-Fi, information can be sent over 3 different frequency bands or by using the frequency hop technology between the three different frequencies. The frequency hopping technology helps reduce the interference that causes a group of devices to use wireless communication at the same time[18]. Note: The name relationship WiFi to the network 802.11. In fact, this figure is from the IEEE (Institute of Electrical and Electronics Engineers). As this institution sets standards for the use of radio frequencies for a group of technologies and encodes them with numbers to classify them"[18]. 2.1.5 IP-address: It is an acronym for Internet Protocol, and it is a personal address for every computer device, and through it can communicates with other computers. without this IP-address, the computer cannot communicate with any other computer or mobile device, even via Wi-Fi or the Internet. 2.1.6 How an IP-address works "An IP address allows computers to send and receive data over the internet. Most IP addresses are purely numerical, but as internet usage grows, letters have been added to some addresses"[23]. 2.1.7 Types of IP-address 1. IP version 4 (IPv4): 32 bits long, It is most commonly used and given to most computer devices [24]. 2. IP version 6 (IPv6): 8 128 bits long, "will be used for the foreseeable future; however there will be a transition from IPv4 to IPv6. Although these two protocols cannot interact with each other directly, “dual stack” systems provide facilities for exchanging data between IPv4 and IPv6"[24]. The IP is the communication protocol between computers over the Internet by being the personal address of this computer. 2.1.8 TCP protocol TCP, or the Transmission Control Protocol, TCP provides the communication between the application program and the Internet Protocol (TCP / IP), the application does not need to fragment the packet sent over TCP[25]. For efficient routing across the network, the TCP protocol tracks the segments where the message is split, due to unexpected network behavior, packets may be lost or delivered out of order, TCP detects and reduces these issues by rearranging packet data or requesting a redelivery and sometimes comes with a delay of several seconds[25]. 2.1.9 Android OS "Android is an open source and Linux-based Operating System for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies. The first beta version of the Android Software Development Kit (SDK) was released by Google in 2007 where as the first commercial version, Android 1.0, was released in September 2008. On June 27, 2012, at the Google I/O conference, Google announced the next Android version, 4.1 Jelly Bean. Jelly Bean is an incremental update, with the primary aim of improving the user interface, both in terms of functionality and performance. The source code for Android is available under free and open source software licenses. Google publishes most of the code under the Apache License version 2.0 and the rest, Linux kernel changes, under the GNU General Public License version 2"[26]. Android has one approach to developing mobile apps, which means that developers only need to develop for Android, and apps are able to work on different devices running the same system. Android is a powerful operating system and supports great features [26]. https://en.wikipedia.org/wiki/Transmission_Control_Protocol 9 Figure 1: Android features 2.1.10 Features of Android: 1. Open source 2. Larger developer and community reach 3. Increased marketing 4. Inter App integration 5. Reduced cost of development 6. Higher success ratio 7. Rich development environment 2.2 Literature review: V. Berlin Hency "Implementation of an automated irrigation system: Smart irrigation system", His paper works on an automatic Irrigation system, allow the sensor sends data to the micro-controller, and sends it through the SIM900A module, according to this sends the data to the mobile. One of the problems of his project is that does not keep the user informed of the condition of the soil regularly, but only relies on the messages that are sent every period by SMS when the degree of humidity reaches the pre-set level in the microcontroller. The advantages the project does not depend on a specific area or a certain range, and the data is sent without relying on the location of the user [11]. 10 Pavankumar Naik , Arun Kumbi, Kirthishree Katti, and Nagaraj Telkar in there research "Automation of irrigation system using IoT" applied the irrigation system from a wider and more efficient side, depending on the capabilities of their country. When implement Internet of things system in Sudan will be of low quality because the Internet does not cover all agricultural areas [12]. Ayoade Felix Agbetuyi, Orovwode hope Evwieroghene, Ayokunle Awelewa, and Samuel Wara Tita, there research "Design and implementation of an automatic irrigation system based on monitoring soil moisture" discuss irrigation system and focusing on the degree of soil moisture and how to measure it in the correct manner without taking into account the degree of moisture appropriate for the plant or crop, as we find that even with the different type of soil, the crop needs a certain amount of water [13]. Gasore Geoffrey, Munyaneza Jean de Dieu, Ngendabanga Jean Pierre, and Twibanire Aimable discuss a simple project in their paper "Design of Automatic Irrigation System for Small Farmers in Rwanda" this project succeeded in designing a project that works with solar energy, ensuring the sustainability of irrigation, opening and closing the motor based on the amount of heat collected in the panels and comparing the soil moisture to the level of humidity in the program. We find that the project lacks the automatic control from farmer in the process of opening and closing the motor. We also find the project covers small areas [14]. Mehedi Islam, Al-Momin, Tauhid, Kamal Hossain, and Sumonto Sarker published enhanced project " IoT Based Smart Irrigation Monitoring & Controlling System in Agriculture " this research paper was published in 2020, it developed the irrigation system in a noticeable way, it used Raspberry Pi as a database platform, used the GPS system and FTT app, through these two applications the user kept informed of the weather prediction and sends a notification of rain, the user can shut down the pump and take advantage of water comes from rains without harming the crop and linking the program to a special Gmail account for the user through which the sensor data is sent, and with it he becomes aware of the latest data on the farm. The pump opens and closes automatically or by the user. Although this paper covered the irrigation system from several angles and used different systems to make the system more flexible and efficient, it is very costly for the user in Sudan [17]. https://www.researchgate.net/profile/Ayoade_Agbetuyi https://www.researchgate.net/profile/Orovwode_Evwieroghene https://www.researchgate.net/profile/Ayokunle_Awelewa https://www.researchgate.net/profile/Samuel_Wara_Tita https://www.researchgate.net/profile/Samuel_Wara_Tita 11 CHAPTER 3: METHODOLOGY 12 CHAPTER 3 METHODOLOGY 3.1 Introduction: This Chapter will discuss what the research is, what it consists of and what tools are appropriate for it, in addition to the block diagram of the circuit and the codes used in the implementation. Project steps can be divided into two parts: i. Software Represented in: o preparing the appropriate environment for programming the Client Android application. Android is programmed in Java language to the customer, the customer communicates with the server, analyzes the data and sends the appropriate suggestions to the user. o Preparing the environment to programming Arduino Server. The server receives the data sent from the sensor and sends it to the client Android application. it also receives orders sent from the user to open or close the pump. ii. Hardware The hard-ware simulates the work of the system, the sensor was connected to the esp8266 via breadboard directly, reached the ADC pin, and a led was used to simulate the work of the motor. The block diagram is shown below: 13 Figure 2: block diagram of the system 3.2 Project needs: 3.2.1 Install the following: o Android studio 4.0. o Arduino IDE. 3.2.2 Prerequisites: o ESP8266-12e. o Led. o Breadboard. o Wires. o Soil moisture sensor Fc-28 Use more than one programming language. 3.3 Definitions of Prerequisites: 3.3.1 Esp8266-12E: 3.3.1.1 What is the Esp8266-12E 14 It's a SOC (system on a chip) produced by Espressif Systems with a full TCP/IP stack, serial UART and microcontroller capability, the Esp8266-12e contain a WiFi module given him more flexibility In addition it's a low-cost Wi-Fi microchip , it is very convenient and affordable. This made developers biased in using this chip frequently.[7] One of the advantages of esp8266-12e is that the environment that is the Arduino IDE for programming the ESP Directly, we only need to download the library concerned with it, as esp8266-12 has many versions such as esp32 and others. The ESP8285 is an ESP8266 with 1 MB of built-in flash, The GPIO pins allow Analog and Digital IO, plus PWM, SPI, I2C, etc. [8] Figure 3: ESP8266-12E Datasheet 3.3.1.2 Uses for esp8266: 1. Wi-Fi controlled robot. https://en.wikipedia.org/wiki/TCP/IP_stack https://en.wikipedia.org/wiki/Microcontroller https://en.wikipedia.org/wiki/Wi-Fi 15 2. World's smallest IoT project. 3. ESP8266 Projects: Wireless Web Server. 4. Humidity and temperature monitoring. 3.3.2 5mm Led: Simple led has a forward voltage of 2.0V and a rated forward current of 20mA.[4] Figure 4: Led 3.3.3 Soil moisture sensor Fc-28: Figure 5: Soil moisture sensor FC-28 16 3.3.3.1 Features • Digital Output Threshold Adjust Potentiometer[2] • Power and Digital Output Indicator LEDs[2] • Analog and Digital outputs[2] • Mounting hole for easy installation [2] 3.3.3.2 Technical Specifications • Operating voltage 3.3V-5V[2] • PCB size: 3.2cm x 1.4cm[2] • Power indicators: (red) and digital switching output indicator (green) [2] • Comparator Chip : LM393 [2] 3.3.3.3 Pinouts • VCC: .3.3V-5V[2] • GND: 0V Ground Reference[2] • DO: digital output (0 or 1) [2] • AO: Analog output (0 – VCC) [2] 3.3.4 Breadboard provide a quick way to build and test circuits for experimentation.[5] 17 Figure 6: Breadboard 3.4 project steps: The main idea in this project is to control the level of water flowing to the farm or plants by opening and closing the water pump, in addition to permanent monitoring of the amount of flowing water and making the user more abreast of the state of the farm or plants. Android was programmed as a client for easy monitoring of more than one group of plants, while esp8266-12e. was programmed as a server, which is shown in the code below. 3.5 Installing Android studio v4 Android Studio is the official integrated development environment (IDE) for Android application development. It is based on the IntelliJ IDEA, a Java integrated development.[6] And it is installed to work on it. [1] This project created an application on Android that provides communication between the sensor and the farmer who is observing the farm or plants, and the opportunity for him to make the appropriate decision based on the readings sent to him from esp8266- 12e. The client was programmed by Android Studio using the Java language Android code MainActivity java code package com.example.irrigationfarmacy1; import android.annotation.SuppressLint; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.CompoundButton; import android.widget.EditText; import android.widget.Switch; import android.widget.TextView; https://searchsoftwarequality.techtarget.com/definition/integrated-development-environment https://www.theserverside.com/definition/IntellJ-IDEA https://www.theserverside.com/definition/Java 18 import androidx.appcompat.app.AppCompatActivity; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.Socket; @SuppressLint("SetTextI18n") public class MainActivity extends AppCompatActivity { Thread Thread1 = null; EditText etIP, etPort; TextView tvMessages; TextView tvConnected; TextView tvFarmers; String SERVER_IP; int SERVER_PORT; public boolean asas=true; int wet=600; int dry=800; int sencerRead; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etIP = findViewById(R.id.etIP); etPort = findViewById(R.id.etPort); tvMessages = findViewById(R.id.tvMessages); tvConnected = findViewById(R.id.tvConnected); Switch sw = (Switch) findViewById(R.id.onOffSwitch); tvFarmers = findViewById(R.id.tvFarmer); sw.setOnCheckedChangeListener(new 19 CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { String message; if (isChecked) { message = "On"; } else { message = "Off"; } if (!message.isEmpty()) { new Thread(new Thread3(message)).start(); } } }); Button btnConnect = findViewById(R.id.btnConnect); btnConnect.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tvConnected.setText(""); SERVER_IP = etIP.getText().toString().trim(); SERVER_PORT = Integer.parseInt(etPort.getText().toString().trim()); Thread1 = new Thread(new Thread1()); Thread1.start(); } }); } private PrintWriter output; private BufferedReader input; class Thread1 implements Runnable { 20 public void run() { Socket socket; try { socket = new Socket(SERVER_IP, SERVER_PORT); output = new PrintWriter(socket.getOutputStream()); input = new BufferedReader(new InputStreamReader(socket.getInputStream())); runOnUiThread(new Runnable() { @Override public void run() { tvConnected.setText("Connected\n"); } }); new Thread(new Thread2()).start(); } catch (IOException e) { e.printStackTrace(); } } } class Thread2 implements Runnable { @Override public void run() { String ms1; final int secondsToSleep =0; while (asas) { try { Thread.sleep(secondsToSleep * 1); } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } try { 21 final String message = input.readLine(); if (message != null) { ms1= "server: " + message + "\n"; asas=true; runOnUiThread(new Runnable() { @Override public void run() { tvMessages.setText( message); sencerRead=Integer.parseInt(message); if(sencerRead >= dry){ tvFarmers.setText(" It's dry. Opereate Pump\n"); } if(sencerRead <= wet) { tvFarmers.setText(" It's wet. stop Pump\n"); } } }); } else { Thread1 = new Thread(new Thread1()); Thread1.start(); return; } } catch (IOException e) { e.printStackTrace(); } } } } 22 class Thread3 implements Runnable { private String message; Thread3(String message) { this.message = message; } @Override public void run() { output.write(message); output.flush(); runOnUiThread(new Runnable() { @Override public void run() { tvConnected.setText("client: " + message + "\n"); } }); } } } 3.6 ESP8266 side: Programming Environment - ESP8266 with Arduino IDE. - ESP8266 with NodeMCU Firmware. Preferred to program the ESP8266 with the Arduino IDE, but both methods are very popular The ESP-12E often called ESP-12E Kit is currently the most practical version It plays the role of the server. To program esp8266-12e installed the library specialized to it which is ESP8266WiFi.h [9] and installed ch340 driver [10] Arduino code: #include #define SendKey 0 23 int port = 8080; WiFiServer server(port); int sensorValue = 0; const int analogInPin = A0; String sensorValueString; String state; int lastState = 0; //Server connect to WiFi Network const char *ssid = "Esp8266"; //Enter your wifi SSID const char *password = "1234"; //Enter your wifi Password int count=0; // Power on setup //======================================================= ============= void setup() { pinMode(16, OUTPUT); Serial.begin(115200); pinMode(SendKey,INPUT_PULLUP); Serial.println(); WiFi.mode(WIFI_STA); WiFi.begin(ssid, password); // Wait for connection Serial.println("Connecting to Wifi"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); delay(500); 24 } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); server.begin(); server.setNoDelay(true); Serial.print("Open Telnet and connect to IP:"); Serial.print(WiFi.localIP()); Serial.print(" on port "); Serial.println(port); } // Loop //======================================================= ============= void loop() { WiFiClient client = server.available(); if (client) { if(client.connected()) { Serial.println("Client Connected"); } sensorValue = analogRead(analogInPin); sensorValueString = String(sensorValue); Serial.print(sensorValueString); client.print(sensorValueString ); client.write(""); delay(1000); 25 state = client.readStringUntil('\r'); //Serial.parseInt(); if (state == "On") { digitalWrite(16, HIGH); } if (state == "Off") { digitalWrite(16, LOW); } } } 26 3.7 Circuit diagram: Figure 7: Circuit diagram 27 CHAPTER 4: RESULTS & DISCUSSION 28 Chapter 4 Results & Discussion 4.1 Result: After running the programs mention in the method above following results were obtain the following: Connecting with the WIFI: The first read from the sensor 29 When the soil is dry 30 When the motor is opened When the motor is closed 31 32 4.2 Discussion: The system was operating as expected. When running the app, it waits for permission to connect to the server, and the server will check the client's IP and connect to the app. When conducting the connection, the sensor sends the readings, and accordingly, the readings provide a suggestion to the user to turn on or off the motor. The farmer will make the best choice for farm or plants. It is noticeable from the readable results that the degree of dryness in the sensor does not change when it is in the air or on dry soil, and it was also noticed that the degree of dryness decreases with the increase in the amount of water. but if the sensor is putted in the place full of water, the reading will not exceed 330 as the sensor is working On measuring the degree of conductivity 33 When the sensor putted on the water, It is very clear, the sensor reading indicated that the degree of dryness is not high, and this is incorrect because the degree of conductivity in the water is less than that of the soil with a high degree of wetness. the readings were as follows: 34 Readings on very dry soil: Note: it is the same read when the sensor put at air. The benefit from this project to help the user to control the amount of water flowing to his plants or farm. And been him kept abreast of the proper humidity of the plant by preserving the amount of water. On the other hand, the user was able to reduce the amount of water used for irrigation, and to preserve it and use it in other areas that need water. And also maintaining the presence of suitable water for the crop or plants helps to improve the quality of the crop. what distinguishes this project is enables the user to open and close the motor based on what suits him, in addition to the presence of suggestions from the system for the user to see the best. 35 Chapter 5: Conclusions & Recommendations 36 Chapter 5 Conclusions & Recommendations 5.1 Conclusion: The project focuses to use in our country, Sudan, characterized by very low cost and flexibility of use in a very wide range on Sudanese lands that are not covered by the Internet, it can also be used in nurseries and homes. The project reduced the manpower and the amount of water flowing to the crop, saving time and effort for the user. 37 5.2 Recommendation: o To improve and develop this work, it is recommended to provide more accurate and scientific data to help the farmer make the decision to get the best crop. o More sensors can be added to give a more accurate reading of the soil moisture, such as the temperature sensor and the light sensor. o Also, consideration can be given to adding fertilizer that is dissolved in water to improve the productivity. o In case the Internet is available in agricultural areas, the project can be involved into the Internet of Things systems. o Also, the project can be provided with a database on the crop to help the farmer know the appropriate amount of water and the most appropriate irrigation method, surface irrigation or drip irrigation. 38 References [1] https://developer.android.com/studio [2] http://www.ti.com/lit/ds/symlink/lm393-n.pdf/ [3] https://www.youtube.com/watch?v=9TD6mOyowcg [4] https://www.sparkfun.com/products/9590 [5]https://components101.com/sites/default/files/component_datasheet/Breadboard% 20Datasheet.pdf [6] https://en.wikipedia.org/wiki/Android_Studio [7] https://en.wikipedia.org/wiki/ESP8266 [8] http://fabacademy.org/archives/2015/doc/networking-esp8266.html [9] https://github.com/esp8266/Arduino [10] https://www.driverguide.com/driver/download/USB-SERIAL-CH340 [10] [11]https://www.researchgate.net/publication/283230079_Implementation_of_an_automated _irrigation_system_Smart_irrigation_system_paper_subtitle [12] https://www.ripublication.com/ijems_spl/ijemsv8n1_08.pdf [13]https://www.researchgate.net/publication/309251140_Design_and_implementation_of_a n_automatic_irrigation_system_based_on_monitoring_soil_moisture [14] https://file.scirp.org/pdf/AS_2015030617402250.pdf [15]https://mawdoo3.com/%D8%A3%D9%86%D9%88%D8%A7%D8%B9_%D8% A7%D9%84%D8%B1%D9%8A [16] https://agronomie.info/%D8%A7%D9%84%D8%B1%D9%8A/ [17]https://www.researchgate.net/publication/341192722_IoT_Based_Smart_Irrigatio n_Monitoring_Controlling_System_in_Agriculture [18] https://www.hazemsakeek.net/wifi/ [19]https://mawdoo3.com/%D9%85%D8%A7_%D9%87%D9%8A_%D8%AE%D8%A7%D 8%B5%D9%8A%D8%A9_%D8%A7%D9%84%D9%88%D8%A7%D9%8A_%D9%81%D 8%A7%D9%8A [20] https://ujeeb.com/%D9%85%D8%A7-%D9%87%D9%8A- %D8%A7%D9%87%D9%85%D9%8A%D8%A9-%D8%A7%D9%84%D8%B1%D9%8A [21] https://iopscience.iop.org/article/10.1088/1748-9326/aadeef https://developer.android.com/studio http://www.ti.com/lit/ds/symlink/lm393-n.pdf/ https://www.youtube.com/watch?v=9TD6mOyowcg https://en.wikipedia.org/wiki/ESP8266 https://www.driverguide.com/driver/download/USB-SERIAL-CH340%20%5b10 https://www.researchgate.net/publication/283230079_Implementation_of_an_automated_irrigation_system_Smart_irrigation_system_paper_subtitle https://www.researchgate.net/publication/283230079_Implementation_of_an_automated_irrigation_system_Smart_irrigation_system_paper_subtitle https://www.researchgate.net/publication/309251140_Design_and_implementation_of_an_automatic_irrigation_system_based_on_monitoring_soil_moisture https://www.researchgate.net/publication/309251140_Design_and_implementation_of_an_automatic_irrigation_system_based_on_monitoring_soil_moisture https://www.hazemsakeek.net/wifi/ https://mawdoo3.com/%D9%85%D8%A7_%D9%87%D9%8A_%D8%AE%D8%A7%D8%B5%D9%8A%D8%A9_%D8%A7%D9%84%D9%88%D8%A7%D9%8A_%D9%81%D8%A7%D9%8A https://mawdoo3.com/%D9%85%D8%A7_%D9%87%D9%8A_%D8%AE%D8%A7%D8%B5%D9%8A%D8%A9_%D8%A7%D9%84%D9%88%D8%A7%D9%8A_%D9%81%D8%A7%D9%8A https://mawdoo3.com/%D9%85%D8%A7_%D9%87%D9%8A_%D8%AE%D8%A7%D8%B5%D9%8A%D8%A9_%D8%A7%D9%84%D9%88%D8%A7%D9%8A_%D9%81%D8%A7%D9%8A https://ujeeb.com/%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%87%D9%85%D9%8A%D8%A9-%D8%A7%D9%84%D8%B1%D9%8A https://ujeeb.com/%D9%85%D8%A7-%D9%87%D9%8A-%D8%A7%D9%87%D9%85%D9%8A%D8%A9-%D8%A7%D9%84%D8%B1%D9%8A https://iopscience.iop.org/article/10.1088/1748-9326/aadeef 39 [22] https://ar-ar.facebook.com/agricultureislife.84/posts/392361094153509/ [23] https://www.investopedia.com/terms/i/ip-address.asp [24] https://www.apnic.net/get-ip/faqs/what-is-an-ip-address/ [25] https://www.extrahop.com/resources/protocols/tcp/ [26] https://www.tutorialspoint.com/android/android_overview.htm [27] https://circuits4you.com/2018/11/26/esp8266-nodemcu-tcp-socket-server-arduino- example/ [28] https://www.espressif.com/sites/default/files/documentation/0a- esp8266ex_datasheet_en.pdf [29] https://www.tutorialspoint.com/sending-and-receiving-data-with-sockets-in-android [30] https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/ [31] https://www.ti.com/lit/ds/symlink/lm393-n.pdf [32]https://developer.android.com/reference/android/widget/CompoundButton.OnCheckedCh angeListener.html [33] https://www.arduino.cc/en/Reference/WiFi [34] https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html [35] https://androidstudio.googleblog.com/2020/08/constraintlayout-200.html [36] https://artofcircuits.com/product/fc-28-soil-moisture-sensor-analog-and-digital- outputs https://ar-ar.facebook.com/agricultureislife.84/posts/392361094153509/ https://www.investopedia.com/terms/i/ip-address.asp https://www.apnic.net/get-ip/faqs/what-is-an-ip-address/ https://www.extrahop.com/resources/protocols/tcp/ https://www.tutorialspoint.com/android/android_overview.htm https://circuits4you.com/2018/11/26/esp8266-nodemcu-tcp-socket-server-arduino-example/ https://circuits4you.com/2018/11/26/esp8266-nodemcu-tcp-socket-server-arduino-example/ https://www.espressif.com/sites/default/files/documentation/0a-esp8266ex_datasheet_en.pdf https://www.espressif.com/sites/default/files/documentation/0a-esp8266ex_datasheet_en.pdf https://www.tutorialspoint.com/sending-and-receiving-data-with-sockets-in-android https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/ https://developer.android.com/reference/android/widget/CompoundButton.OnCheckedChangeListener.html https://developer.android.com/reference/android/widget/CompoundButton.OnCheckedChangeListener.html https://www.arduino.cc/en/Reference/WiFi https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/readme.html https://androidstudio.googleblog.com/2020/08/constraintlayout-200.html