Site Loader
Order Essay
111 Town Square Pl, Jersey City, NJ 07310, U.S.
111 Town Square Pl, Jersey City, NJ 07310, U.S.

DECLARATION OF ORIGINALITY
FACULTY/ SCHOOL/ INSTITUTE: Engineering
DEPARTMENT: Electrical and Information Engineering
COURSE NAME: Bachelor of Science in Electrical & Electronic Engineering
TITLE OF NAME OF STUDENT: Mwai Eric Kabuitu
REGISTRATION NUMBER: F17/1597/2013
COLLEGE: Architecture and Engineering
PROJECT TITLE: A SENSOR BASED AUTOMATIC IRRIGATION CONTROL SYSTEM
I understand what plagiarism is and I am aware of the university policy in this regard.

I declare that this final year project report is my original work and has not been submitted elsewhere for examination, award of a degree or publication. Where other people’s work or my own work has been used, this has properly been acknowledged and referenced in accordance with the University of Nairobi’s requirements.

We Will Write a Custom Essay Specifically
For You For Only $13.90/page!


order now

I have not sought or used the services of any professional agencies to produce this work.

I have not allowed, and shall not allow anyone to copy my work with the intention of passing it off as his/her own work.

I understand that any false claim in respect of this work shall result in disciplinary action, in accordance with University anti-plagiarism policy.

Student
Signature: ………………………………………………………………………………………
Date: ……………………………………………………………………………………………
Supervisor:
Signature: ………………………………………………………………………………………
Date: ……………………………………………………………………………………………
DEDICATION
This project is dedicated to my mum and late dad for their selfless support to reach this academic milestone.

ACKNOWLEDGEMENT
First, I would like to acknowledge the Almighty God for his grace and strength to prepare this work.

Special appreciation to my supervisor, Prof. Oduol for the valuable advice that guided me immensely throughout my project work.Sincere thanks also goes to the Department of Electrical and Information Engineering and all my lecturers in the University of Nairobi including the supporting staff for the impact they have had to my life and also for providing the conducive and enabling environment for learning.

Finally, I extend my appreciation to my family and friends for the support they offered me during my study at the University.

I also dedicate gratitude to Mr. and Mrs. Gichuki for their support during my study at the university and the preparation of this project.

LIST OF ABBREVIATIONS
SMS –Soil Moisture Sensor
VWC -Volumetric Water Content
TDR -Time Domain ReflectometryFDR -Frequency Domain ReflectometryRDAC -Resistive Digital-To-Analog Converters
PIC -Programmable Interface Controllers
LCD-Liquid crystal Display
ADC-Analog to Digital Converter
DAC –Digital to Analog Converter
LED-Light Emitting Diode
SPST -Single Pole Single Throw
SPDT – Single Pole Double Throw
DPST -Double Pole Single Throw
PCB –Printed Circuit Board
ABSTRACT
Farming of crops usually has a big challenge in achieving the optimum soil moisture for a particular crop. Overwatered crops may suffer from leaf scorch as the roots die from suffocation. This is because water logged soils do not have enough air spaces thus limited oxygen for the plant roots. Overwatering also means that the plant become weakened to withstand a dry spell.
The aim of this project is to design and implement a low cost automated control system applicable to the Kenyan farms.

The objective is to control the water pump automatically and direction of water flow depending on the water moisture levels detected by the sensors
The information from the sensors is received on an arduino development board a programmed “Atmega-328” microcontroller gives the control commands depending on the soil moisture levels. The system operation status such as whether the motor is on and moisture level percentages should also be sent to the farmer remotely on his mobile phone and concurrently displayed on an LCD display on the farm.

TOC o “1-5” h z u 1.INTRODUCTION PAGEREF _Toc520135637 h 11.1Brief Background PAGEREF _Toc520135638 h 11.2Problem statement PAGEREF _Toc520135639 h 11.3Main objectives PAGEREF _Toc520135640 h 11.4Project justification PAGEREF _Toc520135641 h 21.5Project scope PAGEREF _Toc520135642 h 21.6Project organization PAGEREF _Toc520135643 h 22LITERATURE REVIEW PAGEREF _Toc520135644 h 32.1Types of irrigation PAGEREF _Toc520135645 h 32.1.1Ditch Irrigation PAGEREF _Toc520135646 h 32.1.2Terrace Irrigation PAGEREF _Toc520135647 h 32.1.3Drip Irrigation PAGEREF _Toc520135648 h 32.1.4Sprinkler irrigation PAGEREF _Toc520135649 h 42.1.5Rotary Systems PAGEREF _Toc520135650 h 42.2Sensors PAGEREF _Toc520135651 h 42.2.1Soil moisture sensors PAGEREF _Toc520135652 h 42.2.2Soil Moisture calculation PAGEREF _Toc520135653 h 52.2.3types of soil moisture sensors PAGEREF _Toc520135654 h 62.2.3.1Electrical resistance blocks Sensors PAGEREF _Toc520135655 h 62.2.3.2Electrical conductivity probe sensors PAGEREF _Toc520135656 h 82.2.3.3Dielectric sensors PAGEREF _Toc520135657 h 92.2.3.4Capacitance sensors PAGEREF _Toc520135658 h 92.2.3.5Time Domain Reflectometry (TDR) sensors PAGEREF _Toc520135659 h 92.2.3.6Heat dissipation sensors PAGEREF _Toc520135660 h 112.2.3.7Tensiometer Sensors PAGEREF _Toc520135661 h 112.2.3.8YL-69 Moisture Sensor PAGEREF _Toc520135662 h 132.2.3.8.1LM393 comparator PAGEREF _Toc520135663 h 162.2.4Sensor Selection PAGEREF _Toc520135664 h 192.2.5Sensor Calibration PAGEREF _Toc520135665 h 212.3Microcontroller PAGEREF _Toc520135666 h 212.3.1Types of Microcontrollers PAGEREF _Toc520135667 h 222.3.1.18051 PAGEREF _Toc520135668 h 222.3.1.2Programmable Interface Controller (PIC) PAGEREF _Toc520135669 h 222.3.1.3AVR: PAGEREF _Toc520135670 h 222.3.1.4Arduino PAGEREF _Toc520135671 h 242.3.2Types of arduino boards PAGEREF _Toc520135672 h 242.3.2.1Legacy Versions PAGEREF _Toc520135673 h 242.3.2.2Arduino Mega 2560 PAGEREF _Toc520135674 h 272.3.2.3Arduino LilyPad PAGEREF _Toc520135675 h 272.3.2.4Arduino Mega ADK PAGEREF _Toc520135676 h 272.4Liquid Crystal Display (LCD) PAGEREF _Toc520135677 h 292.5Automatic switching circuits PAGEREF _Toc520135678 h 302.5.1The Triac Switching circuit PAGEREF _Toc520135679 h 302.5.2Relay switching circuit PAGEREF _Toc520135680 h 322.6Remote Communication PAGEREF _Toc520135681 h 352.6.1SIM800L GSM / GPRS MODULE PAGEREF _Toc520135682 h 352.6.1.1Module pin-out PAGEREF _Toc520135683 h 363SYSTEM DESIGN AND IMPLEMENTATION PAGEREF _Toc520135684 h 373.1Hardware Design PAGEREF _Toc520135685 h 373.1.1Control Unit: ATMega328 microcontroller on arduino platform PAGEREF _Toc520135686 h 373.1.2Sensing Unit: PAGEREF _Toc520135687 h 383.1.2.1YL-69 soil moisture sensor arduino interface PAGEREF _Toc520135688 h 383.1.3The Dc pump and valve interface with the arduino PAGEREF _Toc520135689 h 403.1.4The Power supply PAGEREF _Toc520135690 h 413.1.5The GSM module (SIM800L)- arduino interface PAGEREF _Toc520135691 h 433.1.6Final circuit assembly PAGEREF _Toc520135692 h 433.2Software Design PAGEREF _Toc520135693 h 463.2.1Program Pseudo code PAGEREF _Toc520135694 h 464RESULTS ANALYSIS AND DISCUSSIONS PAGEREF _Toc520135695 h 484.1Results PAGEREF _Toc520135696 h 485CONCLUSION AND RECOMMENDATIONS PAGEREF _Toc520135697 h 505.1CONCLUSION PAGEREF _Toc520135698 h 505.2RECOMMENDATIONS PAGEREF _Toc520135699 h 505.3Cost Analysis PAGEREF _Toc520135700 h 506REFERENCES PAGEREF _Toc520135701 h 527APPENDIX PAGEREF _Toc520135702 h 537.1Microcontroller code PAGEREF _Toc520135703 h 53
TOC h z c “Figure” Figure 21 Home-made soil moisture sensor PAGEREF _Toc520128709 h 7Figure 22 Schematic of an electrical resistance block and meter PAGEREF _Toc520128710 h 8Figure 23 Diagram of a tensiometer PAGEREF _Toc520128711 h 12Figure 24 Tensiometer installation PAGEREF _Toc520128712 h 12Figure 25YL-69 Sensor PAGEREF _Toc520128713 h 13Figure 26 YL-69 PCB PAGEREF _Toc520128714 h 14Figure 27Digipot schematic PAGEREF _Toc520128715 h 14Figure 28 P3362 Electronic potentiometer PAGEREF _Toc520128716 h 16Figure 29 Operational amplifier PAGEREF _Toc520128717 h 16Figure 210 LM 393 Comparator PAGEREF _Toc520128718 h 18Figure 211LM393 pin configuration PAGEREF _Toc520128719 h 18Figure 212 Installation of flat probe SMS PAGEREF _Toc520128720 h 20Figure 213 Different types of arduino PAGEREF _Toc520128721 h 26Figure 214 Parts of arduino uno PAGEREF _Toc520128722 h 26Figure 215 Atmega 328 microcontroller pin configuration PAGEREF _Toc520128723 h 27Figure 216 LCD (16X2) PAGEREF _Toc520128724 h 29Figure 217 Figure 2.18 The TRIAC PAGEREF _Toc520128725 h 32Figure 218 5VDC Coil Relay PAGEREF _Toc520128726 h 33Figure 219 Inside a SPST relay PAGEREF _Toc520128727 h 34Figure 220 Simple relay interfacing PAGEREF _Toc520128728 h 34Figure 221sim800l module PAGEREF _Toc520128729 h 35Figure 222 module pinout PAGEREF _Toc520128730 h 36Figure 31Arduino Uno PAGEREF _Toc520128731 h 37Figure 32 lcd pin connections to arduino PAGEREF _Toc520128732 h 40Figure 33 motor and valve switching PAGEREF _Toc520128733 h 41Figure 34 power supply circuit PAGEREF _Toc520128734 h 42Figure 35 SIM800L arduino interface PAGEREF _Toc520128735 h 43Figure 36 final design PAGEREF _Toc520128736 h 44Figure 37 Components final assembly PAGEREF _Toc520128737 h 45Figure 41 watering when moisture is low(sensors out of water) PAGEREF _Toc520128738 h 48Figure 42 soil moisture optimum PAGEREF _Toc520128739 h 49Figure 43 pump OFF for soggy soil condition PAGEREF _Toc520128740 h 49
INTRODUCTIONBrief BackgroundKenya continues to be food insecure despite decades of efforts to improve our food production. This is compounded by the fact that the population growth far outstrip the growth in our food production. This slow growth has been blamed on limited mechanization and application of current emerging technologies among other challenges.

This has seen the agricultural sector employing about 75% of the total workforce yet accounting for only 32% of the total GDP. This is in contrast to food secure countries employing technology and mechanization where the agricultural sector often employ less than 5% of the total workforce.

Kenya has an arable land of 10.19%of the total land mass (as of 2015), which is still affected by the changing climate thus unpredictable rains are now common. This means Kenyan farms need to move to mechanized irrigation applying latest technology and innovation for higher yields.

Problem statementEach crop has a specific optimum moisture requirement, this is often a major hindrance to optimum output of a crop. The water resource a Kenyan farms is also scarce as many farmers largely depend on rainfall which is unpredictable thus the limited water should be used economically.

The aim of this project is to water the crops to just the right amount of moisture content per crop and in the most economical irrigation method.
Main objectivesThe designed system should read moisture levels in the soil and give control commands depending on the moisture levels. If the moisture is below a certain threshold for a crop, the pump is turned on and the land watered up to the optimum level ensuring no overwatering. This means the system should continuously read moisture levels during the watering process.
The farm operations should also be displayed and concurrently sent remotely via text message to the farm manager.
Project justificationKenya agricultural sector employs about 75% of the total workforce yet accounting for only 32% of the total GDP. This is in contrast to food secure countries employing technology and mechanization where the agricultural sector often employ less than 5% of the total workforce.

Kenya has an arable land of 10.19%of the total land mass (as of 2015), which is still affected by the changing climate thus unpredictable rains are now common.

To achieve higher yields with the current resources, innovation is a key ingredient this this project aims to offer a very economical mode of irrigation to Kenyan farms.

Irrigation automation solves the challenge brought about by the unreliability of climate changes thus need for water optimization. Automation of the irrigation systems is one of the most convenient, efficient and effective method of water optimization. The systems helps in saving water and thus more land can be brought under irrigation. Crops grown under controlled conditions tend to be healthier and thus give more yields.

Project scopeThis project entails the design and implementation of the automated irrigation system. Soil moisture sensors will act as the inputs a microcontroller which will process the information and give the control commands to the actuators. The actuators will be a water pump and valve controlled through the relay module. Display and notification of operations will also be a key ingredient this an LCD screen will be in use to display and a GSM module to remotely send the information to the user.
Project organizationThis project report is organized into five chapters:
Chapter one gives the introduction to the project, the project objectives and the scope.

Chapter Two is the literature review which describes the system and the components used in the design.

Chapter Three gives the technical description of the project design.

Chapter Four analyses and discusses the project
Chapter Five gives the conclusion of the whole project, if the objective and scope of the project were achieved. This chapter also includes appendices and the references used
LITERATURE REVIEWTypes of irrigationDitch IrrigationDitch Irrigation is a rather traditional method, where ditches are dug out and seedlings are planted in rows. The plantings are watered by placing canals or furrows in between the rows of plants. Siphon tubes are used to move the water from the main ditch to the canals.

Terrace IrrigationThis is a very labor-intensive method of irrigation where the land is cut into steps and supported by retaining walls. The flat areas are used for planting and the idea is that the water flows down each step, while watering each plot. This allows steep land to be used for planting crops.   
Drip IrrigationThis is one of the most effective and efficient method of irrigation as water is dripped at the crop root zone. The method saves water from runoff and evaporation.

Sprinkler irrigationThis method uses overhead sprinklers. Each sprinkler irrigates a given area. During installation care should be taken to avoid over or under watering some areas. If poorly installed a lot of water is wasted via runoff.

Rotary SystemsThis is an improvement of sprinkler irrigation method where sprinklers are mechanically moving in a rotary/circular manner. This method is best suited for huge tracks of land. This method is more efficient than the basic sprinkler method.

This project presents a microcontroller based irrigation system which monitor and control the soil moisture content so as to optimize the application of water. Good water balance leads to maximum crop production. The system presented automates irrigation systems with the use of low cost sensor, microcontroller and the simple circuitry, thereby making it a low cost.

SensorsA sensor is a device that detects and measures a physical quantity from the environment and converts it into an electronic signal. The physical quantity could be moisture, temperature, motion, light or any other physical phenomenon. Examples of sensors include: oxygen sensors, temperature sensors, infra-red sensors, humidly sensors, soil moisture sensors and motion detection sensors. The output of the sensors is usually charge, current or voltage. Of interest in this paper is the soil moisture sensor. 4
Soil moisture sensorsA soil moisture sensor is a device that measures the volumetric water content (VWC) of soil. Mathematically VWC, ?, is given as follows;
1905014033500
Equation 1: mathematical representation of VWC
Where: Vw is the water volume and VTis the total volume (soil volume + water volume).

Soil moisture sensors are classified according to how they measure the soil moisture content.

Soil Moisture calculationTwo methods are used in determining the volumetric water content (VWC); direct and indirect. The direct method entails drying a known volume of soil in an oven and weighing it. 4The direct method of measuring VWC is done using the following mathematical notation:
93345091440000
Equation 2 Soil Moisture calculation
Where:
Mwet is soil sample before drying in the oven
Mdry is soil sample after drying in the oven
?w is water density
Vb is the volume of soil sample before drying
Indirect method is based on correlating soil physical and chemical properties with water content. Three techniques are used in this method namely: chemical titrations, geophysical sensing and satellite remote sensing.

Chemical titration determines the moisture loss in sample soil after freeze drying or heating. Satellite remote sensing uses microwave radiation to check on the difference in dielectric properties of dry and wet soils. Geophysical sensing uses physical devices which are inserted in the soil to determine the soil moisture content. Techniques used in this method include: electrical resistance, electrical conductivity, soil dielectric, soil tension, TDR, FDR, soil capacitance among others.

types of soil moisture sensorsElectrical resistance blocks SensorsThese sensors are made up of two electrodes made from a porous substance like sand ceramic mixture or gypsum. The two electrodes are imbedded in the soil during installation. 4 Moisture is allowed to move freely in and out of the sensors electrodes as the soil becomes moist or dries up. The resistance of the electrodes to the flow current is correlated with moisture content. To measure this resistance the electrodes are biased (energized) with a dc voltage and the current flowing through them measured. Applying Ohm’s law;
R=V/I
Where: R is resistance (Unknown) (?)
V is biasing voltage (3.3V to 5.0V)
I is the current flowing through the electrodes (Amps)
93345021971000
Figure 21 Home-made soil moisture sensorWhen the moisture content in the soil is high more current will be allowed to flow thus indicating low resistance. On the other hand for dry soils the sensor will indicate higher resistance portrayed by the low current reading.

This type of sensor is cheap and readily available. Electrical resistance blocks Sensors can also be readily assembled from home using two metal plates or steel nails.

Electrical resistance blocks Sensors are mostly used in small projects and gardens due to the following disadvantages;
They are badly affected by soil PH and salinity thus requiring regular maintenance
They have low sensitivity.

The electrodes; especially which provides a constant source of ions; do not dry at the same rate as the soil surrounding it.

190501905000
Figure 22 Schematic of an electrical resistance block and meterElectrical conductivity probe sensorsElectrical conductivity probes employ the same principle as the Electrical resistance blocks Sensors. The one major difference between the two types of sensors is that Electrical conductivity probes sensors have their electrodes/probes in direct contact with the soil. 4
By definition electricity is the flow of charges and water in its pure form cannot conduct electricity. The amount of impurities in water and mineral salts make it polar thus able to conduct electricity. A large volume of water will mean more ions and thus better electric conduction. Electrical conductivity probes sensors takes advantage of this phenomenon. 4
The amount of current passing between the probes is directly proportional to the soil moisture content. Moist soil allow more current to flow between the probes while drier soils only allow a little current to flow between the probes. Better conductivity indicates a lower electrical resistance.

Most of the soil moisture sensors currently in the market especially for small projects are Electrical conductivity probes sensors. They have the following advantages.

They are cheap
They are readily available
Easy to calibrate and install
Dielectric sensorsDielectric sensors measure the soil water content in the soil by measuring the dielectric permittivity of the soil. A dielectric material is substance that does not conductor electricity, but supports electrostatic field s efficiently. At some cases dielectric substance are referred to as insulators. The volume of water in the soil influences the dielectric permittivity of soil. 4The dielectric of water which is 80.4 is greater than other soil constituents. Therefore change in the amount of water in the soil will directly lead to change in the soil dielectric permittivity.

Dielectric sensors are very complex to build thus making them very expensive. These sensors are mostly used in scientific research owing to their high accuracy and cost
Dielectric sensors are classified into two types namely: Capacitance sensors and Time Domain Reflectometry (TDR) sensors. These sensors do not measure electrical conductivity while measuring soil moisture. 7
Capacitance sensorsCapacitance sensors use frequency domain reflectometry (FDR).Frequency domain reflectometry is the measure of signal reflections through a medium across frequency. Capacitance sensors contain two electrodes which are separated by a dielectric material.

The soil becomes the dielectric component after the electrodes are inserted into the soil; it could even be inserted into the access tube in the soil to achieve the same results. A high oscillating frequency is thereafter applied to the electrodes to induce a resonant frequency. The magnitude of the resonant frequency is dependent on the dielectric constant of the soil which in turns depends on or can change to the soil’s moisture content. The change of the frequency as a result of the soil’s moisture content is converted into the measurement of the soil moisture.

Time Domain Reflectometry (TDR) sensorsTime Domain Reflectometry uses the principle of waveguides. The actual content of water in the soil is measured under this technology and not the water potential.7 The TDR device sends signals to the rods inserted in the soil. The time required for an electromagnetic signal to travel
along the wave guide is measured. The rate at which the send signal returns is used to measure the water content in the soil. The return rate is dependent on the dielectric properties of the soil. The signal takes longer time in moisture soils and shorter time in dry soil. This pulse signal is then converted into soil moisture measurement. 4 TDR sensors give accurate readings faster and require very little maintenance. The major disadvantage of TDR sensors is that they require they require different calibrations depending on different soil types.

Heat dissipation sensorsHeat dissipation sensors measure the soil moisture content by measuring the amount of heat dissipated from a medium which is of ceramic kind in most cases. The water contained in the medium spaces is directly proportional to the heat dissipated from the medium. 8The less the water contained in the medium the less the heat dissipated and more heat is dissipated if the water contained in the medium is high. More heat dissipated leads to lower reading on the sensor and less heat dissipated leads to higher reading on the sensor.

The sensor uses the principle of capillarity. Capillary forces influence movement of water between the sensor medium and the surrounding soil. Heat dissipation sensors are independent of soil salinity thus not affected by soil type. They require minimum or no calibration at all. On the downside this type of sensors are very expensive.

Tensiometer SensorsTensiometers sensors measure the soil moisture content in the soil by measuring the moisture tension/suction in the soil. Tensiometers sensors is made up of two major parts; a plastic tube which has a ceramic porous medium at its tip and a vacuum gauge on the opposite end. 7
During installation the ceramic tip is buried in the soil at the calibrated depth which should be as near as possible to the plants root area. The vacuum gauge measures the effort the plants roots have to put to extract water from the soil.4This is the measure of the soil measure tension which is measured in centibars.

93345091440000
Figure 23 Diagram of a tensiometerIf the soil moisture content is low the roots work harder to extract water from the soil. The reading on the sensor is high. When water is more available in the soil the roots works less and thus lower reading is indicated on the sensor.8
1905013716000
Figure 24 Tensiometer installationYL-69 Moisture SensorThis is an Electrical resistance Sensor. The sensor is made up of two electrodes. This soil moisture sensor reads the moisture content around it. A current is passed across the electrodes through the soil and the resistance to the current in the soil determines the soil moisture. If the soil has more water resistance will be low and thus more current will pass through. On the other hand when the soil moisture is low the sensor module outputs a high level of resistance. 7This sensor has both digital and analogue outputs. Digital output is simple to use but is not as accurate as the analogue output.

9525013462000
Figure 25YL-69 SensorYL-69 soil moisture sensor has the following specifications: 7
Vcc power supply 3.3V or 5V
Current 35mA
Signal output voltage 0-4.2V
Digital Outputs 0 or 1
Analog Resistance (?)
Panel Dimension 3.0cm by 1.6cm
Probe Dimension 6.0cm by 3.0cm
GND Connected to ground
Table 21 YL-69 specifications
The sensor comes with a small PCB board fitted with LM393 comparator chip and a digital potentiometer.

190501460500
Figure 26 YL-69 PCBDigital potentiometer
A potentiometer is basically a variable resistor. Like analog potentiometers, digital potentiometers are used to scale or adjust resistance of a circuit. 7 Digital potentiometers are also known as a digital pot or digipot. Digipots are used mostly in scaling analog signals to be used in a microcontroller.

24765027051000
Figure 27Digipot schematicDigipot output resistance is variable based on digital inputs and thus also know as resistive digital-to-analog converters (RDACs). Some RDACs come with nonvolatile memory thus
provide wiper setting retention after a power ON to OFF cycle. Digipots are available as integrated circuits (ICs).

2476501460500
Figure 28 P3362 Electronic potentiometerOn the soil moisture sensor the digital potentiometer acts as a low resolution digital to analog convertor (DAC) thus adjusting it varies the sensitivity of the sensor.

LM393 comparatorA compactor is an electronic device that compares two voltages or currents and gives a digital signal as the output. It indicates which of the two compared quantities is large. A comparator has a least two input pins and one output pin. Operational amplifier operating in open loop configuration and without negative feedback can be used as a simple comparator.

24765027178000
Figure 29 Operational amplifierOne of the most commonly used comparators is LM393. It is available as an IC.

116205091440000
Figure 210 LM 393 ComparatorIt is preferred due to the following characteristics: 7
? Supply Voltage (2.0 to 36.0) V
? Supply Single or dual (±1.0 to ±18.0) V
? Current drain 0.4 mA
? Biasing current 25 nA? Offset current ± 5 nA? Saturation Voltage ± 3 mV
? Compatibility TTL, DTL,ECL, MOS and CMOS logic
Systems
? Differential input voltage range Same as power supply voltage
Table 22 LM 393 Comparator specifications
24765021590000
Figure 211LM393 pin configurationLM393 finds application in limit comparators, simple ADC, time delay generators and square wave generators among others. The capability of LM393 to interface with low power drain is an advantage over other types of comparators.

Sensor SelectionWhen deciding on which sensor to use the following factors should be put into consideration:
48
Price: This is the most important parameter when selecting any component. The price of the sensor will ultimately affect the price of the whole system as this is one of the major system modules. Sensor with the most competitive price should be chosen.

Power: In any electrical system power efficiency is critical. Moisture sensor will low power consumption should be selected. Sensors which can be battery powered can be used in areas without electricity connection.

Technology: Technology used to design sensor dictate the sensitivity, cost and durability of the sensors. Most low cost sensors have poor sensitivity, rust and corrode over time. Resistive or conductive sensors which are affected by soli salinity thus have a short life.

Shape: Long and slender sensors can be used in many applications than bulky ones.

Durability: Soil moisture sensor which are not affected by soil salinity, corrode or rust should be selected. Soil moisture sensor probes that measure conductivity or resistance should be avoided, since they will wear out over time.

Accuracy and Linearity: A quality soil moisture sensor probe should give an output which is proportional to water content over the full output range. In addition, the soil moisture sensor probe should have a good output range to reduce sensitivity to noise.

Voltage Range: Choose a sensor that has a big supply voltage range. Powering a sensor with the wrong voltage will damage the sensor or give inaccurate results.

Sensor Installation
Sensors orientation and installation depends on the sensor type, size and shape (flat, node, and rod). Installation should be guided by the manufacturer’s installation manual. But in general the sensor should be installed as close to the root area as possible. 4
On new fields; the SMS should be installed prior to planting crops. The sensor should be installed at approximately 3 inches deep. For existing fields trenches are dug at uniform intervals and SMS installed.8
1905013652500
Figure 212 Installation of flat probe SMSFlat sensor probes are commonly found in two types and typically use TDT technology. These are the Exposed wave guides and the Encased wave guides. Both of these sensor types are installed horizontally. 7
Node probes type soil moisture sensors are usually installed vertically around the root area.

Granular Matrix technology is typically used in this SMS type.

1905021844000
Figure 2.13. SMSs with node probes installation
For rod type probes SMSs; the probes are installed inclined at 450 to the ground to allow the probes to the read moisture content from the root zone. TDR technology is typically used in this class of sensors. SMSs should be installed away from structures, tree canopy, construction roads and plant debris.

Sensor CalibrationAs is the case of sensors installation, sensor calibration should also be done in line with the manufacturer’s specifications. Different sensors have different calibration procedures. Development stage of the plants roots also determines the SMSs calibration. 7 The soil type and crops water requirements greatly influence the sensors calibration.

Dry soil 0 ~300
Humid soil 300~700
In water(soil soggy) 700~950
Table 2-3. YL-69 sensor value description
Maintenance
The technology used to design the sensors determines the regularity of maintenance. Electric resistance and conductance sensors tend to corrode with time and thus require regular maintenance and replacement. TDT and TDR sensors are the most stable and durable thus requiring minimum maintenance.

MicrocontrollerA microcontroller is a single on chip computer which includes number of peripherals like RAM, EEPROM, Timers etc., required to perform some predefined task. 1 There are different microcontroller families including: 8051, PIC (Programmable Interface Controller) and AVR. Microcontrollers are used in digital applications as control units. 3 Some microcontrollers come with their in-build circuits like Analog to digital convertors or digital to analog convertors.

Microcontrollers are mostly programmed using assembly language but in recent years high level languages like C, C++ PASCAL and java have been used. 5 High level programming of microcontrollers brings the advantage of not having a different program for each microcontroller manufacturer. High level programming is also neat, easy to document and maintain and user friendly.

Types of Microcontrollers8051These are among the earlier microcontrollers to be fabricated. Due to superiority in technology in the newer versions, very few companies still fabricate 8051. Earlier types of 8051 have 12 clocks per instruction whereas the newer versions have 6 clocks per instruction. 8051 microcontroller does not have an in built memory bus and ADC. First 8051 microcontroller to be fabricated with Harvard architecture was done in 1980 by Intel. 1
Programmable Interface Controller (PIC)Programmable Interface Controllers are commonly referred to as PIC. PICs are slightly older than 8051 microcontrollers. PICs are preferred to 8051 because of their small low pin count devices. PICs perform better and are affordable than 8051. 3 The Microchip technology fabricated the single chip microcontroller PIC with Harvard architecture. The only major downside of PIC is its programming part is very tedious. PICs are hence not recommended for beginners.

AVR:In 1996, Atmel fabricated this single chip microcontroller with a modified Harvard Architecture. This chip is loaded with C- compiler and a free IDE. Like PIC, AVR microcontrollers are difficult for the beginners to work with. AVR microcontroller has on-chip boot-loader thus AVR can be programmed easily without any external programmer. 3 AVR controllers has number of I/O ports, timers/counters, interrupts, A/D converters, USART, I2C interfaces, PWM channels, on-chip analog comparators.8
ArduinoArduino is an open-source electronics design platform. The Arduino board is specially designed for programming and prototyping with Atmel microcontrollers. 5 An arduino interacts with physical world via sensors. Using arduino; electric equipments can be designed to respond to change in physical elements like temperature, humidity, heat or even light. 5 This is the automation process. For example, reading a humidity sensor and turning on and off of an automatic irrigation system. There several types of arduino boards.

The open-source Arduino environment allows one to write code and load it onto the Arduino board’s memory. The development environment is written in Java and based on Processing, AVR-GCC, and other open source software. 5 The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment. The arduino software is published as open source tools, available for extension by experienced programmers. The language can be expanded through C++ libraries, and people wanting to understand the technical details can make the leap from Arduino to the AVR C programming language on which it’s based. Similarly, AVR-C code can be added directly into the Arduino programs if one so wishes.5
Types of arduino boardsLegacy VersionsArduino legacy versions include Arduino NG, Diecimila, and the Duemilanove. These arduinos use ATMEGA168 chips. They require manual selection of either USB or battery power.5 For Arduino NG one is required to hold the rest button on the board for a few seconds before uploading a program on to it.

93345091440000
Figure 213 Different types of arduinoArduino Uno
This is the most common arduino type. This arduino type uses ATmega328 AVR microcontroller.

190501333500
Figure 214 Parts of arduino unoATmega328 is more preferred due to the following features:
Have three 8-bit bi-directional I/O ports with internal pull-up resistors.5
32K Bytes of flash memory.

1K Bytes EEPROM
2K Bytes of RAM
2 instruction words/vector.

8-channel 10-bit successive approximation ADC
Programmable Serial USART
23 Programmable I/O Lines
Operating Voltage 1.8 – 5.5Ve.t.c
190509271000
Figure 215 Atmega 328 microcontroller pin configurationArduino Mega 2560This is regarded as an advancement of arduino uno. It has more memory than arduino uno. It has a total of 54 input pins of which 16 are analog inputs. It has a larger PCB board than arduino. Overall it is more powerful than arduino uno. This arduino board is based on ATmega2560. 5
Arduino LilyPadThis arduino board is designed for wearable applications. It is usually sewn on fabric. This board requires the use of a special FTDI-USB TTL serial programming cable. Arduino LilyPad is used to design “smart” wearable. 5
Arduino Mega ADKThis arduino board is specifically designed to interact with android devices.

Liquid Crystal Display (LCD)Liquid Crystal Display (LCD) screen is an electronic display module. An LCD has a wide range of applications in electronics. The most basic and commonly used LCD in circuits is the 16×2 display. LCDs are commonly preferred in display because they are cheap, easy to programme and can display a wide range of characters and animations.

A 16×2 LCD have two display lines each capable of displaying 16 characters. This LCD has Command and Data registers. The command register stores command instructions given to the LCD while the Data register stores the data to be displayed by the LCD.

9525013716000
Figure 216 LCD (16X2)When using 8-bit configuration all 8 data pins (DB0-DB7) are used while only 4 data pins (DB4-DB7) are used in a 4-bit configuration.

Pin number Function symbol
1 Ground (0V) VSS
2 Supply voltage (5V) VDD
3 Contrast adjustment; through a variable resistor(potentiometer) V0
4 Selects command register when low; and data register when RS
High 5 Low to write to the register; High to read from the register RW
6 Sends data to data pins when a high to low pulse is given E
7 8-bit data pins D0
8 8-bit data pins D1
9 8-bit data pins D2
10 8-bit data pins D3
11 8-bit data pins D4
12 8-bit data pins D5
13 8-bit data pins D6
14 8-bit data pins D7
15 Backlight VCC (5V) A
16 Backlight Ground (0V) K
Table 23 LCD Pin configuration
Automatic switching circuitsIn electronics automation many times the designer is confronted by a situation where he/she has to switch very high voltage equipment on, using a low voltage circuit. For example using a 5v dc voltage, it is possible to switch on/off a 230v ac machine. 6 Digital or discrete signals enables as opposed to analog signals are used. There are a number of components used in electronic switching today.

The Triac Switching circuitTriode for Alternating Current (TRIAC) is an electronic component-of the thyristor family- that can conduct current in either direction when it is triggered. Due to this capability a TRIAC is also known as bidirectional triode thyristor or bilateral triode thyristor. TRIAC has 3-terminals. There are two Main Terminals, A1 and A2 which carry the heavy current that is being switched, and a control terminal, the Gate, G, which accepts the control signal to turn the switch on.

90043090043000
Figure 217 Figure 2.18 The TRIACTRIACs are closely related to silicon-controlled rectifiers (SCR) but a number of differences arise between the two.

Triac is bidirectional devices unlike SCR which is unidirectional. Triac can be activated using either negative or positive current applied to its gate unlike SCR which can only be activated using positive currents. Triac cannot be turned off using the gate once turned on.

The bi-directionality makes TRIACs very convenient switches for AC circuits, also allowing them to control very large power flows with only milliampere-scale gate currents. In addition, applying a trigger pulse at a controlled phase angle in an AC cycle allows one to control the percentage of current that flows through the TRIAC to the load (phase control), which is commonly used, for example, in controlling the speed of low-power induction motors, in dimming lamps and in controlling AC heating resistors.

Relay switching circuitThis is an electromagnetic switch which is activated when a current is applied to it. A relay uses small currents to switch huge currents. Most relays use principle of electromagnetism to operate but still other operating principles like solid state are also used.6 A contactor is a type of relay which can handle a high power required to control an electric motor or other loads directly. Solid state relays have no moving parts and they use semiconductor devices to perform switching.

93345091440000
Figure 218 5VDC Coil RelayRelays are switches and thus terminologies applied to switches are also applied to relays. A relay switches one or more poles, each of whose contacts can be thrown by energizing the coil in one of three ways.

NO contacts connect the circuit when the relay is activated; the circuit is disconnected when the relay is inactive.

NC contacts disconnect the circuit when the relay is activated; the circuit is connected when the relay is inactive.

CO or double-throw (DT), contacts control two circuits: one normally-open contact and one normally-closed contact with a common terminal.

A contact relay switches one or more poles each of whose contacts can be thrown by energizing the coil in three ways namely; normally open(NO), normally closed(NC) or change over(CO).

Just like manual switches the relay switch part is available in various configurations. Double pole, double throw (DPDT) configuration is most common configuration. DPDT means that the relay separately controls two switches that work together. Both switches have a normally NO and NC contacts. Other commonly used configurations are:
SPST – Single Pole Single Throw. This relay configuring has four terminals. Two of the terminals are coil terminals.

SPDT – Single Pole Double Throw. This configuring has five terminals. One of the terminals is a common terminal which connects to either of the two others.

139065091440000
Figure 219 Inside a SPST relayDPST – Double Pole Single Throw. This relay configuring has six terminals. It is equivalent to SPST in that it is actuated by a single coil.

A simple example of relay application is where a 9V DC circuit can be used to turn on/off a 230v AC lamp.

190501397000
Figure 220 Simple relay interfacing
Whenever a relay is driven from a circuit that has delicate components such as integrated circuits or transistors, a diode is always included across the relay coil to prevent the relay from damaging the circuit.

Remote CommunicationSIM800L GSM / GPRS MODULESIM800L is a quad-band GSM/GPRS module, that works on frequencies GSM850MHz, EGSM900MHz,
DCS1800MHz and PCS1900MHz. SIM800L features GPRS multi-slot class 12/ class 10 (optional) and supports the GPRS coding schemes CS-1, CS-2, CS-3 and CS-4.
With a tiny configuration of 15.8*17.8*2.4mm, SIM800L can meet almost all the space requirements in user applications, such as smart phone, PDA and other mobile devices.
SIM800L has 88pin pads of LGA packaging, and provides all hardware interfaces between the module and customers’ boards.
Support 5*5*2 keypads
One full modem serial port, user can configure two serial ports
One USB, the USB interfaces can debug, download software
Audio channel which includes two microphone input; a receiver, output and a speaker output
Programmable general purpose input and output.
A SIM card interface
Support FM
Support one PWM
SIM800L is designed with power saving technique so that the current consumption is as low as 0.7mA in sleep mode.

Figure 221sim800l moduleModule pin-outPin-out (bottom side – left):
RING (not marked on PBC, first from top, square) – LOW state while receiving call
DTR – sleep mode. Default in HIGH state (module in sleep mode, serial communication disabled). After setting it in LOW the module will wake up.

MICP, MICN – microphone (P + / N -)
SPKP, SPKN – speaker (P + / N -)
Pin-out (bottom side – right):
NET – antenna
VCC – supply voltage
RESET – reset
RXD – serial communication
TXD – serial communication
GND – ground

Figure 222 module pinoutSYSTEM DESIGN AND IMPLEMENTATIONThe irrigation system has can be broken down into the following functional blocks:
The soil moisture/humidity sensors(soil humidity was detected using YL-69 soil sensor),The control unit(ATMega328 microcontroller based on arduino platform was used), The motor and valve switching unit ,The display, The remote communication unit(using the SIM800L GSM module, The power supply).

The system was designed to switch on and off the motor and valves depending on the soil moisture levels. Information on the soil moisture levels and motor operation was displayed on the LCD screen as and concurrently sent remotely via a text message.

The design involved the two main stages: hardware and software.

Hardware DesignControl Unit: ATMega328 microcontroller on arduino platformATMega328 microcontroller on arduino platform was selected the control unit of the microcontroller. Arduino Uno was selected from the expansive arduino family. Arduino Uno has a total of 20 inputs pins of which 14 are digital and 6 are analog inputs. 5 The digital pins can be used as either inputs or outputs and also 6 of the 14 pins can be utilized as PMW. The board has a 16 MHz ceramic resonator, a USB connection and a power jack.

Figure 31Arduino UnoThe analogue pins were used as the inputs and the digital pins as the outputs
The arduino pins were connected as shown in the table below:
Arduino Pin Connection
Digital pin 2 GSM module reset pin
Digital pin 3 LCD pin D7
Digital pin 4 LCD pin D6
Digital pin 5 LCD pin D5
Digital pin 6 LCD pin D4
Digital pin 7 Sensors Vcc
Digital pin 8 Motor control pin
Digital pin 9 RX for SIM800L
Digital pin 10 TX for SIM800L
Digital pin 11 LCD Enable pin (E)
Digital pin 12 LCD RS pin
Digital pin 13 Valve control pin
Analogue pin A0 Sensor 1 AO
Analogue pin A1 Sensor 2 A0
Power 5 V Vcc supply for :LCD VDD, SIM800L Vcc, Relays Vcc
Power GND Common gnd
Table 31 Arduino pins as connected to peripherals
Sensing Unit:YL-69 soil moisture sensor arduino interfaceYL-69 soil moisture sensor was interfaced to the arduino through a digital a PCB drive. The PCB drive has a digital potentiometer and a LM393 comparator.
For this case, two sensors were used as in a practical farm environment, an average of several sensors from different positions and soil depth may be required to form an accurate of the moisture content of the soil.
The sensor pins were connected as follows:
Vcc(for both sensors) Arduino pin 7
A0(sensor1) Analogue input A0
A0(sensor2) Analogue input A1
Gnd Arduino gnd
Table 32 YL-69 pins connection to arduino
The sensors were powered using the output pin of the arduino to enable reading of the analogue voltage when needed to conserve energy, reduce data processing burden on the microcontroller and also increase the durability of the sensors.

The analogue output of the sensors was preferred as we can map the moisture content to varied percentages from dry to soggy soils.

LCD interface with Arduino
To display the system operation status a 16×4 Liquid Crystal Display (LCD) was chosen. LCD pins D4, D5, D6 and D7 were used as data lines in a 4 bit mode configuration. These pins were connected to arduino pins 6, 5, 4 and 3 respectively. Pin 15(A) was connected to Vcc and pin 16 (K) was connected to via a 100 ohm resistor GND. These pins (A and K) are for the LEDs integrated on the LCD circuit board. LCD’s pin E (Enable) was connected to digital pin 11 on the arduino board. Pin RS (Register Select) on the LCD was connected to arduino digital pin 12. R/W pin of the LCD was connected to GND (ground).

A 10k potentiometer was used to adjust the contrast on the LCD between the Vcc and ground the common to the Vo of the LCD.

Figure 32 lcd pin connections to arduinoThe Dc pump and valve interface with the arduinoTo switch on and off the motor and valves, the arduino cannot handles that directly. To handle this, a relay operated by a transistor switch was designed.

A relay SRD-05VDC-SL-C was chosen. The relay coil terminals were connected across the arduino 5V vcc and the collector of the transistor switch. The pump and in series with the 12V DC supply was connected between the common terminal of the relay and the normally open terminal.

Transistor BD137 (NPN) was selected and the emitter connected to the common ground.

To protect the transistor; while turning it on, a resistor was used. The resistor limits the current flowing through the transistor.

Rmin = (5 – 0.7) V / 40mA = 107.5
A resistor of 470 ohms was selected and thus the base current through the transistor was thus limited to;
4.3V / 470=9.12 mA
To protect the microcontroller from back e.m.f during switching a diode was connected across the relay. The connection was as shown below

Figure 33 motor and valve switchingNote that here an LED has been used to simulate activation of the 3-way solenoid valve.

The Power supplySeveral components with the circuit required different voltages, such as the motor and valve 12Vdc, the relays 5Vdc and the GSM module 800l 4.2Vdc.
The arduino cannot power all these components thus a power supply from the mains was necessary.
Power from the mains 220V ac was fed into a transformer rated I/P:~230V/50Hz and O/P:~11.0Vx2/2.3A Yellow-Black-Yellow.

The Yellow-Black however had a practical output voltage of 15.2V thus sufficient to supply the circuit.

The out voltage was tapped for three rectifier bridges and the smoothened using a 470uF capacitor for each case. Voltage regulators L7812 and L7805 were used to achieve a fixed output voltage of 12vdc and 5vdc respectively.
The L78 series voltage regulators have a maximum current of 1A thus one cannot support the motor and valve current requirements. The motor used has a current rating of :I=P/V
=4.8watts/12v
=0.4A
The GSM module can consume up to 2A at 4.2A.

The designed power supply was as shown below:

Figure 34 power supply circuitThe GSM module (SIM800L)- arduino interfaceThe Sim800L module pins were interface with the arduino as shown in the figure and table below. Since the module require a voltage rating of 3.8V-4.2V and can consume up to 2A, the module cannot be powered using the arduino 5V supply. The Vcc of the module was thus supplied via LM2596 DC-DC Buck Converter Step-down Power module.

The module input was tapped from the L7812 output from the power supply circuit.
The reset pin of the was connected to the arduino digital pin 2 through a transistor switch.

Figure 35 SIM800L arduino interfaceFinal circuit assembly
All the components and modules were assembled as shown in the final design shown in the figure below:

Figure 36 final design
The design was implemented on a proto-board as shown on the attached imaged below:

Figure 37 Components final assemblySoftware DesignTo effect the automatic control, the atmega328 microcontroller on the Arduino was programmed. This was achieved by use of the arduino Integrated Development environment (IDE). Arduino programs (sketches) are cross platform, Simple, clear and at the same time flexible for advanced programmers.

Once the program which is ideally in C++ is written, it was compiled and a .hex file from the complier was then uploaded to the arduino platform through a USB cable connection.
The project sketch is attached at the appendices page.

Program Pseudo codeREAD sensorvalueCOMPARE sensorvalue with set threshold
IF sensorvalue ; minimum set value
TURN ON valve
TURN-ON pump
DISPLAY soil condition and pump status on LCD
SEND sms notification on pump status and soil condition
COMPARE sensorvalue with set threshold
IF sensorvalue ; minimum set value
TURN OFF pump
TURN OFF valve
ELSE IF sensorvalue ; maximum set value ; minimum set value TURN-OFF pump
DISPLAY soil condition on LCD
ELSE IF sensorvalue maximum set value
TURN-OFF pump
DISPLAY soil condition on LCD
SEND sms notification(recommend draining)
RESULTS ANALYSIS AND DISCUSSIONSResultsWhen the sensors were put into a low moisture soil (calibrated to be less than 50% soil moisture), the system automatically switched on the water pump ON and displayed the message “pump ON, watering the land”

Figure 41 watering when moisture is low(sensors out of water)When the land was successfully watered and moisture risen to more than 50%, the system automatically switched OFF the pump and displayed the new moisture level of the soil on the screen.

Figure 42 soil moisture optimumWhen the sensors detected soggy condition of the soil (calibrated as more than 75% soil moisture), the switched ensures that the pump is OFF and sends and displays on the screen that the soil is soggy with the detected moisture level and makes a recommendation to the farm operator to apply some soil draining measures. This may include draining furrows and trenches and in extreme water flooding connect the water pipes of the pump to drain the water.

When the soil moisture levels are optimum within the right range for the plant (calibrated to a soil moisture between 50% and 75%), the system continuously displays the message “moisture is optimum” and the moisture read after each second delay.

Figure 43 pump OFF for soggy soil conditionCONCLUSION AND RECOMMENDATIONSCONCLUSIONAn automatic sensor based irrigation was successfully designed and implemented based on the YL-69 moisture sensors and the “Atmega328” microcontroller on the arduino board. The water pump water motor was successfully able to be turned ON when low moisture was detected, turned off when the moisture was at a good level or soggy .This information was also successfully able to be displayed on the LCD screen and also through a text message to the user.
RECOMMENDATIONSTo improve on the effectiveness and efficiency of the system the following recommendations can be put into considerations:
Use of wireless sending of the sensor readings may recommended as may wires crossing the crop paths offer maneuverability problems for the farmer tending the crops.
The pump should also be controlled via SMS.

More sensors should be arranged on the farm strategically to ensure more accurate moisture representation of entire farm
The system can be integrated with temperature and humidity sensors to monitor the weather conditions in the farm.

Cost AnalysisThe implementation of the entire project has costs:
Item Quantity Cost(Ksh)
Arduino Uno 1 1200
SIM800L module 1 1000
Dc mini pump 1 800
Solenoid valve 1 500
Lcd (16×4) 1 400
10k Potentiometer 1 100
Soil moisture sensors 2 400
BC547 transistors 1 20
BD137 transistors 2 40
5V relays 2 200
Resistors 5 25
L7812 2 60
L7805 1 30
Capacitors 12 120
IN4007 diodes 16 80
Step down transformer 1 600
Power cable 1 200
Proto-board 2 300
Pin ports 25 200
Jumper cables 2 bundles 300
Water pipes 2 300
Simcard1 100
Total 6775
REFERENCESMassimo Banzi, Getting started with Arduino, Second Edition, O’Reilly Media, Inc, 2011
Francis Z. Karina and Alex Wambua Mwaniki, irrigation agriculture in Kenya, Nairobi, Kenya, 2011
Allan Trevennor, Practical AVR Microcontrollers, New York , USA, Springer Science + Business Media, 2012
Clemmens, A.J. Feedback Control for Surface Irrigation Management, ASAE Publication 04 -90, 1990.

www.arduino.cc Accessed on 6th Dec,2013 , 25th Dec,2013 and 17th Jan,2014
Songle relay Datasheet
Soil moisture sensor datasheet
W. C. Dunn, Introduction to Instrumentation Sensors, and Process Control, British Library Cataloguing, 2005
General Purpose Transistors NPN Silicon (KSP2222A) datasheet
http://www.vision2030.go.ke/ accessed on 12th January 2014
APPENDIXMicrocontroller code// include the library code:
#include <LiquidCrystal.h>
#include <Sim800l.h>
#include <SoftwareSerial.h> //is necesary for the library
LiquidCrystal lcd(12,11,6,5,4,3);
// YL-39 + YL-69 humidity sensor
Sim800l Sim800l; //to declare the library
byte moisture_sensor_pin0 = A0;
byte moisture_sensor_pin1 = A1;// set analogue sensor input pins
byte moisture_sensor_vcc = 7;// set sensor vcc to pin 5
int motorPin = 8;
int valvePin =13;
char* text;
char* number;
bool error; //to catch the response of sendSmsvoid setup() {
// set up the LCD’s number of columns and rows:
lcd.begin(16, 4);
// Print a message to the LCD.

lcd.print(“Initialising..”);
// Init the humidity sensor board
pinMode(moisture_sensor_vcc, OUTPUT);
pinMode(motorPin, OUTPUT);
pinMode(valvePin, OUTPUT);
digitalWrite(moisture_sensor_vcc, LOW);
// Setup Serial
while (!Serial);
delay(1000);
Serial.begin(9600);// initialize serial communication at 9600 bits per second
}
// function to read soil moisture percentage
int read_moisture_sensor() {
digitalWrite(moisture_sensor_vcc, HIGH);// sensor on to read value
delay(500);
int value1 = analogRead(moisture_sensor_pin0);//read the sensor analogue value
int value2 = analogRead(moisture_sensor_pin1);
digitalWrite(moisture_sensor_vcc, LOW);// sensor off
int value3 =1023-value1; //actual voltage is maximum byte value minus the analogue voltage read
int value4 =1023-value2;
int moisture= (value3+value4)/(5.8*2); //from a maximum value of 580 read, we convert this to a percentage
return moisture;

}
int motor() { //function turns motor ON and only exits after moisture reaches optimal value
while(read_moisture_sensor();50){
digitalWrite(valvePin,HIGH);
delay(800);
digitalWrite(motorPin,HIGH);
lcd.clear();
lcd.print(“motor ON”);
lcd.setCursor(0,2);
lcd.print(“watering land”);
Serial.print(“motor ON”);
delay(1000);}
if(read_moisture_sensor();50){
digitalWrite(motorPin, LOW);
delay(100);
int newMoisture= read_moisture_sensor(); // new value of moisture after watering recorded
lcd.clear();
lcd.print(“motor OFF”);
Serial.print(“motor OFF”);
delay(1500);
lcd.clear();
lcd.print(“new moisture:”);
lcd.setCursor(0,2);
lcd.print(newMoisture);
lcd.print(“%”);
delay(1500);
digitalWrite(valvePin,LOW);//delay in calling valve off to allow all water drip out and system stability
}
}
int soggy() { //function called when soil is soggy to recommend draining of the soggy soil
while(read_moisture_sensor();75){
digitalWrite(valvePin,LOW);
delay(50);
digitalWrite(motorPin,LOW);// ensure system stability that motor is OFF
lcd.clear();
lcd.print(“soil is soggy”);
lcd.setCursor(0,2);
lcd.print(read_moisture_sensor());
lcd.print(“%”);
delay(1500);
lcd.clear();
lcd.print(“Draining”);
lcd.setCursor(0,2);
lcd.print(“Recommended”);
Serial.print(“Soil is Soggy”);
delay(2000);}
if(read_moisture_sensor();80){
int newMoisture1= read_moisture_sensor(); // new value of moisture after draining recorded
lcd.clear();
lcd.print(“Draining”);
lcd.setCursor(0,2);
lcd.print(“Successful”);
Serial.print(“Draining Successful”);
delay(1500);
lcd.clear();
lcd.print(“Drained to:”);
lcd.setCursor(0,2);
lcd.print(newMoisture1);
lcd.print(“%”);
delay(1000);
}
}
int good() { //function loops to indicate good soil moisture percentage
while(read_moisture_sensor();=50 ;; read_moisture_sensor() ;=75){
digitalWrite(valvePin,LOW);
digitalWrite(motorPin,LOW); // ensure system stability that motor/ pump is OFF
lcd.print(“soil moisture”);
lcd.setCursor(0,2);
lcd.print(“Optimum”);
delay(1500);
lcd.clear();
lcd.print(read_moisture_sensor());
lcd.print(“%”);
delay(1500);
lcd.clear();
}
}
int drySms(){
Sim800l.begin(); // initializate the library.
text=”Low moisture detected, pump turned ON”; // alert on low moisture.
number=”+254700103928″; //reciepient’s phone number
error=Sim800l.sendSms(number,text); //Sms sent
}
int soggySms(){
Sim800l.begin(); // initializate the library.
text=”Soil is Soggy, draining recommended”; // alert on low moisture.
number=”+254700103928″; //reciepient’s phone number
error=Sim800l.sendSms(number,text); //Sms sent
}
void loop() {
Serial.print(“Moisture level: “);
lcd.clear();
lcd.print(“MoistureLevel:”);
int moisture_P=(read_moisture_sensor());
Serial.println(moisture_P);
lcd.setCursor(0,2);
lcd.print(moisture_P);
lcd.print(“%”);
delay(1000);
lcd.clear();
if(read_moisture_sensor();50){
lcd.print(“Low moisture alert”);
lcd.setCursor(0,2);
lcd.print(moisture_P);
lcd.print(“%”);
delay(1000);
motor();
drySms();
}else if(read_moisture_sensor();75){
lcd.print(“soggy Soil alert!”);
lcd.setCursor(0,2);
lcd.print(moisture_P);
lcd.print(“%”);
delay(1000);
soggySms();
soggy();
}else{
good();}

}

Post Author: admin

x

Hi!
I'm Elizabeth!

Would you like to get a custom essay? How about receiving a customized one?

Check it out