ALNEELAIN UNIVERSITY

FACULTY OF ENGINEERING

M.Sc. OF EMBEDDED SYSTEMS

Design of a Smart Greenhouse Adaptation and Control Irrigation System based on Arduino and Android Application

Thesis Submitted of Partial Fulfillment for M.Sc. Degree in Embedded Systems

Prepared by:

Motaz Alhassin Alhassan Abdalrahman

Supervisor:

Prof. Shareif Fadul Babikir

February 2020

I

االستهالل

بسى اهلل انشحًٍ انشحٍى

قبل حعبنى :

﴿ نَرْفَعُ دَرَجَاتٍ مَّن نَّشَاءُ ۗ وَفَىْقَ كُلِّ ذِي عِلْمٍ عَلِيمٌ ﴾

سىرة يىسف - اآلية )67(

I

DEDICATION

I am very grateful to Almighty Allah for helping me through this

long journey, May He continues to bless, help and guide us to the right

path.

I dedicate this project to all those that helped me toward this success, specially my parents, my families, my teachers and my colleagues.

And do not forget also those who departed from our world of

teachers.

Thank you all…

II

ACKNOWLEDGEMENTS

I would like to express my gratitude and appreciation to all those who gave me the possibility to complete this project. A special thanks to my supervisor Prof. Sharief Fadul Babikir, who helped me, stimulating suggestions and encouragement, help gratitude to coordinate my project and writing this Thesis.

III

ABSTRACT

Greenhouse is a kind of place which can change growth environment of plants, create the best conditions for plant growth, and avoid influence on plant growth due to outside changing. In this thesis, Android and Arduino based system applied to monitor and control greenhouse irrigation, temperature and humidity designed. The main objective of thesis to afford a cheap technology to control agriculture process. The methodology followed for show the results and control the system by using low power consumption Arduino kit and Bluetooth module. The result obtained show that the system performance is quite reliable and has successfully overcome quite a few shortcomings of the existing systems by reducing the power consumption, maintenance and complexity, at the same time providing a flexible and reliable form of maintaining the environment.

IV

المستخلص

انبٍج انًحًً عببسة عٍ يكبٌ ٌخى فٍّ حغٍٍش بٍئت ًَٕ انُببث ٔحٕفٍش انبٍئت انًثهى نًُٕ انُببث ٔحفبدي حغٍشاث انًُبخ انخبسجً . فً انبٍج انًحًً ٌٕجذ انكثٍش يٍ انًؤششاث انبٍئٍت ٔانخً ٌصعب يشاقبخٓب ٌذٌٔب . األطشٔحّ ححخٕي عهً حصًٍى دائشة بًخحكى قببم نهبشيجت ٔ يشبٕط بخطبٍق اَذسٌٔذ نخخحكى ببنشي ٔحشاقب ٔ حخحكى بذسجت انحشاسة ٔانشطٕبت انُسبٍت داخم انبٍج انًحًً، حٍذ ًٌثم فٍٓب )االسدٌُٕٔ( انًخحكى انشئٍسً. انٓذف انشئٍسً نألطشٔحّ ْٕ أٌ حٕفش حكُٕنٕنجٍب سخٍصّ نهخحكى فً عًهٍت انزساعت، ٔطشٌقت انعًم انًخبعّ نٓزِ انخكُٕنٕجٍب بأسخخذاو يخحكًت )اسدٌُٕٔ( راث األسخٓالك األقم نهطبقّ يع سبطٓب بٕحذة بهٕحٕد نعشض انُخبئج ٔانخحكى فٍٓب. َخٍجت السخخذاو ْزا انُظبو حى حم عذٌذ يٍ يشكالث األَظًت انسببقت حٍذ حى حقهٍم انطبقت انًسخٓهكت ٔاصبحج األَظًت أقم حعقٍذا، ٌٔعخًذ عهٍٓب نهحفبظ عهً بٍئت يُبسبت نًُٕ انُببث.

V

TABLE OF CONTENTS

I ...... االستهالل DEDICATION ...... II ACKNOWLEDGEMENTS ...... III ABSTRACT ...... IIV V ...... المستخلص TABLE OF CONTENTS ...... VI LIST OF FIGURES ...... VIVIIII LIST OF SYMBOLS ...... VIVIII ABBREVIATIONS ...... IIX Chapter One ...... 1 Introduction ...... 1 1.1 Preface ...... 1 1.2 Problem Statement ...... 1 1.3 Project Objectives ...... 2 1.4 Methodology ...... 2 1.5 Outlines of the Thesis ...... 3 Chapter Two ...... 4 Literature Review ...... 4 2.1 Overview ...... 4 2.2 Control of Greenhouse ...... 4 2.2.1 Temperature Control ...... 4 2.2.2 Greenhouse Cooling ...... 5 2.2.3 Greenhouse Heating ...... 6 2.2.4 Humidity Control ...... 6 2.3 Software Environment ...... 7 2.3.1 Arduino IDE...... 7 2.3.2 Android Service ...... 9 2.3.3 MIT app inventor ...... 10 2.3.4 App Inventor Built-in Blocks ...... 11 2.4 Control Unit ...... 12 2.4.1 Arduino ...... 12 VI

2.5 Sensors ...... 17 2.5.1 LM35 Temperature Sensor ...... 18 2.5.2 DHT 11 Humidity & Temperature Sensor ...... 18 2.5.3 Water sensor ...... 19 2.6 Bluetooth technology ...... 20 2.6.1 Bluetooth module HC-06 ...... 21 Chapter Three ...... 22 Methodology ...... 22 3.1 Overview ...... 22 3.2 Block Diagram of The System ...... 22 3.3 Flow Chart of The System ...... 23 3.4 The system connection ...... 24 3.5 Arduino sensor readings ...... 24 3.6 LM35 Temperature calculation ...... 25 3.7 DHT11 Humidity calculation ...... 25 3.8 Software implementation ...... 27 3.9 ...... 28 3.10 Circuit Simulation ...... 30 Chapter Four ...... 31 Result and Discussions ...... 31 4.1 Android application interfacing result ...... 31 4.2 Testing of Temperature Sensor ...... 31 4.3 Testing of water sensor ...... 32 4.3 Controlling via the application ...... 33 Chapter Five ...... 35 Conclusion and Recommendations ...... 35 5.1 Conclusion ...... 35 5.2 Recommendations ...... 35 Refrencece ...... 40 Appendices ...... A-1

VII

LIST OF FIGURES

Figure No Figure Name Page Figure ‎2.1 Arduino IDE 9 Figure 2.2 MIT APP Inventor 11 Figure ‎2.3 Arduino Uno 14 Figure ‎2.4 LM35 Temperature Sensor 18 Figure ‎2.5 DHT humidity sensor 19 Figure 2.6 Water sensor. 20 Figure ‎2.7 Bluetooth module HC-06 21 Figure 3.1 Block diagram of the system 22 Figure 3.2 Block diagram of the system 23 Figure 3.3 Designer screen 28 Figure 3.4 Android user interface 29 Figure 3.5 Mounting of the tablet 30 Figure 3.6 Simulation of system hardware circuit 30 Figure 4.1 User interface of android application 31 Figure 4.2 Temperature sensor readings 32

Figure 4.3 Water sensor reading 32 Figure 4.4 Readings in application and controlling motor 34 bump and cooling fan

LIST OF SYMBOLS

° degree Celsius µ Micro

VIII

ABBREVIATIONS

AC Analog Current AIDL Android Interface Definition Language AREF Analog Reference CSAIL MIT's Computer Science and Artificial Intelligence Laboratory DC Direct Current DHT Digital Temperature and Humidity Sensor GHZ Giga Hertz GND Ground IC Integrated Circuit IDE Integrated Development Environment IEEE Institute of Electrical and Electronics Engineers IoT Internet of Things ISM Institute for Supply Management LED Light Emitting Diode MIT Massachusetts Institute of Technology NTC Negative Temperature Coefficient OS PAN Personal Area Network PC Personal Computer PLC Programmable Logic Control PWM Pulse Width Modulation RH Relative Humidity RX Receiver T Temperature TX Transmitter UHF Ultra High Frequency USB Universal Serial Bus V Voltage WIFI Wireless Fidelity

IX

Chapter One Introduction 1.1 Preface The concept of greenhouses is Protected agriculture known as crop production to non-conventional means in particular facilities to protect from inappropriate weather conditions, such as agriculture in tunnels or plastic greenhouses with controlled internal climate control and control (glass or glass Viper) to ensure heating or cooling in summer and winter as well as the appropriate moisture control and plant protection from hot and cold air currents, precipitation and agricultural pests, and which is a sophisticated agricultural and factor in increasing agricultural productivity and quantity of crops. Early automated control consisted of independent thermostats, humidistat, and timers. Even these simple devices allowed major advances in efficiency and product quality and made grower‟s lives simpler. The common problems experienced with using several independent thermostats and timers to control a greenhouse led to the development of early electronic analogue controls, also known as “step” controls. These devices made a major contribution to improving the growing environment and increasing efficiency by combining the functions of several thermostats into a single unit with a single temperature sensor. [1]

1.2 Problem Statement In green houses there are a lot of parameters such as temperature, humidity and irrigation, which are very hard to monitor all of these parameters by human. And any significant changes in one climate parameter could have an adverse effect on another climate parameter as well as the development process of the plants. Therefore, continuous

1 monitoring and control of these climate factors will allow for maximum crop yield. Temperature, humidity and light intensity are the three most common climate variables that most growers generally pay attention to. The solution for all that thing and other in use android application with Arduino to monitor and control the greenhouse environment.

1.3 Project Objectives The objective of this Project is to design and implement simple, easy to install, Arduino-based circuit to monitor and control the irrigation of greenhouse and the values of temperature and humidity of the natural environment that are continuously modified and controlled in order optimize them to achieve maximum plant growth and yield. To work out the pre mentioned problem and find the best solution, different sensors such as humidity, temperature, and water sensors can be utilized to measure the related data, feed it back to a monitoring station and take relevant control actions at the same time without human intervention.

1.4 Methodology There is two parts in the practical implementation:

The first part is the android application that is connected with the Bluetooth with the control unit.

The second part which is the control unit that include a circuit with Arduino and sensors (humidity, temperature, water ) these sensor sends signals to the Arduino which is connected with the android application the circuit as well has a drive circuit which convert the electrical energy to a mechanical energy so that the motor will understand it.

2

1.5 Outlines of the Thesis This thesis will be divided into five chapters.

The first chapter contains Introduction Include preface, problem statement, methodology and project objectives.

The second chapter contains literature review explain system component and previous studies.

Chapter three explains the topic of the way we develop and design highlight the system circuit and explain the system function.

Chapter four result and discussions shows obtains result from simulation and practical implementation.

Chapter five conclusion and recommendations.

3

Chapter Two Literature Review 2.1 Overview Monitoring and control of greenhouse environment play a significant role in greenhouse production and management. To monitor the greenhouse environment parameters effectively, it is necessary to design a control system. Here controlling process takes place effectively by both manual and automatic manner. For manual control purpose RS232 is used, which will send status of greenhouse environment automatic control process. To control room. There we can control the activities through PC and send to controller back which is in greenhouse environment. [2]

2.2 Control of Greenhouse 2.2.1 Temperature Control In general, the temperature parameter is the primary focus of most climate control systems. This may include the air temperature surrounding the aerial portion of the plant, as well as, root zone and leaf temperatures. The changes of external climatic condition strongly influence the inside air temperature. For example, the decrease of the temperature outside the greenhouse or the increase of the wind speed will lead to the decrease of the temperature inside the greenhouse. [2] Temperature is raised by heating, generally by hot water circulated in ground level pipes, and lowered by opening roof ventilators. [3] Temperature is the most easily measured aerial environmental parameter. However, each plant species has its own optimum range and timetable for features such as productivity, flowering, and timing to market. [4]

4

To measure the temperature the sensor tip must not be exposed to radiant energy, such as from direct sunlight or a heating system radiator, as this will increase the sensor tip temperature. In that case, the measurement taken would not be representative of the surrounding air temperature. Accurate measurement of the air temperature is best accomplished using an aspirated housing to move an air sample across the sensor and protect the sensor from direct exposure to solar radiation. This ensures a more representative measurement of the greenhouse air temperature. Two temperatures are important when dealing with evaporative cooling systems; dry bulb temperature and wet bulb temperature. Dry bulb temperature is the temperature that is usually thought of as air temperature. It is the temperature measured by a regular thermometer exposed to the air stream. The wet-bulb temperature is the temperature at which air is fully saturated (100% RH). Wet bulb temperature is an indication of the amount of moisture in the air. Wet bulb temperatures can be determined by checking with local weather station or by investing in an aspirated psychomotor, a sling psychomotor, or an electronic humidity meter. The best time to measure wet bulb temperature to calculate the potential cooling performance of the evaporative cooling system is in the afternoon. This is when dry bulb temperature is at its peak because solar radiation and outside temperatures are highest.

2.2.2 Greenhouse Cooling Techniques of cooling can be organized into several categories; each utilizes the evaporative cooling process to reduce air temperature, as well as fan ventilation for exchanging the moist air with dry outside air. Greenhouse cooling reduces plant stress caused by high leaf and air temperatures. The root and stem system may not be able to supply

5 adequate water to the leaves, thereby limiting transpiration, the plant cooling mechanism. Also, hot and humid air around the leaves will reduce the effectiveness of transpiration at the leaf surface. [5]

2.2.3 Greenhouse Heating The purpose of the heating system is to replace energy lost from the greenhouse when outside temperatures are lower than desired in the greenhouse growing area. Heat is transferred by conduction, convection, and radiation. Radiation heat loss can represent 25% or more of the total heat loss for a double- layer polyethylene greenhouse on clear night‟s .The heat loss from a greenhouse depends upon three parameters:

(1) The surface area of the greenhouse.

(2) The location of the greenhouse and crop to be grown.

(3) The greenhouse heat loss rate which is largely dependent upon the glazing material.

Two of these are readily determined, and the third is an approximation depending upon the glazing and its condition and whether or not thermal screens are in place. Heat losses down to the ground are usually negligible relative to losses to the atmosphere. These are usually not included because the temperature difference between the greenhouse and soil is small and the heat transfer coefficient is relatively small. [6]

2.2.4 Humidity Control There are several terms that describe humidity and several ways to measure humidity. Relative Humidity indicates the “relative” fraction of water vapor in a volume of air to how much water vapor that air would contain at saturation at the same temperature and pressure. [7] Controlling the humidity in the greenhouse can yield powerful benefits in disease reduction, improved water and nutrient uptake, and improved 6 plant growth. It is too often underutilized and not well understood. Humidity control is a standard function of nearly all greenhouse control systems. Accurate humidity sensing can be a challenge, even with the most expensive sensors, which are typically not suitable or practical for the commercial greenhouse industry. Humidity can generally be lowered by ventilation (which may also necessitate heating) and raised by the evaporation of water supplied from fogging nozzles. Wet and dry bulb thermometers, usually resistance elements, are used to determine the air temperature and humidity.

2.3 Software Environment In this section the software that used in this system was mention.

2.3.1 Arduino IDE The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino and Genuino hardware to upload programs and communicate with them.

Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file extension .ino. The editor has features for cutting/pasting and for searching/replacing text. The message area gives feedback while saving and exporting and also displays errors. The console displays text output by the Arduino Software (IDE), including complete error and other information. The bottom right hand corner of the window displays the configured board and serial port. The toolbar buttons allow you to verify and upload programs, create, open, and save sketches, and open the serial monitor.

7

A program for Arduino may be written in any for a compiler that produces binary machine code for the target processor. Atmel provides a development environment for their microcontrollers, Automatic control to regulate the voltage "AVR" Studio and the newer Atmel Studio.

The Arduino project provides the Arduino integrated development environment (IDE), which is a cross-platform application written in the programming language Java. It originated from the IDE for the languages Processing and Wiring. It includes a code editor with features such as text cutting and pasting, searching and replacing text, automatic indenting, brace matching, and syntax highlighting, and provides simple one-click mechanisms to compile and upload programs to an Arduino board. It also contains a message area, a text console, a toolbar with buttons for common functions and a hierarchy of operation menus.

The Arduino IDE supports the languages C and C++ using special rules of code structuring. The Arduino IDE supplies a software library from the Wiring project, which provides many common input and output procedures. User-written code only requires two basic functions, for starting the sketch and the main program loop, that are compiled and linked with a program stub main() into an executable cyclic executive program with the GNU tool chain, also included with the IDE distribution. The Arduino IDE employs the program avrdude to convert the executable code into a text file in hexadecimal encoding that is loaded into the Arduino board by a loader program in the board's firmware [8].

8

Figure 2.1: Arduino IDE 2.3.2 Android Service As mentioned before service is a task that runs in the background to perform long running operation without direct user interaction. Example: playing music in background while user checking new mail, another example is updating weather condition for the gadgets running on the phone. It is important to know that service will run the main thread of its hosting process. In other words, service is neither a separate process nor a thread. Thus, Android service is a facility to tell the system it wants to perform special task in background. In addition, service is a capability to depict some its functionality to other applications. Interaction with service in Android platform can be complex or easy, considering it as local object in java or remote able interface by use of AIDL. Context.bindService() is used to get persistent connection with service.

9

To use a service in an Android project, it is mandatory to provide tag in manifest file of the project. In this case, other applications are needed to show tag in their manifest file to be able to start, stop, or bind the services. Local Service is usual type of service when the service should be part of an application, and should interact with the application. Remote Messenger Service is another kind of Android service which provides complex connection with client in remote process. Service can be started by Context.startService(), at this point system demand the service and run onStartCommand() method to enable the service to do its task until Context.stopservice() is called. Note that it is not important how many times Context.startService() be called. The service is started again just in a condition that not be in running mode.

2.3.3 MIT app inventor App Inventor for Android is an open-source web application originally provided by , and now maintained by the Massachusetts Institute of Technology (MIT). It allows newcomers to to create software applications for the Android operating system (OS). It uses a graphical interface explained in Figure 2.2, very similar to Scratch and the Star Logo TNG user interface, which allows users to drag-and-drop visual objects to create an application that can run on Android devices. In creating App Inventor, Google drew upon significant prior research in educational computing, as well as work done within Google on online development environments.

MIT App Inventor is an intuitive is visual programming environment that allows everyone – even children – to build fully

10 functional apps for and tablets. Those new to MIT App Inventor can have a simple first app up and running in less than 30 minutes. What‟s more, our blocks-based tool facilitates the creation of complex, high-impact apps in significantly less time than traditional programming environments. The MIT App Inventor project seeks to democratize software development by empowering all people, especially young people, to move from technology consumption to technology creation.

A small team of CSAIL staff and students, led by Professor , forms the nucleus of an international movement of inventors. In addition to leading educational outreach around MIT App Inventor and conducting research on its impacts, this core team maintains the free online app development environment that serves more than 6 million registered users.

Figure 2.2: MIT APP Inventor 2.3.4 App Inventor Built-in Blocks Built-in blocks are available regardless of which components are in your project. In addition to these language blocks, each component in your project has its own set of blocks specific to its

11 own events, methods, and properties. This is an overview of all of the Built-In Blocks available in the Blocks Editor. [9]

 Control blocks  Logic blocks  Math blocks  Text blocks  Lists blocks  Colors blocks  variables blocks  Procedures blocks

2.4 Control Unit The process o requires a hardware unit to control the motors movement and collecting the data .

Many types of controllers can be used to perform this operation such as:

 Microcontroller   Arduino kit

2.4.1 Arduino Arduino is an open-source platform used for building electronics projects. Arduino consists of both a physical programmable circuit board (often referred to as a microcontroller) and a piece of software, or IDE (Integrated Development Environment) that runs on your computer, used to write and upload computer code to the physical board.

The Arduino platform has become quite popular with people just starting out with electronics, and for good reason. Unlike most previous

12 programmable circuit boards, the Arduino does not need a separate piece of hardware (called a ) in order to load new code onto the board – you can simply use a USB cable. Additionally, the Arduino IDE uses a simplified version of C++, making it easier to learn to program. Finally, Arduino provides a standard form factor that breaks out the functions of the micro-controller into a more accessible package.

Arduino makes several different boards, each with different capabilities. In addition, part of being open source hardware means that others can modify and produce derivatives of Arduino boards that provide even more form factors and functionality. If you‟re not sure which one is right for your project, check this guide for some helpful hints. Here are a few options that are well-suited to someone new to the world of Arduino: [10]

 Arduino Uno The Uno is a great choice for your first Arduino. It‟s got everything you need to get started, and nothing you don‟t. It has 14 digital input/output pins (of which 6 can be used as Pulse width modulation "PWM" outputs), 6 analog inputs, a USB connection, a power jack, a reset button and more. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a Alternating current "AC"-to- Direct current"DC" adapter or battery to get started.

13

Figure 2.3: Arduino Uno - Power (USB / Barrel Jack) Every Arduino board needs a way to be connected to a power source. The Arduino UNO can be powered from a USB cable coming from your computer or a wall power supply (like this) that is terminated in a barrel jack. In the picture above the USB connection is labeled (1) and the barrel jack is labeled (2).

- Pins (5V, 3.3V, Ground "GND", Analog, Digital, PWM, AREF) The pins on your Arduino are the places where you connect wires to construct a circuit (probably in conjunction with a breadboard and some wire. They usually have black plastic „headers‟ that allow you to just plug a wire right into the board. The Arduino has several different kinds of pins, each of which is labeled on the board and used for different functions.

GND (3): Short for „Ground‟. There are several GND pins on the Arduino, any of which can be used to ground your circuit.

5V (4) & 3.3V (5): As you might guess, the 5V pin supplies 5 volts of power, and the 3.3V pin supplies 3.3 volts of power. Most of the simple components used with the Arduino run happily off of 5 or 3.3 volts. 14

Analog (6): The area of pins under the „Analog IN‟ label (A0 through A5 on the UNO) are Analog IN pins. These pins can read the signal from an analog sensor (like a temperature sensor) and convert it into a digital value that we can read.

Digital (7): Across from the analog pins are the digital pins (0 through 13 on the UNO). These pins can be used for both digital input (like telling if a button is pushed) and digital output (like powering an LED).

PWM (8): You may have noticed the tilde (~) next to some of the digital pins (3, 5, 6, 9, 10, and 11 on the UNO). These pins act as normal digital pins, but can also be used for something called Pulse-Width Modulation (PWM). We have a tutorial on PWM, but for now, think of these pins as being able to simulate analog output (like fading an LED in and out).

AREF (9): Stands for Analog Reference. Most of the time you can leave this pin alone. It is sometimes used to set an external reference voltage (between 0 and 5 Volts) as the upper limit for the analog input pins

- Reset Button Just like the original Nintendo, the Arduino has a reset button (10). Pushing it will temporarily connect the reset pin to ground and restart any code that is loaded on the Arduino. This can be very useful if your code doesn‟t repeat, but you want to test it multiple times. Unlike the original Nintendo however, blowing on the Arduino doesn‟t usually fix any problems.

- Power LED Indicator

15

Just beneath and to the right of the word “UNO” on your circuit board, there‟s a tiny LED next to the word „ON‟ (11). This LED should light up whenever you plug your Arduino into a power source. If this light doesn‟t turn on, there‟s a good chance something is wrong. Time to re-check your circuit!

- Transmitter "Tx" Receiver "Rx" LEDs TX is short for transmit, RX is short for receive. These markings appear quite a bit in electronics to indicate the pins responsible for serial communication. In our case, there are two places on the Arduino UNO where TX and RX appear – once by digital pins 0 and 1, and a second time next to the TX and RX indicator LEDs (12). These LEDs will give us some nice visual indications whenever our Arduino is receiving or transmitting data (like when we‟re loading a new program onto the board).

- Main Integrated Circuit "IC" The black thing with all the metal legs is an IC, or Integrated Circuit (13). Think of it as the brains of our Arduino. The main IC on the Arduino is slightly different from board type to board type, but is usually from the ATmega line of IC‟s from the ATMEL company. This can be important, as you may need to know the IC type (along with your board type) before loading up a new program from the Arduino software. This information can usually be found in writing on the top side of the IC. If you want to know more about the difference between various IC‟s, reading the datasheets is often a good idea.

- Voltage Regulator The voltage regulator (14) is not actually something you can (or should) interact with on the Arduino. But it is potentially useful to know that it is there and what it‟s for. The voltage regulator does exactly what 16 it says – it controls the amount of voltage that is let into the Arduino board. Think of it as a kind of gatekeeper; it will turn away an extra voltage that might harm the circuit. Of course, it has its limits, so don‟t hook up your Arduino anything greater than 20 volts .

2.5 Sensors A Sensor is equipment capable of measuring a physical quantity and converts it into a signal which then can be monitored by an observer or by an instrument. In daily life, from a simple touch screen on mobile phones to more complicated achievements such as an automated robot in modern productions, it is clear that sensors and sensor applications have become a main key of technology in engineering. Basically, sensors are devices to measure and analyze different kind of physical phenomena to make them more sensible and understandable by changing them to signals on which processing are more convenient .

Another definition of sensor is a device, module, or subsystem whose purpose is to detect events or changes in its environment and send the information to other electronics, frequently a computer processor. A sensor is always used with other electronics, whether as simple as a light or as complex as a computer.

Sensors are used in everyday objects such as touch-sensitive elevator buttons (tactile sensor) and lamps which dim or brighten by touching the base, besides innumerable applications of which most people are never aware. With advances in micro-machinery and easy- to-use microcontroller platforms, the uses of sensors have expanded beyond the traditional fields of temperature, pressure or flow measurement, for example into MARG sensors. Moreover, analog

17 sensors such as potentiometers and force-sensing resistors are still widely used. Applications include manufacturing and machinery, airplanes and aerospace, cars, medicine, robotics and many other aspects of our day-to-day life.

2.5.1 LM35 Temperature Sensor There are many types of temperature sensors, some of them maybe engage with the fire sensor unit, most of Arduino projects use the sensor lm35.

The LM35 as example in Figure 2.4 is one kind of commonly used temperature sensor that can be used to measure temperature with an electrical o/p comparative to the temperature (in °C).

Figure 2.4: LM35 Temperature Sensor

It can measure temperature more correctly compare with a thermistor. This sensor generates a high output voltage than thermocouples and may not need that the output voltage is amplified. The LM35 has an output voltage that is proportional to the Celsius temperature. The scale factor is .01V/°C.

18

2.5.2 DHT 11 Humidity & Temperature Sensor

DHT11 Temperature & Humidity Sensor features a temperature & humidity sensor complex with a calibrated digital signal output. By using the exclusive digital-signal-acquisition technique and temperature & humidity sensing technology, it ensures high reliability and excellent long-term stability. This sensor includes a resistive-type humidity measurement component and an NTC temperature measurement component, and connects to a high-performance 8-bit microcontroller, offering excellent quality, fast response, anti-interference ability and cost-effectiveness.

Figure 2.5: DHT humidity sensor

Each DHT11 element is strictly calibrated in the laboratory that is extremely accurate on humidity calibration. The calibration coefficients are stored as programs in the OTP memory, which are used by the sensor‟s internal signal detecting process. The single-wire serial interface makes system integration quick and easy. Its small size, low power consumption and up-to-20 meter signal transmission making it the best choice for various applications, including those most demanding ones. The component is 4-pin single row pin package. It is convenient to connect and special packages can be provided according to users‟ request. [12]. 19

2.5.3 Water sensor A water sensor for example Figure 2.6 is a device used in the detection of the water level for various applications. Water sensors are of several types that include ultrasonic sensors, pressure transducers, bubblers, and float sensors.

Figure 2.6: water sensor. 2.6 Bluetooth technology

Bluetooth is a wireless technology standard for exchanging data over short distances (using short-wavelength UHF radio waves in the ISM band from 2.4 to 2.485 GHz) from fixed and mobile devices, and building personal area networks (PANs). Invented by telecom vendor Ericsson in 1994, it was originally conceived as a wireless alternative to RS-232 data cables.

Bluetooth is managed by the Bluetooth Special Interest Group (SIG), which has more than 30,000 member companies in the areas of telecommunication, computing, networking, and consumer electronics. The IEEE standardized Bluetooth as IEEE 802.15.1, but no longer maintains the standard. The Bluetooth SIG oversees development of the specification, manages the qualification program, and protects the trademarks. A manufacturer must meet Bluetooth SIG standards to market it as a Bluetooth device. A network 20 of patents apply to the technology, which are licensed to individual qualifying devices.

2.6.1 Bluetooth module HC-06 The HC-06 presented in Figure 2.7 is a class 2 slave Bluetooth module designed for transparent wireless serial communication.

Once it is paired to a master Bluetooth device such as PC, smart phones and tablet, its operation becomes transparent to the user. All data received through the serial input is immediately transmitted over the air. When the module receives wireless data, it is sent out through the serial interface exactly at it is received. No user code specific to the Bluetooth module is needed at all in the user microcontroller program.

Figure 2.7: Bluetooth module HC-06

The HC-06 works with supply voltage of 3.6VDC to 6VDC, however, the logic level of RXD pin is 3.3V and is not 5V tolerant. A Converters recommended to protect the sensor if connect it to a 5V device (e.g. Arduino Uno and Mega) [12].

21

Chapter Three Methodology

3.1 Overview This research divided to two parts: Software implementation and hardware implementation. In software implementation android app is used to connect with the Arduino to gather information from sensors also to control the motor bump and fan for cooling .Arduino code is used to collect information from sensors and send it to the application. In hardware implementation sensors are used to collect the readings, motor bump is used for irrigation and the fan is used for cooling, all sensors and motors are attached to Arduino and perform specific algorithm.

3.2 Block Diagram of The System

Figure 3.1: Block diagram of the system

Figure (3.1) shows the block diagram of smart greenhouse adaptation and irrigation control system based on Arduino and android 22 application. The sensors are used to gather the information of the environment of the greenhouse to Arduino to send it via Bluetooth module and display the reading on the tablet, the motor bump used for irrigation and the fan for cooling. The user control the motor bump and fan via android application.

3.3 Flow Chart of The System

Figure 3.2: Block diagram of the system

Figure (3.2) shows the flow chart of smart greenhouse adaptation and irrigation control system based on Arduino and android application.

Firstly the serial connection between Arduino and android application installed on tablet must be established.

23

Then the Arduino reads the values comes from sensors and send the value of sensors to the application and also read the user command from application and executes them.

3.4 The system connection The connection between the android device and the Arduino is through the Bluetooth Module HC-06 bluetooth devices can communicate at ranges of up to 10 meters and they do not need to be in direct sight of each other. This makes bluetooth communication much more flexible and robust. It‟s also important to note that because bluetooth excels at low bandwidth data transfer, it is not intended as a replacement for high-bandwidth cabled peripherals. For high-bandwidth devices, such as external hard drives or video cameras, cables are still the best option. The heart of the bluetooth specification is the bluetooth protocol stack. By providing well-defined layers of functionality, the bluetooth specification ensures interoperability of bluetooth devices and encourages adoption of bluetooth technology. The characteristics of bluetooth technology-low cost, low power, and radio based- encouraged the concept of a personal area network (PAN). A PAN envelops the user in a small, mobile bubble of connectivity that is effortlessly available at any time. Bluetooth‟s freedom from cables and potential ubiquity make it ideal for carrying your personal network around with you.

3.5 Arduino sensor readings The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5volts/1024 units or, 0.0049 volts (4.9 mV) per unit. The input range and resolution can be changed using analog Reference ( ). 24

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

3.6 LM35 Temperature calculation The LM35 is a common TO-92 temperature sensor. It is often used with the equation Temp = (5.0 * analogRead (tempPin) * 100.0) / 1024; However, this does not yield high resolution. This can easily be avoided, however. The LM35only produces voltages from 0 to +1V. The ADC uses 5V as the highest possible value. This is wasting 80% of the possible range. If you change aRef to 1.1V, you will get almost the highest resolution possible. The original equation came from taking the reading, finding what percentage of the range (1024) it is, multiplying that by the range itself (aRef, or 5000 mV), and dividing by ten (10 mV per degree Celsius, according to the datasheet).

3.7 DHT11 Humidity calculation

The DHT11 sensor measures both temperature and humidity in the room. The working temperature is -40°C ... + 80°C and the humidity range is from 0-100%. The temperature has an accuracy of 0.5° C, and the humidity, 2%. Pin 2 of the sensor is connected to the 2 digital pin of the Arduino Uno board. Between 1 and 2 pins of the sensor it was connects a 10K pull-up resistance. Communication between Arduino Uno board and DHT11 sensor, is made via Max Detect 1 wire.

DHT22 is a digital sensor consisting of a thermistor (temperature measurement) and a capacitive sensor for determining the humidity [5]. DHT22 temperature & humidity sensor the voltage supply must be

25 between 3.3V and 6V (recommended 5V). Communication between Arduino Uno board ATMEGA328 microcontroller and DHT11 sensor is made through MaxDetect 1-wire. Calculation MaxDetect 1-wire: data consists of the integer part and decimal part. The formula is as follows:

DATA = 8 integer data bit RH + 8 decimal data bits RH + 8 data bits integer T + 8 decimal data bits T + 8 check-sum bit.

If the data is transmitted correctly, then check-sum should be: This sensor has a 4-pin :

- Pin 1 is a power pin

- Pin 2 is data pin

- Pin 3 is a NULL pin

- Pin 4 is a ground pin

Measuring humidity in the room. We obtained humidity of + 57, 6 RH. The Arduino receives 40 bits from the sensor: 16 RH data bits, 16 T data bits and 8 check-sum bits. Displayed data were calculated as follows:

0000 0010 0100 0000 0000 0000 1101 0001 10001 0011

- Humidity calculation:

Binary RH = 0000 0010 0100 0000 -> decimal RH = 576

RH = 576/10 = 57.6%

This type of measurement relies on two electrical conductors with a non- conductive film laying between them to create an electrical field between them. Moisture from the air collects on the film and causes changes in the voltage levels between the two plates. This change is then converted into a digital measurement of the air‟s relative humidity after taking the air temperature into account. Above figure can clear your 26 doubt. The DHT11 calculates relative humidity by measuring the electrical resistance between two electrodes.

The humidity sensing component of the DHT11 is a moisture holding substrate with the electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes while lower relative humidity increases the resistance between the electrodes.

The DHT11 converts the resistance measurement to relative humidity on a chip mounted to the back of the unit and transmits the humidity and temperature readings directly to the Arduino Uno.

3.8 Software implementation In software implementation, C programing language for Arduino used to program Arduino, and in the hardware implementation Arduino, smoke sensor, temperature sensor, speaker, fire sensor, liquid sensor, Bluetooth shield.

Arduino C used to program Arduino for analyzing the data and sent it to android Tablet to give appropriate sound instruction. The Android application will be programmed using MIT app inventor (tool developed by MIT to develop android application). The values of the sensors from the Arduino sent to the application to show the status of the factory. There are two main windows in App inventor 2

The first screen is designer screen

27

Figure 3.3: Designer screen

3.9 User interface The program is designed to give the user easy access to the system through the screens . App Inventor programs describe how the android should respond to certain events: a button is been pressed, the phone is being shacked; the user is dragging his finger over a canvas, etc. This specified by event handler blocks. First, I designed my interface layout (buttons,screen of status)

28

Figure 3.4: Android user interface

Firstly user should establish serial communication between Arduino and the android application. Then there are temperature label, humidity label and water level label to show the reading of sensor.

In the control part we have four bottoms to control motor bump and cooling fan associated with two labels to show the status of each one.

 Mounting the tablet

The tablet should be inside anti fire and anti-broken glass with high temperature resistance.

The tablet should be mounted like the following figure to give easy access.

29

Figure 3.5: Mounting of the tablet 3.10 Circuit Simulation

Figure 3.6: Simulation of system hardware circuit. Figure (3.6) shows the simulation of system hardware circuit. Simulation work probably

30

Chapter Four Result and Discussions

4.1 Android application interfacing result

Figure 4.1: User interface of android application

Figure (4.1) shows the user interface of the application which used to connect with Arduino to read data from Arduino and send commands to control motor bump an cooling fan.

4.2 Testing of Temperature Sensor Sensor of temperature tested in room temperature the readings are not regulated and not stable .

31

Figure 4.2: Temperature sensor readings

4.3 Testing of water sensor The water sensor tested in leak and worked successfully, the readings and connection of the sensor shown in figure 4.1 below.

Figure 4.3: Water sensor reading

32

4.4 Controlling via the application

(a)

(b)

(c) Figure 4.4: Readings in application and controlling motor bump and fan dc Figure (4.4) shows that the reading from sensors to Arduino will be sent via Bluetooth to the application so that the user could see the reading from the screen of the tablet.

33

When the user press the motor bump off or on bottom the motor will turn off or on and by pressing fan on or off the cooling fan will be turned on or off and the status will be displayed in the application. The result is shown from devices and sensors it represent the condition of weather and the environment adjacent to the sensors inside of the greenhouse so it must be considered in the calculations of designing system like this system to be aware of the changing in this conditions and the sensors efficiency and accuracy of readings to avoid more defects and errors happens while implementation of perfect systems should be designed perfectly from the beginning and for some want go so far and design more advanced version of this system it is good base information‟s.

34

Chapter Five Conclusion and Recommendations

5.1 Conclusion  A step-by-step approach in of smart greenhouse adaptation and irrigation control system based on Arduino and android application For measurement and control of the three essential parameters for plant growth i.e. temperature humidity and irrigation has been followed. The results obtained from the measurement have shown that the system performance is quite reliable and accurate.  The system has successfully overcome quite a few shortcomings of the existing systems by reducing the power consumption, maintenance and complexity, at the same time providing a flexible and precise form of maintaining the environment.  The continuously decreasing costs of hardware and software, the wider acceptance of electronic systems in agriculture, and an emerging agricultural control system industry in several areas of agricultural production, will result in reliable control systems that will address several aspects of quality and quantity of production. Further improvements will be made as less expensive and more reliable sensors are developed for use in agricultural production.

5.2 Recommendations The following improvements can be recommended for possible future work:

 More parameters can be detected such as soil moisture and co2 level as well other conditions may include such as shade and fire detection. 35

 Using different devices to monitor and control greenhouse environment such as PLCs.  To use solar system to reduce electricity usage.  Global System for Mobile Communication (GSM) and Short Message Service.  (SMS) can also be integrated into the system. These extra features will allow the system to directly alert the user of any abnormal changes in the greenhouse environment through the transmission of a simple short text message.  Connect the system with internet (IoT) for remote control.

36

References

References

[1]S.Thenmozhi1 &M.M.Dhivya2 &R.Sudharsan& K.Nirmalakumari , 2014," Greenhouse Management Using Embedded System and Zigbee Technology",International Journal of Advanced Research in Electrical, Electronics and Instrumentation Engineering, Vol. 3, Issue 2, 3. [2] Determining heating pipe temperature in greenhouse using proportional integral plus feed-forward control and radial basic function neural-networks, Yuet al. / J Zhejiang Univ SCI 2005 6A(4):265-269.

[3] Uk Controlled Environment Users' Group 2002 Scientific Meeting “The glasshouse Environment”.

[4] Principles of Evaluating Greenhouse Aerial Environments- Part 1 of 3-Agricultural and Biological Engineering- Penn state university. [5] Canada Plan Service, M-6704. [6] Environmental Control of Greenhouses, Professor Emeritus W.J. Roberts (Originally published in June 1997, revised in 2005) . [7] Horticultural Engineering- Volume 17 No. 5, October 2002. [2] Yuxin Jing, Letian Zhang, Irwin Arce, Aydin Farajidavar " An Android Remote Control Car Unit for Search Missions " 2014. [8] Programming Arduino Getting Started with Sketches". McGraw-Hill. Nov 8, 2011. Retrieved 2013-03-28. [9] Edwards, Robert (1987). "Optimizing the Zilog Z8 Forth Microcontroller for Rapid Prototyping" (PDF). Martin Marietta: 3. Retrieved 9 December 2012.

[10] Pritchard, Stephen (1 March 2012). "Raspberry Pi: A BBC Micro for today's generation". ITPRO. Retrieved 15 March 2012. [11] Arduino. Arduino introduction. 2014 [cited 2019 21 September]; Available from:https://www.arduino.cc/en/guide/introduction.And https://www.arduino.cc/en/Main/Products. [12] Herman, Stephen. Industrial Motor Control. 6th ed. Delmar, Cengage Learning, 2010. Page 251.

40

Appendices

Appendix A: Arduino code

#include #include LiquidCrystal lcd( 13, 11, 10, 9 ,8,7); #define DHTPIN 2 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); int temmin=25; int temmax=35; int hummin=30; int hummax=55; String WATER_STATUS; String MOTOR_STATUS; String FAN_STATUS; long int TEM_IN; float TEM_VALUE; void setup() { pinMode(2,INPUT); pinMode(3,INPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); Serial.begin(9600); lcd.begin(16, 2); dht.begin(); } void loop() { String appcommand = Serial.readString(); // Read humidity int HUM = dht.readHumidity(); TEM_IN=analogRead(0); TEM_VALUE=map(TEM_IN,0,1023,0,500); // Check if any reads failed and exit early (to try again) if (isnan(HUM)) { lcd.clear(); lcd.setCursor(5, 0); lcd.print("Error"); return; } // CHECK WATER STATUS if (digitalRead(3)==0){ WATER_STATUS = "Water not full"; } else {

A-401

WATER_STATUS = "Water is full"; } //CHECK FAN STATUS if (TEM_VALUE>=temmax || appcommand=="fan on" ){ digitalWrite(5,HIGH); FAN_STATUS = "FAN TURN ON";} else {if (TEM_VALUE<=temmin || appcommand=="fan off"){ digitalWrite(5,LOW); FAN_STATUS = "FAN TURN OFF";} } // CHECK MOTOR STATUS if (digitalRead(3)==1 || (TEM_VALUE<=temmin && HUM >= hummax ) || appcommand=="motor off"){ digitalWrite(4,LOW); MOTOR_STATUS = "MOTTOR TURN OFF "; } else { if((digitalRead(3)==0 && HUM <= hummax && TEM_VALUE>=temmax) || appcommand=="motor on") digitalWrite(4,HIGH); MOTOR_STATUS = "MOTOR TURN ON"; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("T:"); lcd.print(TEM_VALUE); lcd.print("C"); lcd.setCursor(8, 0); lcd.print(" H:"); lcd.print(HUM); lcd.print("%"); lcd.setCursor(0, 1); lcd.print(WATER_STATUS); Serial.print(TEM_VALUE); Serial.print("C"); Serial.print("|"); Serial.print(HUM); Serial.print("%"); Serial.print("|"); Serial.print(WATER_STATUS); Serial.print("|"); Serial.print(MOTOR_STATUS); Serial.print("|"); Serial.print(FAN_STATUS); }

AA.1-2

Appendix B: MIT app inventor code

A. Bluetooth connection initialization

BA.1-1

B. Receive data from Arduino via Bluetooth

B-A.12

C. Send commands to Arduino via Bluetooth

D. Close the application

BA.1-3