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

MICROCONTROLLER

BASED IRRIGATION SYSTEM


A MINI PROJECT REPORT

Submitted by

A.ISMAIL (070106502012)

N.MADHAN KUMAR (070106502015)

V.NANDA GOPAL (070106502020)

C.SAMPATH KUMAR (070106502028)

In partial fulfillment for the award of the degree

Of

BACHELOR OF ENGINEERING

IN

ELECTRICAL AND ELECTRONICS ENGINEERING

ER.PERUMAL MANIMEKALAI COLLEGE OF ENGINEERING

HOSUR-635117

ANNA UNIVERSITY COIMBATORE - 641047

OCTOBER 2010
1
ANNA UNIVERSITY COIMBATORE 641047

BONAFIDE CERTIFICATE

Certified that this project report MICROCONTROLLER BASED


IRRIGATION SYSTEM is the bonafide work of A.ISMAIL,
N,MADHAN KUMAR, V.NANDA GOPAL , C.SAMPATH KUMAR who
carried out the project work under my supervision.

SIGNATURE SIGNATURE

SUPERVISOR HEAD OF THE DEPARTMENT

MR.C.PALANI M.E., MR.K.UMESHA M.E.,Ph.D

LECTURER HOD

DEPARTMENT OF EEE, DEPARTMENT OF EEE,

Er.PMC TECH Er.PMC TECH

HOSUR HOSUR

------------------------- ----------------------------------
Internal Examiner External Examiner

2
ACKNOWLEDGEMENT

We are grateful to the ALMIGHTY who helped us in all the


ways throughout the project and who has molded us into what we are
today.

We are extremely grateful to the honorable chairman,


honorable secretary and honorable trustee and beloved principal
DR.C.GAJENDRAN B.E., Ph.D of Er. Perumal Manimekalai
College of Engineering for having providing with us with
opportunity to pursue our studies in this esteemed institution.

We express our sincere gratitude to our HOD


Mr.K.UMESHA M.E., Ph.D, of Er. Perumal Manimekalai
College of Engineering.

We are thankful to our project guide Mr.C.PALANI M.E,


lecturer, Department of EEE, Er. Perumal Manimekalai College
of Engineering, Hosur for his constructive suggestion and guidance
in this endeavor. We extend our thanks also to the teaching staff, who
helped us in completing our project.

We are thankful to Mrs.R.CHANDRALEKHA M.E,


coordinator, Department of EEE, Er. Perumal Manimekalai
College of engineering, Hosur for her constructive suggestion and
guidance in this endeavor.
3
TABLE OF CONTENTS: PAGE NO

CHAPTER 1

1. Abstract 2

2. Introduction 3

3. Design of irrigation system 4

CHAPTER 2

2.1. Block diagram 7

2.2. System requirements . 9

2.3. Circuit diagram . 10

CHAPTER 3

3.1. Microcontroller (ATMEGA16).. 13

3.2. sensor (LM35) 17

3.3. LCD unit 20

3.4. relay unit 22

CHAPTER 4

4.1. AVR osp 26

4.2. Code vision 28

4
CHAPTER - 5

5.1. Codings of the microcontroller 30

CHAPTER- 6

6.1. Advantages 41

6.2. Disadvantages ... 41

6.3. Conclusion 42

6.4. References 43

5
TABLE OF FIGURES:

1. Data Flow Diagram 7

2. Circuit Diagram. 10

3. Pin Diagram Of Microcontroller 13

4. Power Circuit For Microcontroller 16

5. Sensor(Lm35) 18

6. LCD Unit 20

7. Relay Unit. 22

LIST OF TABLES:

1. Electrical Characteristics of LM35.. 18

2. Details Of 16x2 LCD 21

6
CHAPTER 1

7
1. ABSTRACT:

In the field of agriculture, use of proper method of irrigation is important and it is well
known that irrigation by drip is very economical and efficient. In the conventional drip
irrigation system, the farmer has to keep watch on irrigation timetable, which is different
for different crops. The project makes the irrigation automated. With the use of low cost
sensors and the simple circuitry makes this project a low cost product, which can be
bought even by a poor farmer. This project is best suited for places where water is scares
and has to be used in limited quantity. Also, third world countries can afford this simple
and low cost solution for irrigation and obtain good yield on Crops.

The heart of the project is the microcontroller. UART controller that will be used in
this project. A 162 LCD is connected to the microcontroller, which displays the humidity
level and ambient temperature. Three pushbuttons are provided to set the limits of
humidity for switching the individual solenoid valves controlling the water flow to the
field. The humidity and temperature levels are transmitted at regular time interval to the
PC through the RS232 serial port for data logging and analysis. The humidity sensors are
constructed using aluminum sheets and housed in easily available materials. The aim is to
use the readily available material to construct low cost sensors. Five relays are controlled
by the microcontroller through the high current driver IC, ULN2003. Four relays are
provided for controlling four solenoid valves, which controls the flow of water to four
different parts of the field. One relay is used to shut-off the main motor which is used to
pump the water to the field.

8
2.Introduction

The continuous increasing demand of the food requires the rapid improvement in food
production technology. In a country like India, where the economy is mainly based on
agriculture and the climatic conditions are isotropic, still we are not able to make full use of
agricultural resources. The main reason is the lack of rains & scarcity of land reservoir water.
The continuous extraction of water from earth is reducing the water level due to which lot of
land is coming slowly in the zones of un-irrigated land. Another very important reason of this
is due to unplanned use of water due to which a significant amount of water goes waste. At
the present era, the farmers have been using irrigation technique in India through the manual
control in which the farmers irrigate the land at the regular intervals. This process sometimes
consumes more water or sometimes the water reaches late due to which the crops get dried.
Water deficiency can be detrimental to plants before visible wilting occurs. Slowed growth
rate, lighter weight fruit follows slight water deficiency. This problem can be perfectly
rectified if we use automatic micro controller based drip irrigation system in which the
irrigation will take place only when there will be intense requirement of water.

Automating farm or nursery irrigation allows farmers to apply the right amount of water
at the right time, regardless of the availability of labor to turn valves on and off. In addition,
farmers using automation equipment are able to reduce runoff from over watering saturated
soils, avoid irrigating at the wrong time of day, which will improve crop performance by
ensuring adequate water and nutrients when needed. . It also helps in time saving, removal of
human error in adjusting available soil moisture levels and to maximize their net profits.

9
3.DESIGN OF MICRO CONTROLLER BASED
IRRIGATION SYSTEM:
The key elements that should be considered while designing a mechanical model: -.

a) Flow: -

You can measure the output of your water supply with a one or five gallon bucket and a
stopwatch. Time how long it takes to fill the bucket and use that number to calculate how
much water is available per hour. Gallons per minute x 60=number of gallons per hour.

b) Pressure (The force pushing the flow):

Most products operate best between 20 and 40 pounds of pressure. Normal household
pressure is 40-50 pounds.

c) Water Supply & Quality: -

City and well water are easy to filter for drip irrigation systems. Pond, ditch and
some well water have special filtering needs. The quality and source of water will dictate the
type of filter necessary for your system.

d) Soil Type and Root Structure:

The soil type will dictate how a regular drip of water on one spot will spread. Sandy
soil requires closer emitter spacing as water percolates vertically at a fast rate and slower
horizontally. With a clay soil water tends to spread horizontally, giving a wide distribution
pattern. Emitters can be spaced further apart with clay type soil. A loamy type soil will
produce a more even percolation dispersion of water. Deep-rooted plants can handle a wider
spacing of emitters, while shallow rooted plants are most efficiently watered slowly (low gap
emitters) with emitters spaced close together. On clay soil or on a hillside, short cycles
repeated frequently work best. On sandy soil, applying water with higher gap emitters lets
the water spread out horizontally better than a low gap emitter.

e) Elevation: -

Variations in elevation can cause a change in water pressure within the system.
Pressure changes by one pound for every 2.3 foot change in elevation. Pressure-
compensating emitters are designed to work in areas with large changes in elevation.

10
f) Timing: -

Watering in a regular scheduled cycle is essential. On clay soil or hillsides, short


cycles repeated frequently work best to prevent runoff, erosion and wasted water. In sandy
soils, slow watering using low output emitters is recommended. Timers help prevent the too-
dry/too-wet cycles that stress plants and retard their growth. They also allow for watering at
optimum times such as early morning or late evening.

g) Watering Needs: -

Plants with different water needs may require their own watering circuits.
For example, orchards that get watered weekly need a different circuit than a garden that gets
watered daily. Plants that are drought tolerant will need to be watered differently than plants
requiring a lot of water.

11
CHAPTER 2

12
2.1. DATA FLOW DIAGRAM

13
EXPLANATION OF DATA FLOW DIAGRAM

The automated control system consists of temperature sensors, keypad, LCD


display, microcontroller, relay, etc

The important parameters to be measured for automation of irrigation system are soil
moisture and temperature. The entire field is first divided into small sections such that each
section should contain a temperature sensor.

These sensors are buried in the ground at required depth. Once the soil has reached
desire moisture level the sensors send a signal to the microcontroller to turn off the relays.

LCD module can be used in the system to monitor current readings of all the sensors
and the current status of respective valves or motors.

The keypad is used to set the temperature value as needed by the different crops .

The relay drive is used to drive the relay unit as the relay cannot be controlled directly by
microcontroller.

14
2.2SYSTEM SPECIFICATIONS

Hardware requirements:

1. Microcontroller (ATMEGA16)

2. Keypad

3. LCD

4. Relay drive and relay

5. Temperature sensors (LM35)

6. Power supply

Software requirements:

1. Embedded C

2. Compiler (Code vision)

3. Program downloader(AVRosp)

15
2.3.CIRCUIT DIAGRAM

16
DESCRIPTION OF CIRCUIT DIAGRAM:

The three temperature sensor pins TADC1, TADC2, TADC3 are connected to
the microcontroller pins 40, 39, 37 respectively. The microcontroller pins 11 and 31 are
grounded and a pin 10 is connected to VCC.

The keypad pins KP1, KP2, KP3, KP4 are connected to the micro controller pins 1, 2,
3, 4 respectively in order to change the values of the temperature according to the need of the
crops.

In the 16x2 LCD the pin 1 is grounded and 2 is VCC. The pins 11(LCD4) ,
12 (LCD5), 13(LCD 6), 14(LCD 7) of LCD are connected to the pins 18, 19, 20, 21 of the
microcontroller respectively in order to display the status of motor or to display the
temperature value.

The output of the project is get through relay. The pin 2 of the relay is connected to the
pin 29 of the micro controller.

The crystal oscillator is connected to the pin 12 and 13 of the micro controller. XTAL1
and XTAL2 are input and output, respectively, of an inverting amplifier which can be
configured for use as an On-chip Oscillator. Either a quartz crystal or a ceramic resonator
may be used. The CKOPT Fuse selects between two different Oscillator amplifier modes.
When CKOPT is programmed, the Oscillator output will oscillate will a full rail- to-rail
swing on the output. This mode is suitable when operating in a very noisy environment or
when the output from XTAL2 drives a second clock buffer. This mode has a wide frequency
range. When CKOPT is unprogrammed, the Oscillator has a smaller output swing. This
reduces power consumption considerably. This mode has a limited frequency range and it can
not be used to drive other clock buffers.

For resonators, the maximum frequency is 8 MHz with CKOPT unprogrammed and
16MHz with CKOPT programmed. C1 and C2 should always be equal for both crystals and
resonators. The optimal value of the capacitors depends on the crystal or resonator in use, the
amount of stray capacitance, and the electromagnetic noise of the environment.

17
CHAPTER 3

18
3.1.MICROCONTROLLER (ATMEGA16)
The ATmega16 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced
RISC architecture. By executing powerful instructions in a single clock cycle, the ATmega16
achieves throughputs approaching 1 MIPS per MHz allowing the system designed to
optimize power consumption versus processing speed.

Pin configuration:

The AVR core combines a rich instruction set with 32 general purpose working registers.
All the 32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two
independent registers to be accessed in one single instruction executed in one clock cycle.
The resulting architecture is more code efficient while achieving throughputs up to ten times
faster than conventional CISC microcontrollers.

19
The ATmega16 provides the following features: 16K bytes of In-System Programmable
Flash Program memory with Read-While-Write capabilities, 512 bytes EEPROM, 1K byte
SRAM, 32 general purpose I/O lines, 32 general purpose working registers, a JTAG
interface for Boundary scan, On-chip Debugging support and programming, three flexible
Timer/Counters with compare modes, Internal and External Interrupts, a serial programmable
USART, a byte oriented Two-wire Serial Interface, an 8-channel, 10-bit ADC with optional
differential input stage with programmable gain (TQFP package only), a programmable
Watchdog Timer with Internal Oscillator, an SPI serial port, and six software selectable
power saving modes. The Idle mode stops the CPU while allowing the USART, Two-wire
interface, A/D Converter, SRAM; Timer/Counters, SPI port, and interrupt system to continue
functioning.

The Power-down mode saves the register contents but freezes the Oscillator,
disabling all other chip functions until the next External Interrupt or Hardware Reset. In
Power-save mode, the Asynchronous Timer continues to run, allowing the user to maintain a
timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the
CPU and all I/O modules except Asynchronous Timer and ADC, to minimize switching noise
during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while
the rest of the device is sleeping. This allows very fast start-up combined with low-power
consumption.

Features
High-performance, Low-power AVR 8-bit Microcontroller

Advanced RISC Architecture


131 Powerful Instructions Most Single-clock Cycle Execution
32 x 8 General Purpose Working Registers
Fully Static Operation
Up to 16 MIPS Throughput at 16 MHz
On-chip 2-cycle Multiplier

High Endurance Non-volatile Memory segments


16K Bytes of In-System Self-programmable Flash program memory
512 Bytes EEPROM

20
1K Byte Internal SRAM
Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
Data retention: 20 years at 85C/100 years at 25C(1)
Optional Boot Code Section with Independent Lock Bits
Programming Lock for Software Security

Peripheral Features
Two 8-bit Timer/Counters with Separate Prescalers and Compare Modes
One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode.
Real Time Counter with Separate Oscillator
Four PWM Channels

Special Microcontroller Features


Power-on Reset and Programmable Brown-out Detection
Internal Calibrated RC Oscillator
External and Internal Interrupt Sources
Six Sleep Modes: Idle, ADC Noise Reduction, Power-save. .

I/O and Packages


32 Programmable I/O Lines
40-pin PDIP, 44-lead TQFP, and 44-pad QFN/MLF

Operating Voltages
2.7 - 5.5V for ATmega16L
4.5 - 5.5V for ATmega16

Speed Grades
0 - 8 MHz for ATmega16L
0 - 16 MHz for ATmega16

Power Consumption @ 1 MHz, 3V, and 25C for ATmega16L


Active: 1.1 mA
Idle Mode: 0.35 mA
Power-down Mode: < 1 A

21
POWER CIRCUIT FOR MICROCONTROLLER

U1
1 3
VI N VOU T

D1 7805
R1 J P1

1
W 01G
+ 330
2
1 2

1
2 3 C1
TX1 470uF C1 C1 D2 1
47uF 0. 1uF
LN 211W P
-

V1
4
230V

2
230/9V

The operation of power supply circuits built using filters, rectifiers, and then
voltage regulators. Starting with an AC voltage, a steady DC voltage is obtained by rectifying
the AC voltage, Then filtering to a DC level, and finally, regulating to obtain a desired fixed
DC voltage.

The regulation is usually obtained from an IC voltage regulator Unit, which takes
a DC voltage and provides a somewhat lower DC voltage, which remains the same even if
the input DC voltage varies, or the output Load connected to the DC voltage changes.

22
3.2.SENSOR
After the processor had been chosen, the next decision to be made was what would be
needed to sufficiently model the weather to allow for compensation of its effects. A number
of ideas were considered, which included

x Measuring the soil resistance to obtain a soil moisture level reading. As the moisture
level decreases the resistance should increase. They could be placed at different
depths to give a better overall indication of soil conditions.
x Using a 3 pin temperature sensor unit (possibly an ICLM35) to convert the current
temperature to an appropriate voltage level. The three pins are ground,5 volts and
signal (1 4V). The signal would be sent to an ADC (Analogue to Digital Converter)
which would send its output to the microcontrollers input port.

LM35
The LM35 series are precision integrated-circuit temperature sensors, whose
output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35
thus has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not
required to subtract a large constant voltage from its output to obtain convenient Centigrade
scaling.

The LM35 does not require any external calibration or trimming to provide
typical accuracies of 14C at room temperature and 34Cover a full 55to+150C
temperature range. Low cost is assured by trimming and calibration at the wafer level. The
LM35s low output impedance, linear output, and precise inherent calibration make
interfacing to read out or control circuitry especially easy.

23
ELECTRICAL CHARACTERISTICS OF LM35

It can be used with single power supplies, or with plus and minus supplies .As it draws
only 60A from its supply, it has very low self-heating, less than 0.1 C in still air.

The LM35 is rated to operate over a 55to+150C temperature range, while the LM35C
is rated for a 40to+110C range (10with improved accuracy). The LM35 series is
available packaged in hermetic TO 46 transistor packages.

24
MAXIMUM RATINGS:

SupplyVoltage+35Vto0.2V
OutputVoltage+6Vto1.0V
OutputCurrent10Ma

Features

o Calibrated directly in Celsius (Centigrade)


o Linear+10.0mV/C scale factor
o 0.5C accuracy guaranteeable(at+25C)
o Rated for full 55to+150C range
o Suitable for remote applications
o Low cost due to wafer-level trimming
o Operates from 4 to 30volts
o Less than 60A current drain
o Low self-heating ,0.08C in still air
o Non linearity only 14C typical
o Low impedance output, 0.1 for 1mA load

25
3.3.LCD DISPLAY:

16 x 2 Character LCD DISPLAY

A liquid crystal display (LCD) is a thin, flat electronic visual display that uses the light
modulating properties of liquid crystals (LCs). LCs do not emit light directly.

They are available in a wider range of screen sizes than CRT and plasma displays, and since
they do not use phosphors, they cannot suffer image burn-in.

LCDs are more energy efficient and offer safer disposal than CRTs. Its low electrical power
consumption enables it to be used in battery-powered electronic equipment. It is an
electronically-modulated optical device made up of any number of pixels filled with liquid
crystals and arrayed in front of a light source (backlight) or reflector to produce images in
colour or monochrome.

LCD module can be used in the system to monitor current readings of all the sensors and the
current status of respective valves.

SCHEMATIC VIEW 16 X 2 LCD DISPLAY:

26
FEATURES:

5 x 8 dots with cursor

Built-in controller (KS 0066 or Equivalent)

+ 5V power supply (Also available for + 3V)

1/16 duty cycle

N.V. optional for + 3V power supply

DETAILS OF 16 X 2 LCD DISPLAY:

27
3.4.RELAY UNIT:
A relay is an electro-magnetic switch, which is useful if you want to use a low
voltage circuit to switch on and off a light bulb (or anything else) connected to the 220v
mains supply.

Relays are used to and for:

x Control a high-voltage circuit with a low-voltage signal, as in some types of modems


or audio amplifiers.

x Control a high-current circuit with a low-current signal, as in the starter solenoid of an


automobile.

x Detect and isolate faults on transmission and distribution lines by opening and closing
circuit breakers (protection relays),a dpdt ac coil relay with "ice cube" packaging.

x Isolate the controlling circuit from the controlled circuit when the two are at different
potentials, for example when controlling a mains-powered device from a low-voltage
switch.

28
The latter is often applied to control office lighting as the low voltage wires are easily
installed in partitions, which may be often moved as needs change. They may also be
controlled by room occupancy detectors in an effort to conserve energy.

x Logic functions. For example, the boolean and function is realised by


connectingnormally open relay contacts in series, the or function by connecting
normally open contacts in parallel. The change-over or form c contacts perform the
xor (exclusive or) function. Similar functions for nand and nor are accomplished
using normally closed contacts.

The ladder programming language is often used for designing relay logic networks.

O Early computing. Before vacuum tubes and transistors, relays were used as
logical elements in digital computers. See arra (computer), harvard mark ii,
zuse z2, and zuse z3.
O Safety-critical logic. Because relays are much more resistant than
semiconductors to nuclear radiation, they are widely used in safety-critical
logic, such as the control panels of radioactive waste-handling machinery.

x A dashpot is a piston filled with fluid that is allowed to escape slowly. The time
period can be varied by increasing or decreasing the flow rate. For longer time
periods, a mechanical clockwork timer is installed.

29
RELAY DRIVER
The current needed to operate the relay coil is more than can be supplied by most chips
(op. amps etc), so a transistor is usually needed.

Use BC109C or similar. A resistor of about 47K will probably be alright. The diode
is needed to short circuit the high voltage back emf induced when current flowing through
the coil is suddenly switched off.

The relay drive is used to drive the relay unit as the microcontroller cannot be
controlled directly.

30
CHAPTER 4

31
4.1.AVR Open Source Programmer
The AVR Open Source Programmer (AVROSP) is an AVR programmer
application equivalent to the AVR Prog tool included in AVR Studio. It is a command-line
tool, using the same syntax as the other command-line tools in AVR Studio. The open source
code and its modular design make it easy to port the application to other platforms and to add
support for other programmer types and communication channels. Currently, AVROSP
supports the programmers described in AVR109 and AVR910 through the standard PC serial
port.

The application note describes how to add more support. AVROSP reads and writes
Intel HEX files, and can use an existing AVR Studio installation to get required device
parameters. This means that AVROSP automatically supports all devices supported by AVR
Studio. No update is required for future AVR devices other than keeping your AVR Studio
installation up to date.

The AVROSP application tries to generalize this procedure into one application, thereby
eliminating the need for different applications with different syntax and usage for each
programmer type. Whether you are using a boot loader, an in-system programmer or a third-
party programmer, the procedure is basically the same. AVROSP gives a consistent interface
to the programming operation.

The original Part Description Files are very large, and it takes some time to parse them.
Therefore AVROSP creates a small XML file containing only the parameters of interest, and
stores it in the AVROSP home directory.

Features

Open source C++ code

Modular design

Reads device information from AVR Studios XML files

Supports the Boot loader in AVR109

Supports the In-System Programmer in AVR910

Command-line equivalent to AVR Studio command-line tools

32
AVROSP Class Diagram

Most of the top-level work is encapsulated in the JobInfo class. It uses objects of class
XMLFile, HEXFile and AVRDevice to read and write XML and HEX files and to extract
device information from the Part Description Files.

The two helper classes Utility and ErrorMsg are used throughout the application. The
part of JobInfo that communicates with the programmer does not need to know what kind of
communication channel to use. It decodes the command line and creates an instance of the
required derived class, e.g. the SerialPort class.

The rest of the code just works through the generalized CommChannel parent class.
Currently, only a class for the PC COM port is implemented, but to use e.g. USB or TCP/IP
communication, you could derive a specialized class from the CommChannel base class,
and add a check for this channel type in the command line parser.

33
4.2.CODE VISION AVR
Code vision AVR is a C cross compiler , integrated development environment and automatic
program generator designed for the Atmel AVR family of microcontrollers.

The program is a native 32 bit application that runs under the Windows operating systems.

The C cross compiler implements nearly all the elements of the ANSIC language, as
allowed by the AVR architecture, with some features added to take advantage of specificity
of the AVR architecture and the embedded system needs.

The compiled COFF object files can be C source level debugged, with variable
watching, using the Atmel AVR studio debugger.

The Integrated Development Environment(IDE) has built-in AVR chip in-system


programmer software that enables the automatical transfer of the program to the
microcontroller chip after successful compilation/assembly.

34
CHAPTER 5

35
5.1.CODING FOR THE MICROCONTROLLER:

#include <config.c>
#include <delay.h>

#define TE_BIT PORTB.0


#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7

#define FRAMING_ERROR (1<<FE)


#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)

#define MAX_SAMPLE 30

unsigned char eeprom EEP_Rly_Stat=1;


unsigned char SRAM_Rly_Stat;
unsigned char proba;
int com_out=0;
bit Samp_rdy,Sec_Rdy;
unsigned int
Adc_V[MAX_SAMPLE],Adc_I[MAX_SAMPLE],Adc_T[MAX_SAMPLE];
unsigned int F_Adc_V,F_Adc_I,F_Adc_T,t_F_Adc_V,t_F_Adc_I;
unsigned char Adc_Samp_Cnt;
unsigned int Msec_Cnt,TE_Time;
signed char Sec_Cnt;
// Timer 1 overflow interrupt service routine

36
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
// Reinitialize Timer 1 value
TCNT1H=0xFC;
TCNT1L=0x13;
Msec_Cnt++;
TE_Time++;
if (Msec_Cnt >=500)
{
Msec_Cnt = 0;
Sec_Rdy = 1;
PORTD.7 = ~PORTD.7 ;
Sec_Cnt++;

}
// Place your code here

// ADC interrupt service routine


// with auto input scanning

// USART Receiver buffer


#define RX_BUFFER_SIZE 16
char rx_buffer[RX_BUFFER_SIZE];

#if RX_BUFFER_SIZE<256
unsigned char rx_wr_index,rx_rd_index,rx_counter;
#else
unsigned int rx_wr_index,rx_rd_index,rx_counter;
#endif

// This flag is set on USART Receiver buffer overflow


bit rx_buffer_overflow;
37
// USART Receiver interrupt service routine
interrupt [USART_RXC] void usart_rx_isr(void)
{
char status,data;
status=UCSRA;
data=UDR;

if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)


{
rx_buffer[rx_wr_index]=data;
// PORTB.0=~PORTB.0;
if (++rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
if (++rx_counter == RX_BUFFER_SIZE)
{
rx_counter=0;
rx_buffer_overflow=1;
};
};
}

#ifndef _DEBUG_TERMINAL_IO_
// Get a character from the USART Receiver buffer
#define _ALTERNATE_GETCHAR_
#pragma used+
char getchar(unsigned long timeout1)
{
char data;
while ((rx_counter==0) && (timeout1 > 0))
timeout1--;
if(timeout1==0)// (rx_counter==0)
{
com_out=1;
return 1;
38
}
data=rx_buffer[rx_rd_index];
if (++rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
#asm("cli")
--rx_counter;
#asm("sei")
return data;
}
#pragma used-
#endif

// USART Transmitter buffer


#define TX_BUFFER_SIZE 32
char tx_buffer[TX_BUFFER_SIZE];

#if TX_BUFFER_SIZE<256
unsigned char tx_wr_index,tx_rd_index,tx_counter;
#else
unsigned int tx_wr_index,tx_rd_index,tx_counter;
#endif

// USART Transmitter interrupt service routine


interrupt [USART_TXC] void usart_tx_isr(void)
{
if (tx_counter)
{
--tx_counter;
UDR=tx_buffer[tx_rd_index];
if (++tx_rd_index == TX_BUFFER_SIZE) tx_rd_index=0;
};
}

#ifndef _DEBUG_TERMINAL_IO_
// Write a character to the USART Transmitter buffer
39
#define _ALTERNATE_PUTCHAR_
#pragma used+
void putchar(char c)
{
while (tx_counter == TX_BUFFER_SIZE);
#asm("cli")
if (tx_counter || ((UCSRA & DATA_REGISTER_EMPTY)==0))
{
tx_buffer[tx_wr_index]=c;
if (++tx_wr_index == TX_BUFFER_SIZE) tx_wr_index=0;
++tx_counter;
}
else
UDR=c;
#asm("sei")
}
#pragma used-
#endif

// Standard Input/Output functions


#include <stdio.h>

interrupt [ADC_INT] void adc_isr(void)


{
static unsigned char input_index=0;
// Read the AD conversion result
//adc_data[input_index]=ADCW;

if(input_index == 0)
{
Adc_V[Adc_Samp_Cnt]=ADCW;
}
else if (input_index == 1)
{
40
Adc_I[Adc_Samp_Cnt]=ADCW;
}
else
{
Adc_T[Adc_Samp_Cnt]=ADCW;
if(++Adc_Samp_Cnt > MAX_SAMPLE-1)
{
ADCSRA.3 = 0;
Adc_Samp_Cnt =0;

Samp_rdy = 1;
}
}

// Select next ADC input


if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
input_index=0;
ADMUX=(FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff))+input_index;
// Start the AD conversion
if(!Samp_rdy)
ADCSRA|=0x40;
}

int waitdoller()
{
// int l=0;
int flag=0;
com_out=0;

if(!com_out)
proba=getchar(100000);
41
else return 0; //here exits by timeout

if(proba==0x24)
{
flag=flag+1;
}

return flag;
}

bit Vb,Ib,Tb;
unsigned char Count;
void main(void)
{
delay_ms(1000);
SRAM_Rly_Stat =EEP_Rly_Stat;

Vb=Ib=Tb=0;
Samp_rdy =0;
Adc_Samp_Cnt =0;
Msec_Cnt =0;
Sec_Rdy =0;
//PORTC.2 = 0;
init();
Sec_Cnt=0;
//PORTC.2 = 0;
Sec_Cnt=0;
Count=0;

if (SRAM_Rly_Stat == 1)
PORTC.2 = 0;
42
else
PORTC.2 = 1;

while(Sec_Cnt<=5);
while(1)
{
if (rx_counter != 0)
{
if (waitdoller())
{

// PORTB.0=~PORTB.0;
proba = getchar(100000);
if(proba=='A')
{
PORTC.2 = 0;
EEP_Rly_Stat = 1;
SRAM_Rly_Stat =1;
printf("%cSTATON%c%c",0x24,0x0D,0x0A);
}
else if(proba=='B')
{
PORTC.2 = 1;
EEP_Rly_Stat = 0;
SRAM_Rly_Stat =0;
printf("%cSTATOFF%c%c",0x24,0x0D,0x0A);
}
else if (proba=='D')

printf("%cREPLY,%00004d,%00004d,%c,%0003d,%c%c",0x24,t_F_Adc_V,t_F_Adc
_I,SRAM_Rly_Stat,Count++,0x0D,0x0A);

}
}
43
if (Samp_rdy == 1)
{
F_Adc_V =Adc_V[0];
F_Adc_I=Adc_I[0];
F_Adc_T=Adc_T[0];
for (Adc_Samp_Cnt = 1;Adc_Samp_Cnt<=MAX_SAMPLE-1;Adc_Samp_Cnt++)
{
F_Adc_V += Adc_V[Adc_Samp_Cnt];
F_Adc_V/=2;
F_Adc_I += Adc_I[Adc_Samp_Cnt];
F_Adc_I/=2;
// F_Adc_T += Adc_T[Adc_Samp_Cnt];
// F_Adc_T/=2;
t_F_Adc_V=F_Adc_V;
t_F_Adc_I=F_Adc_I;

if(Sec_Cnt >=1)
{

printf("%cREPLY,%00004d,%00004d,%d,%0003d,%c%c",0x24,t_F_Adc_V,t_F_Adc
_I,SRAM_Rly_Stat,Count++,0x0D,0x0A);
Sec_Cnt=0;
}

//if (Sec_Cnt>=3)
// {
//
printf("%cU%00004d,V%00004d,%d,W%0003d,%c%c",0x24,F_Adc_I,F_Adc_V,SR
AM_Rly_Stat,Count++,0x0D,0x0A);

// Sd_Data_HTx('T',F_Adc_T);
44
// Sec_Cnt=0;
// Vb=Ib=0;
/// }
//else if (Sec_Cnt>=2 && Ib == 0)
// {
//
printf("%cU%00004d,V%00004d,%d,W%0003d,%c%c",0x24,F_Adc_I,F_Adc_V,SR
AM_Rly_Stat,Count++,0x0D,0x0A);
// Ib=1;}
// {Sd_Data_HTx('I',F_Adc_I);Ib=1;}
//else if (Sec_Cnt>=1 && Vb==0)
// {
//
printf("%cU%00004d,V%00004d,%d,W%0003d,%c%c",0x24,F_Adc_I,F_Adc_V,SR
AM_Rly_Stat,Count++,0x0D,0x0A);
// Vb=1;}
//{Sd_Data_HTx('V',F_Adc_V);Vb=1;}

Samp_rdy = 0;
Adc_Samp_Cnt = 0;

ADCSRA.3 = 1;
ADCSRA|=0x40;

}
45
CHAPTER 6

46
6.1.ADVANTAGES

1 .Are relatively simple to design and install

2. This is very useful to all climatic conditions any it is economic friendly

3. This makes increase in productivity and reduces water consumption

4. Here we are micro controllers so there is error free

5. This is safest and no manpower is required. Permit other yard and garden work to
continue when irrigation is taking place, as only the immediate plant areas are wet

6. Reduce soil erosion and nutrient leaching.

7. Reduce the chance of plant disease by keeping foliage dry.

8. May be concealed to maintain the beauty of the landscape, and to reduce vandalism and
liability when installed in public areas.

9. Require smaller water sources, for example, less than half of the water needed for a
sprinkler system.

6.2. DISADVANTAGES

1. This is only applicable for large size farms


2. Equipment is costlier
3. Require frequent maintenance for efficient operation
4. Have limited life after installation due to the deterioration of the plastic components
in a hot, arid climate when exposed to ultraviolet light

47
6.3. CONCLUSION

The Microcontroller based drip irrigation system proves to be a real time feedback control
system which monitors and controls all the activities of drip irrigation system efficiently. The
present proposal is a model to modernize the agriculture industries at a mass scale with
optimum expenditure. Using this system, one can save manpower, water to improve
production and ultimately profit.

48
6.4. REFERENCES:

http://www.btechstudent.com
http://www.1000projects.com
http://www.chetanasprojects.com
WWW.datasheet4u.com
8081 and Embedded systems by Mohammed Ali Mazidi
1. Clemmens, A.J.. Feedback Control for Surface Irrigation Management. In:Visions of the Future.
ASAE Publication 04-90. American Society of Agricultural Engineers, St. Joseph, Michigan

2. Fangmeier, D.D., Garrot, D.J., Mancino,C.F. and S.H. Husman. 1990. Automated Irrigation Systems
Using Plant and Soil Sensors. In: Visions of the Future. ASAE Publication 04-90. American Society of
Agricultural Engineers, St. Joseph, Michigan

3. Gonzalez, R.A., Struve, D.K. and L.C. Brown. A computer-controlled drip


irrigation system for container plant production. HortTechnology.

4. Wanjura, D.F., Upchurch, D.R. and W. M. Webb. 1991. An automated control system for studying
microirrigation. ASAE Annual International Meeting

49

You might also like