Sie sind auf Seite 1von 87

CROP MONITORING SYSTEM

A Mini Project Report Submitted in the Partial Fulfillment of the Requirements For the Award of the Degree of

BACHELOR OF TECHNOLOGY
IN

ELECTRONICS AND COMMUNICATION ENGINEERING

Submitted By J.PAVAN KUMAR J.HAREEN SAI P.DINESH KUMAR 10881A0427 10881A0413 10881A0409

Under the Guidance of MR. J. KRISHNA CHAITHANYA Associate Professor Department of ECE

Department of Electronics and Communication Engineering


(AUTONOMOUS)
(Approved by AICTE, Affiliated to JNTUH & Accredited by NBA)

2013 - 14

(AUTONOMOUS)
Estd.1999

Shamshabad, Hyderabad - 501218

Department of Electronics and Communication Engineering

CERTIFICATE

This is to certify that the technical seminar report work entitled Crop Monitoring System carried out by Mr. J.Pavan Kumar, Roll Number 10881A0427; Hareen Sai Javaji, Roll Number 10881A0413; Dinesh Kumar Pentam , Roll number 10881A0409 submitted to the department of Electronics and Communication Engineering, in partial fulfillment of the requirements for the award of degree of Bachelor of Technology in Electronics and Communication Engineering during the year 2013 2014.

Name & Signature of the Supervisor

Name & Signature of the HOD

Mr. J.KRISHNA CHAITHANYA Associate Professor

Dr. J. V. R. Ravindra Head, ECE

Kacharam (V), Shamshabad (M), Ranga Reddy (Dist.) 501 218, Hyderabad, A.P. Ph: 08413-253335, 253201, Fax: 08413-253482, www.vardhaman.org

ACKNOWLEDGEMENTS

The satisfaction that accompanies the successful completion of the task would be put incomplete without the mention of the people who made it possible, whose constant guidance and encouragement crown all the efforts with success. We express my heartfelt thanks to Mr. J. Krishna Chaithanya, Associate Professor, technical seminar supervisor, for his suggestions in selecting and carrying out the in-depth study of the topic. His valuable guidance, encouragement and critical reviews really helped to shape this report to perfection. We wish to express my deep sense of gratitude to Dr. J. V. R. Ravindra, Head of the Department for his able guidance and useful suggestions, which helped me in completing the technical seminar on time. We also owe my special thanks to our Director Prof. L. V. N. Prasad for his intense support, encouragement and for having provided all the facilities and support. We am highly indebted to Prof. Y. Pandurangaiah, Ms. A. Vijaya Lakshmi, Mr. H. Shravan Kumar and Mr. S. Rajendar for their guidance and constant supervision as well as moral strength and courage during the tough times of our academic career. Finally thanks to all our family members and friends for their continuous support and enthusiastic help.

Yours Sincerely, J. Pavan Kumar HareenSai Javaji Pentam Dinesh

iii

ABSTRACT
Appropriate soil water level is a necessary pre-requisite for optimum plant growth. Also, water being an essential element for life sustenance, there is the necessity to avoid its undue usage. Irrigation is a dominant consumer of water. This calls for the need to regulate water supply for irrigation purposes. Fields should neither be over-irrigated nor under-irrigated. Over time, systems have been implemented towards realizing this objective of which automated processes are the most popular as they allow information to be collected at high frequency with less labor requirements. Bulk of the existing systems employ micro-processor based systems. These systems offer several technological advantages but are unaffordable, bulky, difficult to maintain and less accepted by the technologically unskilled workers in the rural scenario.

The objective of this project is to design a simple, easy to install methodology to monitor and indicate the level of soil moisture that is continuously controlled in order to achieve maximum plant growth and simultaneously optimize the available irrigation resources. A simple AVR Atmega 64 based comparator circuit is used coupled with relay units which control the water pumps. The use of easily available components reduces the manufacturing and maintenance costs. This makes the proposed system to be an economical, appropriate and a low maintenance solution for applications, especially in rural areas and for small scale agriculturists.

This Project allows farmers to monitor their farm staying away from field and precisely know whether the soil is dry or wet with, humidity and temperature at the field , apart from this , the circuit application allows to switch the Pump Set Motor ON and OFF right from home sitting away from the crop field. Using Atmega 64 and necessary interface integrating circuits like RS232, LM 2685 the hardware components and sensor components are interfaced. Later using switches the complete crop status such as Temperature and Humidity at crop Field, whether the soil is wet or dry and necessary actions can be taken as stated before.

iv

CONTENTS
Acknowledgements Abstract List of Figures
List of Tables

(iii) (iv) (vii)


(viii)

INTRODUCTION 1.1 Device Overview 1.2 Device Architecture 1.3 Development And Features 1.4 Programing Interfacing
1.5 Debugging Interfaces

1 2 3 7 10
12

AVR ATmega64A PERIPHERALS 2.1 Interrupts 2.2 I/O Ports 2.3 USART

14 15 18 23
27 27 28 29 31 33 37

DEVELOPMENT BOARD AND PERIPHERALS


3.1 UniBoard Development Board 3.2 Needs for programming the Board 3.3 Hardware Connections 3.4 F ea tu r es 3.5 Setting up Board Configuration 3.6 Gen er a l P urp ose P ORT S

SESORS
4.1 Temperature Sensor 4.2 CMOS Humidity Sensors

39
39 43

4.3 Soil Moisture Sensor 5

49 55 55 65 66

Relay And Motor Driver


5.1 Relay 5.2 Motor Driver

Conclusions REFERENCES
APPENDIX

67
68-79

vi

LIST OF FIGURES
1.2 1.3 Atmega 64 Uniboard development board 4 10 10 15 19 30 38 39 40 46 49 50 50 55 56 56 58 59 60 62 64 65

1.4.6 Uniboard development board 2.1 2.2 3.3 3.6 4.1 Program memory I/O Pin Equivalent Schematic UniBoard Atmege 64 Development Board Pin out Diagram Of Atmega64 LM35- Temperature Sensor

4.1.1 LM35 Sensor Pin outs and Packaging 4.2.3 Humidity sensor 4.3.1 Soil moisture sensor LM324 4.3.2 Pin Out LM324 4.3.3 Pin Diagram of LM324 5.1 Working Of Relay

5.1.1 Electromagnetic Relay 5.1.2 Electromagnetic Relay Operation 5.1.3 Latching Relay 5.1.4 Reed Relay 5.1.5 Solid State Relay 5.1.6 A DPDT AC coil relay with "ice cube" packaging 5.1.7 Relay Driver 5.2 Motor Driver Pin Out

vii

LIST OF TABLES
2.1.1 Port A Pins Alternate Functions 2.2.2 Overriding Signals for Alternate Functions in PA7.PA4 2.2.3 Overriding Signals for Alternate Functions in PA3.PA0 2.2.4 Port C Pins Alternate Functions 2.2.5 Overriding Signals for Alternate Functions in PC7.PC4 2.2.6 Overriding Signals for Alternate Functions in PC3.PC0 20 20 21 21 22 23

viii

Crop Monitoring System

CHAPTER 1 INTRODUCTION
The original AVR MCU was developed at a local ASIC house in Trondheim, Norway called Nordic VLSI at the time, now Nordic Semiconductor, where Bogen and Wollan were working as students. It was known as a RISC (Micro RISC) and was available as silicon IP/building block from Nordic VLSI. When the technology was sold to Atmel from Nordic VLSI, the internal architecture was further developed by Bogen and Wollan at Atmel Norway, a subsidiary of Atmel. The designers worked closely with compiler writers at IAR Systems to ensure that the instruction set provided for more efficient compilation of high-level languages. Atmel says that the name AVR is not an acronym and does not stand for anything in particular. The creators of the AVR give no definitive answer as to what the term "AVR" stands for. However, it is commonly accepted that AVR stands for Alf (Egil Bogen) andVegard (Wollan)'s RISC processor. Note that the use of "AVR" in this article generally refers to the 8-bit RISC line of Atmel AVR Microcontrollers. Among the first of the AVR line was the AT90S8515, which in a 40-pin DIP package has the same pinout as an 8051 microcontroller, including the external multiplexed address and data bus. The polarity of the RESET line was opposite (8051's having an active-high RESET, while the AVR has an active-low RESET), but other than that the pinout was identical. Based on industry-leading, proven technology, the megaAVR family offers our widest selection of devices in terms of memories, pin-counts and peripherals. Choose from generalpurpose devices to models with specialized peripherals like USB, or LCD controllers, or CAN, LIN and Power Stage Controllers. It's easy to find the perfect fit for your project in the megaAVR product family. Being supported by the Atmel Studio development platform further reduces your time-to-market.

Department of Electronics and Communication Engg.

Page 1

Crop Monitoring System

1.1

Device overview
The AVR is a modified Harvard architecture machine where program and data are

stored in separate physical memory systems that appear in different address spaces, but having the ability to read data items from program memory using special instructions. Basic families AVRs are generally classified into six broad groups:

tinyAVR the ATtiny series 0.516 kB program memory 632-pin package Limited peripheral set megaAVR the ATmega series 4512 kB program memory 28100-pin package Extended instruction set (multiply instructions and instructions for handling larger program memories)

Extensive peripheral set XMEGA the ATxmega series 16384 kB program memory 4464100-pin package (A4, A3, A1) Extended performance features, such as DMA, "Event System", and cryptography support. Extensive peripheral set with ADCs Application-specific AVR megaAVRs with special features not found on the other members of the AVR family, such as LCD controller, USB controller, advanced PWM, CAN, etc.

Department of Electronics and Communication Engg.

Page 2

Crop Monitoring System

FPSLIC (AVR with FPGA) FPGA 5K to 40K gates SRAM for the AVR program code, unlike all other AVRs AVR core can run at up to 50 MHz 32-bit AVRs In 2006 Atmel released microcontrollers based on the 32-bit AVR32 architecture. They include SIMD and DSP instructions, along with other audio and video processing features. This 32-bit family of devices is intended to compete with the ARM based processors. The instruction set is similar to other RISC cores, but it is not compatible with the original AVR or any of the various ARM cores.

1.2 Device architecture


Flash, EEPROM, and SRAM are all integrated onto a single chip, removing the need for external memory in most applications. Some devices have a parallel external bus option to allow adding additional data memory or memory-mapped devices. Almost all devices (except the smallest TinyAVR chips) have serial interfaces, which can be used to connect larger serial EEPROMs or flash chips. Program memory Program instructions are stored in non-volatile flash memory. Although the MCUs are 8-bit, each instruction takes one or two 16-bit words. The size of the program memory is usually indicated in the naming of the device itself (e.g., the ATmega64x line has 64 kB of flash while the ATmega32x line has 32 kB). There is no provision for off-chip program memory; all code executed by the AVR core must reside in the on-chip flash. However, this limitation does not apply to the AT94 FPSLIC AVR/FPGA chips. Internal data memory The data address space consists of the register file, I/O registers, and SRAM.
Department of Electronics and Communication Engg. Page 3

Crop Monitoring System

Fig 1.2 Atmega 64A Internal registers The AVRs have 32 single-byte registers and are classified as 8-bit RISC devices. In most variants of the AVR architecture, the working registers are mapped in as the first 32 memory addresses (000016001F16) followed by the 64 I/O registers (002016005F16). Actual SRAM starts after these register sections (address 006016). (Note that the I/O register space may be larger on some more extensive devices, in which case the memory mapped I/O registers will occupy a portion of the SRAM address space.) Even though there are separate addressing schemes and optimized opcodes for register file and I/O register access, all can still be addressed and manipulated as if they were in SRAM.In the XMEGA variant, the working register file is not mapped into the data address space; as such, it is not possible to treat any of the XMEGA's working registers as though they were SRAM. Instead, the I/O registers are mapped into the data address space starting at the very beginning of the address space. Additionally, the amount of data address space dedicated to I/O registers has grown substantially to 4096 bytes (0000160FFF16). As with previous generations, however, the fast I/O manipulation instructions can only reach the first 64 I/O register locations (the first 32 locations for bitwise instructions). Following the I/O registers, the XMEGA series sets aside a 4096 byte range of the data address space which can be used optionally for mapping

Department of Electronics and Communication Engg.

Page 4

Crop Monitoring System

the internal EEPROM to the data address space (1000161FFF16). The actual SRAM is located after these ranges, starting at 200016. I/O Registers in AVR Each port consists of three registes: DDRx, PORTx and PINx.

DDRx : Data direction register. PORTx : Output port register. Used only for output. PINx : Input register. Used only for input. Pin toggling with PINx: "writing a logic one to PINx n bit toggles the value of PORTx n bit, independent on the value of DDRx n". This may not be true for all AVR devices, check the datasheet of the device. EEPROM Almost all AVR microcontrollers have internal EEPROM for semi-permanent data storage. Like flash memory, EEPROM can maintain its contents when electrical power is removed. In most variants of the AVR architecture, this internal EEPROM memory is not mapped into the MCU's addressable memory space. It can only be accessed the same way an external peripheral device is, using special pointer registers and read/write instructions which makes EEPROM access much slower than other internal RAM. However, some devices in the SecureAVR (AT90SC) family [7] use a special EEPROM mapping to the data or program memory depending on the configuration. The XMEGA family also allows the EEPROM to be mapped into the data address space. Since the number of writes to EEPROM is not unlimited Atmel specifies 100,000 write cycles in their datasheets a well designed EEPROM write routine should compare the contents of an EEPROM address with desired contents and only perform an actual write if the contents need to be changed. Note that erase and write can be performed separately in many cases, byte-by-byte, which may also help prolong life when bits only need to be set to all 1s (erase) or selectively cleared to 0s (write).

Department of Electronics and Communication Engg.

Page 5

Crop Monitoring System

Program execution Atmel's AVRs have a two stage, single level pipeline design. This means the next machine instruction is fetched as the current one is executing. Most instructions take just one or two clock cycles, making AVRs relatively fast among eight-bit microcontrollers. The AVR processors were designed with the efficient execution of compiled C code in mind and have several built-in pointers for the task. Instruction set Main article: Atmel AVR instruction set The AVR instruction set is more orthogonal than those of most eight-bit microcontrollers, in particular the 8051 clones and PIC microcontrollers with which AVR competes today. However, it is not completely regular:

Pointer registers X, Y, and Z have addressing capabilities that are different from each other.

Register locations R0 to R15 have different addressing capabilities than register locations R16 to R31.

I/O ports 0 to 31 have different addressing capabilities than I/O ports 32 to 63. CLR affects flags, while SER does not, even though they are complementary instructions. CLR set all bits to zero and SER sets them to one. (Note that CLR is pseudo-op for EOR R, R; and SER is short for LDI R,$FF. Math operations such as EOR modify flags while moves/loads/stores/branches such as LDI do not.)

Accessing read-only data stored in the program memory (flash) requires special LPM instructions; the flash bus is otherwise reserved for instruction memory.

Additionally, some chip-specific differences affect code generation. Code pointers (including return addresses on the stack) are two bytes long on chips with up to 128 kBytes of flash memory, but three bytes long on larger chips; not all chips have hardware multipliers; chips with over 8 kBytes of flash have branch and call instructions with longer ranges; and so forth.
Department of Electronics and Communication Engg. Page 6

Crop Monitoring System

The mostly regular instruction set makes programming it using C (or even Ada) compilers fairly straightforward. GCC has included AVR support for quite some time, and that support is widely used. In fact, Atmel solicited input from major developers of compilers for small microcontrollers, to determine the instruction set features that were most useful in a compiler for high-level languages. MCU speed The AVR line can normally support clock speeds from 0 to 20 MHz, with some devices reaching 32 MHz. Lower powered operation usually requires a reduced clock speed. All recent (Tiny, Mega, and Xmega, but not 90S) AVRs feature an on-chip oscillator, removing the need for external clocks or resonator circuitry. Some AVRs also have a system clock prescaler that can divide down the system clock by up to 1024. This prescaler can be reconfigured by software during run-time, allowing the clock speed to be optimized. Since all operations (excluding literals) on registers R0 - R31 are single cycle, the AVR can achieve up to 1 MIPS per MHz, i.e. an 8 MHz processor can achieve up to 8 MIPS. Loads and stores to/from memory take two cycles, branching takes two cycles. Branches in the latest "3-byte PC" parts such as ATmega2560 are one cycle slower than on previous devices.

1.3 Development and Features


AVRs have a large following due to the free and inexpensive development tools available, including reasonably priced development boards and free development software. The AVRs are sold under various names that share the same basic core, but with different peripheral and memory combinations. Compatibility between chips in each family is fairly good, although I/O controller features may vary. See external links for sites relating to AVR development. Features Current AVRs offer a wide range of features:

Department of Electronics and Communication Engg.

Page 7

Crop Monitoring System

Multifunction, bi-directional general-purpose I/O ports with configurable, built-in pull-up resistors

Multiple internal oscillators, including RC oscillator without external parts Internal, self-programmable instruction flash memory up to 256 kB (384 kB on XMega)

In-system programmable using serial/parallel low-voltage proprietary interfaces or JTAG Optional boot code section with independent lock bits for protection

On-chip debugging (OCD) support through JTAG or debugWIRE on most devices

The JTAG signals (TMS, TDI, TDO, and TCK) are multiplexed on GPIOs. These pins can be configured to function as JTAG or GPIO depending on the setting of a fuse bit, which can be programmed via ISP or HVSP. By default, AVRs with JTAG come with the JTAG interface enabled.

debugWIRE uses the /RESET pin as a bi-directional communication channel to access on-chip debug circuitry. It is present on devices with lower pin counts, as it only requires one pin.

Internal data EEPROM up to 4 kB Internal SRAM up to 16 kB (32 kB on XMega) External 64 kB little endian data space on certain models, including the Mega8515 and Mega162.

The external data space is overlaid with the internal data space, such that the full 64 kB address space does not appear on the external bus and accesses to e.g. address 010016 will access internal RAM, not the external bus.

In certain members of the XMega series, the external data space has been enhanced to support both SRAM and SDRAM. As well, the data addressing modes have been expanded to allow up to 16 MB of data memory to be directly addressed.

AVRs

generally

do

not

support

executing

code

from

external

memory.

Some ASSPs using the AVR core do support external program memory.

8-bit and 16-bit timers

PWM output (some devices have an enhanced PWM peripheral which includes a deadtime generator)
Page 8

Department of Electronics and Communication Engg.

Crop Monitoring System

Input capture that record a time stamp triggered by a signal edge

Analog comparator 10 or 12-bit A/D converters, with multiplex of up to 16 channels 12-bit D/A converters A variety of serial interfaces, including

IC compatible Two-Wire Interface (TWI) Synchronous/asynchronous serial peripherals (UART/USART) (used with RS-232, RS485, and more)

Serial Peripheral Interface Bus (SPI) Universal Serial Interface (USI) for two or three-wire synchronous data transfer

Brownout detection Watchdog timer (WDT) Multiple power-saving sleep modes Lighting and motor control (PWM-specific) controller models CAN controller support USB controller support

Proper full-speed (12 Mbit/s) hardware & Hub controller with embedded AVR. Also freely available low-speed (1.5 Mbit/s) (HID) bitbanging software emulations

Ethernet controller support LCD controller support Low-voltage devices operating down to 1.8 V (to 0.7 V for parts with built-in DCDC upconverter)

picoPower devices DMA controllers and "event system" peripheral communication. Fast cryptography support for AES and DES.

Department of Electronics and Communication Engg.

Page 9

Crop Monitoring System

Fig 1.3 Uniboard development board

1.4 Programming interfaces:


There are many means to load program code into an AVR chip. The methods to program AVR chips varies from AVR family to family. ISP

Fig 1.4.6 10-pin ISP header diagrams The in-system programming (ISP) programming method is functionally performed through SPI, plus some twiddling of the Reset line. As long as the SPI pins of the AVR are not connected to anything disruptive, the AVR chip can stay soldered on a PCB while reprogramming. All that is needed is a 6-pin connector and programming adapter. This is the most common way to develop with an AVR. The Atmel AVR ISP mkII device connects to a computer's USB port and performs in-system programming using Atmel's software. AVRDUDE (AVR Downloader/UploaDEr) runs
Department of Electronics and Communication Engg. Page 10

Crop Monitoring System

on Linux, FreeBSD, Windows, and Mac OS X, and supports a variety of in-system programming hardware, including Atmel AVR ISP mkII, Atmel JTAG ICE, older Atmel serial-port based programmers, and various third-party and "do-it-yourself" programmers. PDI The Program and Debug Interface (PDI) is an Atmel proprietary interface for external programming and on-chip debugging of XMEGA devices. The PDI supports high-speed programming of all non-volatile memory (NVM) spaces; flash, EEPROM, fuses, lock-bits and the User Signature Row. This is done by accessing the XMEGA NVM controller through the PDI interface, and executing NVM controller commands. The PDI is a 2-pin interface using the Reset pin for clock input (PDI_CLK) and a dedicated data pin (PDI_DATA) for input and output. High voltage serial High-voltage serial programming (HVSP) is mostly the backup mode on smaller AVRs. An 8pin AVR package does not leave many unique signal combinations to place the AVR into a programming mode. A 12 volt signal, however, is something the AVR should only see during programming and never during normal operation. High voltage parallel High voltage parallel programming (HVPP) is considered the "final resort" and may be the only way to fix AVR chips with bad fuse settings. ROM The AT90SC series of AVRs are available with a factory mask-ROM rather than flash for program memory.[15] Because of the large up-front cost and minimum order quantity, a maskROM is only cost-effective for high production runs. aWire aWire is a new one-wire debug interface available on the new UC3L AVR32 devices.

Department of Electronics and Communication Engg.

Page 11

Crop Monitoring System

1.5 Debugging interfaces


The AVR offers several options for debugging, mostly involving on-chip debugging while the chip is in the target system. Debug WIRE Debug WIRE is Atmel's solution for providing on-chip debug capabilities via a single microcontroller pin. It is particularly useful for lower pin count parts which cannot provide the four "spare" pins needed for JTAG. The JTAGICE mkII, mkIII and the AVR Dragon support debug WIRE. It was developed after the original JTAGICE release, and now clones support it. JTAG The Joint Test Action Group (JTAG) feature provides access to on-chip debugging functionality while the chip is running in the target system. JTAG allows accessing internal memory and registers, setting breakpoints on code, and single-stepping execution to observe system behaviour. Atmel provides a series of JTAG adapters for the AVR: 1. The JTAGICE 3 is the latest member of the JTAGICE family (JTAGICE mkIII). It supports JTAG, aWire, SPI, and PDI interfaces. 2. The JTAGICE mkII replaces the JTAGICE and is similarly priced. The JTAGICE mkII interfaces to the PC via USB, and supports both JTAG and the newer debugWIRE interface. Numerous third-party clones of the Atmel JTAGICE mkII device started shipping after Atmel released the communication protocol. 3. The AVR Dragon is a low-cost (approximately $50) substitute for the JTAGICE mkII for certain target parts. The AVR Dragon provides in-system serial programming, highvoltage serial programming and parallel programming, as well as JTAG or debugWIRE emulation for parts with 32 KB of program memory or less. ATMEL changed the debugging feature of AVR Dragon with the latest firmware of AVR Studio 4 - AVR Studio 5 and now it supports devices over 32 KB of program memory.

Department of Electronics and Communication Engg.

Page 12

Crop Monitoring System

4. The JTAGICE adapter interfaces to the PC via a standard serial port. Although the JTAGICE adapter has been declared "end-of-life" by Atmel, it is still supported in AVR Studio and other tools. JTAG can also be used to perform a boundary scan test, which tests the electrical connections between AVRs and other boundary scan capable chips in a system. Boundary scan is well-suited for a production line, while the hobbyist is probably better off testing with a multimeter or oscilloscope.

Department of Electronics and Communication Engg.

Page 13

Crop Monitoring System

CHAPTER 2 AVR ATmega64A PERIPHERALS


The AVR architecture has two main memory spaces, the Data Memory and the Program Memory space. In addition, the ATmega64 features an EEPROM Memory for data storage. All three memory spaces are linear and regular. In-System Reprogrammable Flash Program Memory The ATmega64 contains 64 Kbytes On-chip In-System Reprogrammable Flash memory for program storage. Since all AVR instructions are 16 bits or 32 bits wide, the Flash is organized as 32K x 16. For software security, the Flash Program memory space is divided into two sections, Boot Program section and Application Program section. The Flash memory has an endurance of at least 10,000 write/erase cycles. The ATmega64 Program Counter (PC) is 15 bits wide, thus addressing the 32K program memory locations. Constant tables can be allocated within the entire program memory address space (see the LPM Load Program Memory instruction description).

SRAM Data Memory The ATmega64 is a complex microcontroller with more peripheral units than can be supported within the 64 locations reserved in the Opcode for the IN and OUT instructions. For the Extended I/O space from 0x60 - 0xFF in SRAM, only the ST/STS/STD and LD/LDS/LDD instructions can be used. The Extended I/O space does not exist when the ATmega64 is in the ATmega103 compatibility mode. The first 4,352 data memory locations address both the Register File, the I/O memory, Extended I/O memory, and the internal data SRAM. The first 32 locations address the Register File, the next 64 location the standard I/O memory, then 160 locations of Extended I/O memory, and the next 4,096 locations address the internal data SRAM. In ATmega103 compatibility mode, the first 4,096 data memory locations address both the Register
Department of Electronics and Communication Engg. Page 14

Crop Monitoring System

File, the I/O memory and the internal data SRAM. The first 32 locations address the Register File, the next 64 location the standard I/O memory, and the next 4,000 locations address the internal data SRAM.

Fig 2.1 Program memory

2.1 Interrupts
Address 1 0x0000 Source Interrupt Definition RESET External Pin, Power-on Reset, Brown-outReset, Watchdog Reset, and JTAG AVR Reset 2 0x0002 3 0x0004 INT0 External Interrupt Request 0 INT1 External Interrupt Request 1
Page 15

Department of Electronics and Communication Engg.

Crop Monitoring System

4 0x0006 5 0x0008 6 0x000A 7 0x000C 8 0x000E 9 0x0010 10 0x0012 11 0x0014 12 0x0016 13 0x0018 14 0x001A 15 0x001C 16 0x001E 17 0x0020 18 0x0022 19 0x0024 20 0x0026 21 0x0028 22 0x002A 23 0x002C 24 0x002E 25 0x0030 26 0x0032 27 0x0034 28 0x0036 29 0x0038 30 0x003A 31 0x003C

INT2 External Interrupt Request 2 INT3 External Interrupt Request 3 INT4 External Interrupt Request 4 INT5 External Interrupt Request 5 INT6 External Interrupt Request 6 INT7 External Interrupt Request 7 TIMER2 COMP Timer/Counter2 Compare Match TIMER2 OVF Timer/Counter2 Overflow TIMER1 CAPT Timer/Counter1 Capture Event TIMER1 COMPA Timer/Counter1 Compare Match A TIMER1 COMPB Timer/Counter1 Compare Match B TIMER1 OVF Timer/Counter1 Overflow TIMER0 COMP Timer/Counter0 Compare Match TIMER0 OVF Timer/Counter0 Overflow SPI, STC SPI Serial Transfer Complete USART0, RX USART0, Rx Complete USART0, UDRE USART0 Data Register Empty USART0, TX USART0, Tx Complete ADC ADC Conversion Complete EE READY EEPROM Ready ANALOG COMP Analog Comparator TIMER1 COMPC Timer/Countre1 Compare Match C TIMER3 CAPT Timer/Counter3 Capture Event TIMER3 COMPA Timer/Counter3 Compare Match A TIMER3 COMPB Timer/Counter3 Compare Match B TIMER3 COMPC Timer/Counter3 Compare Match C TIMER3 OVF Timer/Counter3 Overflow USART1, RX USART1, Rx Complete

The most typical and general program setup for the Reset and Interrupt Vector Addresses in
Department of Electronics and Communication Engg. Page 16

Crop Monitoring System

ATmega64 is: Address Labels Code Comments 0x0000 jmp RESET ; Reset Handler 0x0002 jmp EXT_INT0 ; IRQ0 Handler 0x0004 jmp EXT_INT1 ; IRQ1 Handler 0x0006 jmp EXT_INT2 ; IRQ2 Handler 0x0008 jmp EXT_INT3 ; IRQ3 Handler 0x000A jmp EXT_INT4 ; IRQ4 Handler 0x000C jmp EXT_INT5 ; IRQ5 Handler 0x000E jmp EXT_INT6 ; IRQ6 Handler 0x0010 jmp EXT_INT7 ; IRQ7 Handler 0x0012 jmp TIM2_COMP ; Timer2 Compare Handler 0x0014 jmp TIM2_OVF ; Timer2 Overflow Handler 0x0016 jmp TIM1_CAPT ; Timer1 Capture Handler 0x0018 jmp TIM1_COMPA ; Timer1 CompareA Handler 0x001A jmp TIM1_COMPB ; Timer1 CompareB Handler 0x001C jmp TIM1_OVF ; Timer1 Overflow Handler 0x001E jmp TIM0_COMP ; Timer0 Compare Handler 0x0020 jmp TIM0_OVF ; Timer0 Overflow Handler The General Interrupt Control Register controls the placement of the Interrupt Vector table. MCUCR MCU Control Register
7 6 5 4 3 2 1 0

SRE

SRW10

SE

SM1

SM0

SM2

IVSEL

IVCE

Bit 1 IVSEL: Interrupt Vector Select When the IVSEL bit is cleared (zero), the Interrupt Vectors are placed at the start of the Flash Memory. When this bit is set (one), the Interrupt Vectors are moved to the beginning of the Boot Loader section of the Flash. The actual address of the start of the Boot Flash section is determined by the BOOTSZ Fuses. To avoid unintentional changes of Interrupt Vector tables, a special write procedure must be followed to change the IVSEL bit:
Department of Electronics and Communication Engg. Page 17

Crop Monitoring System

1. Write the Interrupt Vector Change Enable (IVCE) bit to one. 2. Within four cycles, write the desired value to IVSEL while writing a zero to IVCE. Interrupts will automatically be disabled while this sequence is executed. Interrupts are disabled in the cycle IVCE is set, and they remain disabled until after the instruction following the write to IVSEL. If IVSEL is not written, interrupts remain disabled for four cycles. The I-bit in the Status Register is unaffected by the automatic disabling. Note: If Interrupt Vectors are placed in the Boot Loader section and Boot Lock bit BLB02 is programmed, interrupts are disabled while executing from the Application section. If Interrupt Vectors are placed in the Application section and Boot Lock bit BLB12 is programed, interrupts are disabled while executing from the Boot Loader section. Bit 0 IVCE: Interrupt Vector Change Enable The IVCE bit must be written to logic one to enable change of the IVSEL bit. IVCE is cleared by hardware four cycles after it is written or when IVSEL is written. Setting the IVCE bit will disable interrupts, as explained in the IVSEL description above.

2.2 I/O Ports


All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that the direction of one port pin can be changed without unintentionally changing the direction of any other pin with the SBI and CBI instructions. The same applies when changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if configured as input). Each output buffer has symmetrical drive characteristics with both high sink and source capability. The pin driver is strong enough to drive LED displays directly. All port pins have individually selectable pull-up resistors with a supply voltage invariant resistance.

Department of Electronics and Communication Engg.

Page 18

Crop Monitoring System

Fig 2.2 I/O Pin Equivalent Schematic All registers and bit references in this section are written in general form. A lower case x represents the numbering letter for the port, and a lower case n represents the bit number. However,when using the register or bit defines in a program, the precise form must be used (i.e., PORTB3 for bit no. 3 in Port B, here documented generally as PORTxn). Three I/O memory address locations are allocated for each port, one each for the Data Register PORTx, Data Direction Register DDRx, and the Port Input Pins PINx. The Port Input Pins I/O location is read only, while the Data Register and the Data Direction Register are read/write. In addition, the Pull-up Disable PUD bit in SFIOR disables the pull-up function for all pins in all ports when set. Note that enabling the alternate function of some of the port pins does not affect the use of the other pins in the port as general digital I/O.

Alternate Functions of Port A The Port A has an alternate function as the address low byte and data lines for the External Memory Interface.

Department of Electronics and Communication Engg.

Page 19

Crop Monitoring System

Port Pin PA7 PA6 PA5 PA4 PA3 PA2 PA1 PA0

Alternate Function AD7 (External memory interface address and data bit 7) AD6 (External memory interface address and data bit 6) AD5 (External memory interface address and data bit 5) AD4 (External memory interface address and data bit 4) AD3 (External memory interface address and data bit 3) AD2 (External memory interface address and data bit 2) AD1 (External memory interface address and data bit 1) AD0 (External memory interface address and data bit 0) Table 2.2.1 Port A Pins Alternate Functions

SignalName PUOE PUOV

PA7/AD7 SRE ~(WR | ADA) PORTA7PUD

PA6/AD6 SRE ~(WR|ADA) PORTA6PUD

PA5/AD5 SRE ~(WR | ADA) PORTA5 PUD

PA4/AD4 SRE ~(WR | ADA) PORTA4 PUD SRE WR | ADA SRE A4 ADA | D4 OUTPUT WR 0 0 D4 INPUT

DDOE DDOV PVOE PVOV

SRE WR | ADA SRE A7 ADA | D7 OUTPUT WR

SRE WR | ADA SRE A6 ADA | D6 OUTPUT WR

SRE WR | ADA SRE A5 ADA | D5 OUTPUT WR

DIEOE DIEOV DI AIO

0 0 D7 INPUT

0 0 D6 INPUT

0 0 D5 INPUT

Table 2.2.2 Overriding Signals for Alternate Functions in PA7..PA4

Department of Electronics and Communication Engg.

Page 20

Crop Monitoring System

Signal Name PUOE PUOV

PA3/AD3 SRE ~(WR | ADA) PORTA3 PUD SRE WR | ADA SRE A3 ADA | D3 OUTPUT WR 0 0 D3 INPUT

PA2/AD2 SRE ~(WR | ADA) PORTA2 PUD SRE WR | ADA SRE A2 ADA | D2 OUTPUT WR 0 0 D2 INPUT

PA1/AD1 SRE ~(WR | ADA) PORTA1 PUD SRE WR | ADA SRE A1 ADA | D1 OUTPUT WR 0 0 D1 INPUT

PA0/AD0 SRE ~(WR | ADA) PORTA0 PUD SRE WR | ADA SRE A0 ADA | D0 OUTPUT WR 0 0 D0 INPUT

DDOE DDOV PVOE PVOV

DIEOE DIEOV DI AIO

Table 2.2.3. Overriding Signals for Alternate Functions in PA3..PA0

Alternate Functions of Port C In ATmega103 compatibility mode, Port C is output only. The Port C has an alternate function as the address high byte for the External Memory Interface. Port Pin PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0 Alternate Function A15 A14 A13 A12 A11 A10 A9 A8

Table 2.2.4 Port C Pins Alternate Functions


Department of Electronics and Communication Engg. Page 21

Crop Monitoring System

Signal Name PUOE

PC7/A15 SRE (XMM<1)

PC6/A14 SRE (XMM<2)

PC5/A13

PC4/A12

SRE (XMM<3) SRE (XMM<4)

PUOV DDOE

0 SRE (XMM<1)

0 SRE (XMM<2)

0 SRE (XMM<3 SRE

(XMM<4) 1 SRE (XMM<2) 1 SRE (XMM<3) SRE (XMM<4) A10 0 0 A9 0 0 A8 0 0 1

DDOV PVOE SRE

(XMM<1) PVOV DIEOE DIEOV DI AIO A11 0 0

Table 2.2.5 Overriding Signals for Alternate Functions in PC7..PC4

Signal Name PUOE

PC3/A11

PC2/A10 SRE

PC1/A9

PC0/A8 SRE (XMM<7)

SRE (XMM<5) SRE (XMM<6)

(XMM<7) 0 SRE (XMM<7) 1 SRE (XMM<7) A9 A8


Page 22

PUOV DDOE

0 SRE (XMM<5) SRE

0 SRE (XMM<7)

(XMM<6) DDOV PVOE 1 SRE (XMM<5) SRE (XMM<6) PVOV A11 A10 1

1 SRE (XMM<7)

Department of Electronics and Communication Engg.

Crop Monitoring System

DIEOE DIEOV DI AIO

0 0

0 0

0 0

0 0

Table 2.2.6 Overriding Signals for Alternate Functions in PC3..PC0

2.3 USART
The Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) is a highly flexible serial communication device. The main features are: Full Duplex Operation (Independent Serial Receive and Transmit Registers) Asynchronous or Synchronous Operation Master or Slave Clocked Synchronous Operation High Resolution Baud Rate Generator Supports Serial Frames with 5, 6, 7, 8, or 9 Data Bits and 1 or 2 Stop Bits Odd or Even Parity Generation and Parity Check Supported by Hardware Data OverRun Detection Framing Error Detection Noise Filtering Includes False Start Bit Detection and Digital Low Pass Filter Three Separate Interrupts on TX Complete, TX Data Register Empty and RX Complete Multi-processor Communication Mode Double Speed Asynchronous Communication Mode 3.3.1 Dual USART The ATmega64 has two USARTs, USART0 and USART1. USART0 and USART1 have different I/O Registers. Note that in ATmega103 compatibility mode, USART1 is not available, neither is the UBRR0H or UCRS0C registers. This means that in ATmega103 compatibility mode, the ATmega64 supports asynchronous operation of USART0 only.

Department of Electronics and Communication Engg.

Page 23

Crop Monitoring System

Fig 2.3.1 USART Block Diagram The dashed boxes in the block diagram separate the three main parts of the USART (listed from the top): Clock generator, Transmitter and Receiver. Control registers are shared by all units.The Clock Generation logic consists of synchronization logic for external clock input used by synchronous slave operation, and the baud rate generator. The XCK (Transfer Clock) pin is only used by synchronous transfer mode. The Transmitter consists of a single write buffer, a serial Shift Register, Parity Generator and Control Logic for handling different serial frame formats. The write buffer allows a continuous transfer of data without any delay between frames. The Receiver is the most complex part of the USART module due to its clock and data recovery
Department of Electronics and Communication Engg. Page 24

Crop Monitoring System

units. The recovery units are used for asynchronous data reception. In addition to the recovery units, the Receiver includes a Parity Checker, Control Logic, a Shift Register and a two level receive buffer (UDRn). The Receiver supports the same frame formats as the Transmitter, and can detect Frame Error, Data OverRun and Parity Errors. AVR USART vs. AVR UART Compatibility The USART is fully compatible with the AVR UART regarding: Bit locations inside all USART Registers Baud Rate Generation. Transmitter Operation. Transmit Buffer Functionality. Receiver Operation. However, the receive buffering has two improvements that will affect the compatibility in some Special cases: A second buffer register has been added. The two buffer registers operate as a circular FIFO buffer. Therefore the UDRn must only be read once for each incoming data! More important is the fact that the error flags (FEn and DORn) and the ninth data bit (RXB8n) are buffered with the data in the receive buffer. Therefore the status bits must always be read before the UDRn Register is read. Otherwise the error status will be lost since the buffer state is lost. The Receiver Shift Register can now act as a third buffer level. This is done by allowing the received data to remain in the serial Shift Register if the buffer registers are full, until a new start bit is detected. The USART is therefore more resistant to Data Over Run (DORn) error conditions. The following control bits have changed name, but have same functionality and register location: CHR9 is changed to UCSZn2. OR is changed to DORn. Clock Generation The Clock Generation logic generates the base clock for the Transmitter and Receiver. The USART supports four modes of clock operation: Normal asynchronous, Double Speed asynchronous, Master synchronous and Slave synchronous mode. The UMSELn bit in USART Control and Status Register n C (UCSRnC) selects between asynchronous and
Department of Electronics and Communication Engg. Page 25

Crop Monitoring System

synchronous operation. Double Speed (asynchronous mode only) is controlled by the U2Xn found in the UCSRnB Register. When using synchronous mode (UMSELn = 1), the Data Direction Register for the XCK pin (DDR_XCK) controls whether the clock source is internal (Master mode) or external (Slave mode). The XCK pin is only active when using synchronous mode. External Clock External clocking is used by the synchronous slave modes of operation. External clock input from the XCK pin is sampled by a synchronization register to minimize the chance of meta-stability. The output from the synchronization register must then pass through an edge detector before it can be used by the Transmitter and Receiver. This process introduces a two CPU clock period delay and therefore the maximum external XCK clock frequency is limited by the following equation: <

Note that fosc depends on the stability of the system clock source. It is therefore recommended to add some margin to avoid possible loss of data due to frequency variations. Synchronous Clock Operation When synchronous mode is used (UMSELn = 1), the XCK pin will be used as either clock input (Slave) or clock output (Master). The dependency between the clock edges and data sampling or data change is the same. The basic principle is that data input (on RxD) is sampled at the opposite XCK clock edge of the edge the data output (TxD) is changed.

Department of Electronics and Communication Engg.

Page 26

Crop Monitoring System

CHAPTER 3 DEVELOPMENT BOARD AND PERIPHERALS


3.1 Uniboard Development Board
The uNiBoard version 1.1 is an ideal open source development platform for Embedded and Real Time Systems Programming. Powered by a RISC machine (ATMega 64) that provides a throughput of 16 MIPS and up to 64 KB of internal storage (flash), the board would be suitable for any sort of embedded application development. On~board peripherals like Joystick along with the communication ports (RS232) and the Gtkterm driver (hyper~terminal for Windows) make the board apt for basic game development in an Embedded (non~OS) as well as OS based environment. RT Kernels with small footprint (uC/OS~II, FreeRTOS, nut OS) can be ported on the board to gain hands~on experience of Real time application design. The board is powered by the USB port. The board is also programmable through USB port thereby making it complete stand~alone lab equipment needing nothing apart from a basic PC/laptop to get started with the development process. The open interface (open LED interface, open ports) extend the platfo rms role for prototyping applications like external device/sensor interfacing. The controller by itself supports protocols like SPI, I2C (on~board I2C based RTC), UART (dual programmable UART) which can be used for multi~board communication. Additionally, the board also features an on~board motor driver which allows to control up to two DC motors bidirectionally. External supply, if required for the motors can be provided with appropriate hardware configu ration settings. The board along with its content~rich user manual is a perfect companion to have for hobbyists/aspirants seeking a career in Embedded software design, since it can accommodate preliminary applications like port control or sensor data processing built on Embedded C to complex real time applications built on RTOS like DAS (Data Acquisition Systems), embedded web~ server, FAT FS for embedded systems and more.

Department of Electronics and Communication Engg.

Page 27

Crop Monitoring System

3.1.1 Package Contents The uNiBoard development platform with the peripherals listed below uNiBoard development board 1 unit 16 x2 LCD 1u nit Serial cable (DB9) 1 unit USB cable 1 unit FRC connector cables 2 units CD consisting of uNiBoard user manual (based on Linux (Ubuntu) /Windows), essential software packages and sample codes (RTOS/non~OS applications) 1 unit Pouch for storage 1 unit

3.2 Needs for programming the Board


3.2.1 Hardware requirements uNiBoard version 1.1 along with USB cable Serial cable (optional) FRC Cable (optional)

3.2.2 Software requirements Text Editor (Gedit on Linux/Programmers Notepad on Windows) Tool chain (avr~gcc, avr~binutils, avrdude): Installation

procedure is explained in the upcoming sections Serial terminal (Gtkterm on Linux/hyper terminal on windows)
Page 28

Department of Electronics and Communication Engg.

Crop Monitoring System

Driver for usbasp (Windows requires explicit installation)

3.2.3 Safety and precautions to be taken Do not use the external power supply more than 15V. Board and SMD switches should be handled with care. Fuse settings of the target (micro~controller) should be modified only with appropriate knowledge, since locking the fuse section m ight render the board useless. Do not program the Board while you are using SPI lines for communication which might also render the board useless.

3.3 Hardware Connections


The uNiBoard version 1.1 connects to the PC using USB port. As shown in the figure 3.3 on the board there is a serial port and USB port connectors. The serial port is used for debugging purpose while USB port is used for power and burning the hex files into ATmega64 microcontroller.

The USB cable (for power/programming purposes) and serial cable can be interfaced with the PC. The serial cable is optional as we are not using it for programming the hex file into the Atmega128 chip. For any UART related activities having the serial cable is a must.

Department of Electronics and Communication Engg.

Page 29

Crop Monitoring System

Fig 3.3 UniBoard Atmege 64 Development Board

Department of Electronics and Communication Engg.

Page 30

Crop Monitoring System

3.4 Features
3. 4 . 1 B oard Feat u res ATmega64 controller with external crystal of 16MHZ usbasp: ATmega8 based USB programmer for ATmega128 (open source firmware running on hardware licensed under GNU GPLv2 from http://www.fischl.de/usbasp) I2C communication lines SPI communication lines 16x2 alphanumeric LCD with contrast adjustment RTC with Backup Battery Analog Joystick with centre click LDR sensor Buzzer (beneath the processor board) Onboard Motor Driver (L293D) LEDs for USB programmer ready indicator, Programming status indicator, and Power ON indicator Test LEDs (open for interface with any PORT) Open interface Ports such as PORTF/ADC, PORTC JTAG interface(External JTAG hardware required) USB Port for programming the Board Dual programmable UARTs Push Buttons for External Interrupts, Reset
Page 31

Department of Electronics and Communication Engg.

Crop Monitoring System

Configuration Switches for USB Power/External power, External ADC /Joystick and Program Enable/UART0

Modular design to permit replacement of processor board

3.4.2 Control Features The features of Atmega128 are as follows: Advanced RISC Architecture

128K Bytes of In~System Self~programmable Flash program memory 4K Bytes EEPROM 4K Bytes Internal SRAM JTAG (IEEE std. 1149.1 Compliant) Interface Two 8~bit Timer/Counters with Separate pre~scaler and Compare Modes Two Expanded 16~bit Timer/Counters with Separate pre~scaler, Compare Mode and Capture Mode Real Time Counter with Separate Oscillator

Two 8~bit PWM Channels 6 PWM Channels with Programmable Resolution from 2 to 16 Bits 8~channel, 10~bit ADC Byte~oriented Two~wire Serial Interface Dual Programmable Serial USARTs Master/Slave SPI Serial Interface Programmable Watchdog Timer with On~chip Oscillator
Page 32

Department of Electronics and Communication Engg.

Crop Monitoring System

Power~on Reset and Programmable Brown~out Detection External and Internal Interrupt Sources Six Sleep Modes: Idle, ADC Noise Reduction, Power ~save, Power~down, Standby, and Extended Standby

Software Selectable Clock Frequency (using Fuse bits) 53 Programmable I/O Lines 4.5V ~5.5V for Atmega128 Operating Voltages

3.5 Setting up Board Configuration

B oard Descript i on Atmega128 controller The ATmega128 is a low~power 8~bit microcontroller based on the AVR enhanced RISC architecture. The Atmel ATmega128 is a powerful microcontroller that provides a highly flexible and cost effective solution to many embedded control applications. Atmega8 controller with the firmware for programming through USB USBasp is a USB in~circuit programmer for Atmel AVR controllers. It simply consists of an ATMega8 and a couple of passive components. The programmer uses a firmware (USB driver) to program Atmega128 microcontroller. For more information on building USBasp refer http://www.fischl.de/usbasp. It is an open source firmware along with hardware licensed under GNU GPLv2. I2C and RTC (DS1307) with Backup Battery The DS1307 serial real~time clock (RTC) is a low~power, full binary~coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information (Compensation Valid up to

Department of Electronics and Communication Engg.

Page 33

Crop Monitoring System

2100). No special hardware configuratio n is required as it is mounted on our board and internally connected to the processors pins.

Analog sensors (Joystick and LDR) The Joystick (Analog joystick used in PS2 consoles) is connected to the ADC, X axis on channel 1 (PF1) and Y axis on channel 2 (PF2) of the Atmega128 microcontroller. The LDR sensor is connected to channel 0(PF0) of the Atmega128 microcontroller. Buzzer The Buzzer is connected to PA3 of the Atmega128 microcontroller, and lies beneath the processor board. Onboard Motor Driver The Motor driver chip (L293D) is used to drive the motors which can be connected to the PTR connectors as shown in the above figure. Through software you need to configure as follows: PB6 and PB5 PE2 and PE3 (MOTOR1) (MOTOR2) PB4 (CHIP ENABLE)

There are motors which might need higher than 5V (up to 12V) operating voltage. In such cases an external supply can be given to the board and the USB power switch can be toggled to make the external supply available instead of a USB powered connection. External power The external power connector in the above figure can also be used for connecting rechargeable batteries and making the board operate on battery power in case of robotic or other such mobile applications. Test LEDs
Department of Electronics and Communication Engg. Page 34

Crop Monitoring System

Test LED's are pulled~up so to glow the LEDs we need to make the particular port pin Low. You can connect the General Purpose PORT to test LED Port using FRC Cable. Two UART's UART1 is used to connect PC through the MAX232 voltage converter chip since pc uses RS~232 standard for serial port. UART1 can be used for debugging the code or for any sort of interaction with Gtkterm. UART0 is not connected to MAX232 as it is leftopen for communication between two Boards . LCD LCD for uNiBoard is using 4 data lines, 2 control lines and WR of LCD is connected to GND. DATA LINES (PA4, PA5, PA6, PA7) CONTROL LINES (PA0for RS, PA2 for LCD EN) Push Buttons
External Interrupts SW3 (INT6) SW4 (INT7) General Purpose switch

SW1 SW2 Selection Switches


USB Power (Pressed) / External power (Depressed) Joystick (Pressed) / External ADC (Depressed) Program Enable (Pressed) / UART0(Depressed)

(PD6) Active Low (PD7) Active Low Reset SW

Department of Electronics and Communication Engg.

Page 35

Crop Monitoring System

USB Power (Pressed) / External power (Depressed) Refer to the uNiBoard figure where the components have been labeled to understand where these switches are physically placed on the board. While you have connected the uNiBoard cable for programming purposes or for powering the board this switch should be in the pressed position. While connecting any external power supply or battery, this switch s hould be in depressed position. This makes the 7805 voltage regulator come into picture to provide 5V power supply for the ICs. Joystick (Pressed) / External ADC (Depressed) While you are using the analog joystick you are using the internal ADC of the controller which is available at PORTF. The LDR which is another analog sensor is also connected at PORTF. Make sure that this switch is in pressed position while the joystick is being used. In case you want to use the open interface pins of the PORTF, in order to connect external analog sensors or digital sensors (refer labeled figure of uNiBoard), change the switch position to depressed. There is another jumper setting which you would need to do in order to take the LDR out of the circuit. This configuration will be discussed while discussing jumper settings.

Program Enable (Pressed) / UART0( Depressed) While programming the board this is one switch that you should never forget to press, failing which avrdude (programming software will flash an error saying target not found.

Department of Electronics and Communication Engg.

Page 36

Crop Monitoring System

Once programming has been completed in order to gain access to UART0 you will need to keep the switch in the depressed position, since the UART0pins are mult iplexed with the programming pins .

3.6 General Purpose PORTS


PORTC PORTC is an open interface port which can be used to connect any devices on FRC connector.

PORTF (J oystick/LDR/Externa lsensors) PORTF can be used to connect external analog or digital sensors or it can also be used as Joystick or LDR ADC channels. There are two connectors FRC connector and Berg sensor port connector either of which can be used to connect the external sensors. The Berg sensor port connector is compatible with our TRI sensors. You can visit to website at http://www.thinklabs.in/resources/ to checkout TRI sensors and you can buy at http://www.thinklabs.in/shop/.

PORTG PORTG is an open interface portwhich can be used to connect any devices on berg connector.

PORTC and PORT F The PORTC and PORTF (ADC) are open ports and can be connected to test LEDs through FRC cable. These can be accessed using 10~pin the FRC connector.

Department of Electronics and Communication Engg.

Page 37

Crop Monitoring System

Fig 3.6 Pin out Diagram Of Atmega64

Department of Electronics and Communication Engg.

Page 38

Crop Monitoring System

CHAPTER 4 SENSORS
4.1 TEMPERATURE SENSOR
LM 35: (TEMPERATURE /FIRE SENSOR) The LM35 sensor series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. To detect the heat produced during fire occurrence we use temperature sensor.

Fig 4.1 LM35- Temperature Sensor The Temperature Sensor LM35 sensor series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. LM35 Sensor Specification: The LM35 series are precision integrated-circuit LM35 temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 sensor 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
Department of Electronics and Communication Engg. Page 39

Crop Monitoring System

scaling. The LM35 sensor does not require any external calibration or trimming to provide typical accuracies of C at room temperature and C over a full -55 to +150C temperature range. Low cost is assured by trimming and calibration at the wafer level. The LM35's low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 A from its supply, it has very low self-heating, less than 0.1C in still air. The LM35 is rated to operate over a -55 to +150C temperature range, while the LM35C sensor is rated for a -40 to +110C range (-10 with improved accuracy). The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The LM35D sensor is also available in an 8-lead surface mount small outline package and a plastic TO-220 package.

Fig 4.1.1 LM35 Sensor Pin outs and Packaging

Department of Electronics and Communication Engg.

Page 40

Crop Monitoring System

LM35 Sensor Sources: There are several manufacturers of this popular part and each has LM35 sensor specs, datasheets and other free LM35 downloads. This amplifier is available from the following manufacturers.

National Semiconductor On Semiconductor Texas Instruments Fairchild Semiconductor STMicroelectronics Jameco Electronics Analog Devices

Temperature Recorder using LM35: Here is how you can make an LM35 a temperature recorder by using the 12F675 PIC microcontroller as the controller and data store. It generates serial output so that you can view the results on a PC and it also calculates the temperature reading in Fahrenheit sending both to the serial port at half second intervals.

LM35 Sensor Applications: Most commonly-used electrical temperature sensors are difficult to apply. For example, thermocouples have low output levels and require cold junction compensation. Thermistors are nonlinear. In addition, the outputs of these sensors are not linearly proportional to any temperature scale. Early monolithic sensors, such as the LM3911, LM134 and LM135, overcame
Department of Electronics and Communication Engg. Page 41

Crop Monitoring System

many of these difficulties, but their outputs are related to the Kelvin temperature scale rather than the more popular Celsius and Fahrenheit scales. Fortunately, in 1983 two ICs, the LM34 Precision Fahrenheit Temperature Sensor and the LM35 Precision Celsius Temperature Sensor, were introduced. This application note will discuss the LM34, but with the proper scaling factors can easily be adapted to the LM35. The LM35/LM34 has an output of 10 mV/F with a typical nonlinearity of only 0.35F over a 50 to +300F temperature range, and is accurate to within 0.4F typ ically at room temperature (77F). The LM34s low output impedance and linear output characteristic make interfacing with readout or control circuitry easy. An inherent strength of the LM34 sensor over other currently available temperature sensors is that it is not as susceptible to large errors in its output from low level leakage currents. For instance, many monolithic temperature sensors have an output of only 1 A/K. This leads to a 1K error for only 1 -Ampere of leakage current. On the other hand, the LM34 sensor may be operated as a current mode device providing 20 A/ F of output current. The same 1 A of leakage current will cause an error in the LM34s output of only 0.05F (or 0.03K after scaling). Low cost and high accuracy are maintained by performing trimming and calibration procedures at the wafer level. The device may be operated with either single or dual supplies. With less than 70 A of current drain, the LM34 sensor has very little self-heating (less than 0.2F in still air), and comes in a TO-46 metal can package, a SO-8 small outline package and a TO-92 plastic package. The LM35/LM34 is a versatile device, which may be used for a wide variety of applications, including oven controllers and remote temperature sensing. The device is easy to use (there are only three terminals) and will be within 0.02F of a surface to which it is either glued or cemented. The TO-46 package allows the user to solder the sensor to a metal surface, but in doing so, the GND pin will be at the same potential as that metal. For applications where a steady reading is desired despite small changes in temperature, the user can solder the TO-46

Department of Electronics and Communication Engg.

Page 42

Crop Monitoring System

package to a thermal mass. Conversely, the thermal time constant may be decreased to speed up response time by soldering the sensor to a small heat fin.

4.2 CMOS Humidity Sensors


4.2.1 Introduction: Humidity sensors are gaining more significance in diverse areas of measurement and control technology. Manufacturers are not only improving the accuracy and long-term drift of their sensors, they are improving their durability for use in different environments, and simultaneously reducing the component size and the price. A humidity sensor is a device that measures the relative humidity of in a given area. A humidity sensor can be used in both indoors and outdoors. Humidity sensors are available in both analog and digital forms. An analog humidity sensor gauges the humidity of the air relatively using a capacitorbased system. The sensor is made out of a film usually made of either glass or ceramics. The insulator material which absorbs the water is made out of a polymer which takes in and releases water based on the relative humidity of the given area. This changes the level of charge in the capacitor of the on board electrical circuit. A digital humidity sensor works via two micro sensors that are calibrated to the relative humidity of the given area. These are then converted into the digital format via an analog to digital conversion process which is done by a chip located in the same circuit. A machine made electrode based system made out of polymer is what makes up the capacitance for the sensor. This protects the sensor from user front panel (interface). Conventional sensors determine relative air humidity using capacitive measurement technology. For this principle, the sensor element is built out of a film capacitor on different substrates (glass, ceramic, etc.). The dielectric is a polymer which absorbs or releases water proportional to the relative environmental humidity, and thus changes the capacitance of the capacitor, which is measured by an onboard electronic circuit.
Department of Electronics and Communication Engg. Page 43

Crop Monitoring System

The device includes two calibrated micro sensors for relative humidity and temperature which are coupled to an amplification, analogue-to-digital (ND) conversion and serial interface circuit on the same chip. A micro-machined finger electrode system with different protective and polymer cover layers forms the capacitance for the sensor chip, and, in addition to providing the sensor property, simultaneously protects the sensor from interference. This protection comes in "ways previously not achieved," says Mr. Christian. "Total coverage with condensation or even immersion in liquid presents no problems whatsoever. One and a half year hardness tests have already shown this result." The temperature sensor and the humidity sensor together form a single unit, which enables a precise determination of the dewpoint without incurring errors due to temperature gradients between the two sensor elements. However Mr. Christian says the biggest technology leap comes from the linkage of sensor elements with the signal amplifier unit, the ND converter, the calibration data memory, and the digital bus interface - all on a surface area of a few square millimetres. The integration provides improved signal quality and insensitivity to external disturbances (EMC). 4.2.2 FEATURES: 1. 2. Full interchangeability with no calibration required in standard conditions Instantaneous desaturation after long periods in saturation phase

3. Compatible with automatized assembly processes, including wave soldering, reflow and water immersion (1) 4. 5. 6. 7. 8. High reliability and long term stability Patented solid polymer structure Suitable for linear voltage or frequency output circuitry Fast response time Individual marking for compliance to stringent traceability requirements

9. Fully calibrated
Department of Electronics and Communication Engg. Page 44

Crop Monitoring System

10. Digital output 11. Low power consumption 12. Excellent long term stability 13. SMD type package reflow solderable 4.2.3 Description: SHT1x (including SHT10, SHT11 and SHT15) is Sensirions family of surface mountable relative humidity and temperature sensors. The sensors integrate sensor elements plus signal processing on a tiny foot print and provide a fully calibrated digital output. A unique capacitive sensor element is used for measuring relative humidity while temperature is measured by a bandgap sensor. The applied CMOSens technology guarantees excellent reliability and long term stability. Both sensors are seamlessly coupled to a 14bit analog to digital converter and a serial interface circuit. This result in superior signal quality, a fast response time and insensitivity to external disturbances (EMC) Each SHT1x is individually calibrated in a precision humidity chamber. The calibration coefficients are programmed into an OTP memory on the chip. These coefficients are used to internally calibrate the signals from the sensors. The 2-wire serial interface and internal voltage regulation allows for easy and fast system integration. The tiny size and low power consumption makes SHT1x the ultimate choice for even the most demanding applications.SHT1x is supplied in a surface-mountable LCC (Leadless Chip Carrier) which is approved for standard reflow soldering processes. The same sensor is also available with pins (SHT7x) or on flex print (SHTA1).

Department of Electronics and Communication Engg.

Page 45

Crop Monitoring System

Fig 4.2.3 Humidity sensor

4.2.4 PIN configuration: Pin 1 2 3 4 NC Name GND DATA SCK VDD NC Comment Ground Serial Data, bidirectional Serial Clock, input only Source Voltage Must be left unconnected

Power Pins (VDD, GND) The supply voltage of SHT1x must be in the range of 2.4 5.5V, recommended supply voltage is 3.3V. Power supply pins Supply Voltage (VDD) and Ground (GND) must be decoupled with a 100 nF capacitor see Figure 10. The serial interface of the SHT1x is optimized for sensor readout and effective power consumption. The sensor cannot be addressed by I2C protocol; however, the sensor can be connected to an I2C bus without interference with other devices connected to the bus. The controller must switch between the protocols. Serial clock input (SCK) SCK is used to synchronize the communication between microcontroller and SHT1x. Since the interface consists of fully static logic there is no minimum SCK frequency.

Department of Electronics and Communication Engg.

Page 46

Crop Monitoring System

Serial data (DATA) The DATA tri-state pin is used to transfer data in and out of the sensor. For sending a command to the sensor, DATA is valid on the rising edge of the serial clock (SCK) and must remain stable while SCK is high. After the falling edge of SCK the DATA value may be changed. For safe communication DATA valid shall be extended TSU and THO before the rising and after the falling edge of SCK, respectively see Figure 11. For reading data from the sensor, DATA is valid TV after SCK has gone low and remains valid until the next falling edge of SCK. To avoid signal contention the microcontroller must only drive DATA low. An external pull-up resistor (e.g. 10kX) is required to pull the signal high it should be noted that pull-up resistors may be included in I/O circuits of microcontrollers. See Table 2 for detailed I/O characteristic of the sensor. 4.2.5 More advantages Other advantages include very short response times (4 sec at lie), high precision (2% to 5% according to configuration), low power consumption (<3A standby), and small footprint (7x5x3 mm).

The sensor chip can be connected directly to any microprocessor system by means of the digital 2-wire interface. Humidity sensors (hygrometers) measure and report the airs relative humidity. They are used in homes, wine cellars, and working environments that that are so humid that they negatively impact working conditions. Humidity sensors are also used in vehicles, industrial HVAC systems, and meteorological stations to help in the predicting and reporting of weather conditions. 4.2.6 Description of Humidity Sensor Humidity sensors detect the relative humidity of the immediate environments in which they are placed. They measure both the moisture and temperature in the air and express relative humidity
Department of Electronics and Communication Engg. Page 47

Crop Monitoring System

as a percentage of the ratio of moisture in the air to the maximum amount that can be held in the air at the current temperature. As air becomes hotter, it holds more moisture, so the relative humidity changes with the temperature. Most humidity sensors use capacitive measurement to determine the amount of moisture in the air. This type of measurement relies on two electrical conductors with a non-conductive polymer film laying between them to create an electrical field between them. Moisture from the air collects on the film and causes changes in the voltage levels between the two plates. This change is then converted into a digital measurement of the airs relative humidity after taking the air temperature into account. 4.2.7 Uses Private consumers typically use humidity sensors when they suffer from allergies or a respiratory illness that low humidity exacerbates. Conversely, high humidity can encourage mold, fungus, or bacteria growth. Humidity sensors are also used in wine cellars and humidors to help keep the air at a consistent humidity level to prolong wine and cigar storage. Museums, storage facilities, and commercial HVAC systems use the sensors to ensure a consistent level of moisture and air quality in the building(s). Automobiles now use humidity sensors as part of their defogging or defrosting systems to automatically adjust the amount and type of air used for the vehicles air conditioning system. Finally, humidity sensors are also used when collecting weather or oceanographic information while researching or measuring weather effects over time to help predict and analyze weather patterns.

Department of Electronics and Communication Engg.

Page 48

Crop Monitoring System

4.3 Soil Moisture sensor LM324:


General Description:

The LM324 series consists of four independent, high gains; internally frequency compensated operational amplifiers which were designed specifically to operate from a single power supply over a wide range of voltages. Operation from split power supplies is also possible and the low power supply current drain is independent of the magnitude of the power supply voltage. Application areas include transducer amplifiers, DC gain blocks and all the conventional op amp circuits which now can be more easily implemented in single power supply systems. For example, the LM124 series can be directly operated off of the standard +5V power supply voltage which is used in digital systems and will easily provide the required interface electronics without requiring the additional 15V power supplies.

Fig 4.3.1 soil moisture sensor LM324

Department of Electronics and Communication Engg.

Page 49

Crop Monitoring System

Fig 4.3.2 Pin Out LM324

Unique Characteristics In the linear mode the input common-mode voltage range includes ground and the output voltage can also swing to ground, even though operated from only a single power supply voltage. The unity gain cross frequency is temperature compensated. The input bias current is also temperature compensated.

PIN Diagram of LM324:

Fig: 4.3.3 Pin Diagram of LM324


Department of Electronics and Communication Engg. Page 50

Crop Monitoring System

Theory: The LM124LM124/LM224/LM324/LM2902 Low Power Quad Operational Amplifiers series are op amps which operate with only a single power supply voltage, have truedifferential inputs, and remain in the linear mode with an input common-mode voltage of 0 VDC. These amplifiers operate over a wide range of power supply voltage with little change in performance Characteristics. At 25C amplifier operation is possible down to a minimum supply voltage of 2.3 VDC. The pinouts of the package have been designed to simplify PC board layouts. Inverting inputs are adjacent to outputs for all of the amplifiers and the outputs have also been placed at the corners of the package (pins 1, 7, 8, and 14). Precautions should be taken to insure that the power supply for the integrated circuit never becomes reversed in polarity or that the unit is not inadvertently installed backwards in a test socket as an unlimited current surge through the resulting forward diode within the IC could cause fusing of the internal conductors and result in a destroyed unit. Large differential input voltages can be easily accommodated and, as input differential voltage protection diodes are not needed, no large input currents result from large differential input voltages. The differential input voltage may be larger than V+ without damaging the device. Protection should be provided to prevent the input voltages from going negative more than 0.3 VDC (at 25C). An input clamp diode with a resistor to the IC input terminal can be used.

Department of Electronics and Communication Engg.

Page 51

Crop Monitoring System

To reduce the power supply drain, the amplifiers have a class an output stage for small signal levels which converts to class B in a large signal mode. This allows the amplifiers to both source and sinks large output currents. Therefore both NPN and PNP external current boost transistors can be used to extend the power capability of the basic amplifiers. The output voltage needs to raise approximately 1 diode drop above ground to bias the on-chip vertical PNP transistor for output current sinking applications. For ac applications, where the load is capacitive coupled to the output of the amplifier, a resistor should be used, from the output of the amplifier to ground to increase the class a bias current and prevent crossover distortion. Where the load is directly coupled, as in dc applications, there is no crossover distortion. Capacitive loads which are applied directly to the output of the amplifier reduce the loop stability margin. Values of 50 pF can be accommodated using the worst-case non inverting unity gain connection. Large closed loop gains or resistive isolation should be used if larger load capacitance must be driven by the amplifier.

Department of Electronics and Communication Engg.

Page 52

Crop Monitoring System

LM124/LM224/LM324/LM2902 The bias network of the LM124 establishes a drain current which is independent of the magnitude of the power supply voltage over the range of from 3 VDC to 30 VDC. Output short circuits either to ground or to the positive power supply should be of short time duration. Units can be destroyed, not as a result of the short circuit current causing metal fusing, but rather due to the large increase in IC chip dissipation which will cause eventual failure due to excessive junction temperatures. Putting direct short-circuits on more than one amplifier at a time will increase the total IC power dissipation to destructive levels, if not properly protected with external dissipation limiting resistors in series with the output leads of the amplifiers. The larger value of output source current which is available at 25C provides a larger output current capability at elevated temperatures (see typical performance characteristics) than a standard IC op amp. The circuits presented in the section on typical applications emphasize operation on only a single power supply voltage. If complementary power supplies are available, all of the standard op amp circuits can be used. In general, introducing a pseudo-ground (a bias voltage reference of V+/2) will allow operation above and below this value in single power
Department of Electronics and Communication Engg. Page 53

Crop Monitoring System

supply systems. Many application circuits are shown which take advantage of the wide input common-mode voltage range which includes ground. In most cases, input biasing is not required and input voltages which range to ground can easily be accommodated.

Features: 1. Internally frequency compensated for unity gain 2. Large DC voltage gain 100 dB 3. Wide bandwidth (unity gain) 1 MHz (temperature compensated) 4. Wide power supply range: Single supply 3V to 32V or dual supplies 1.5V to 16V 5. Very low supply current drain (700 A)essentially independent of supply voltage 6. Low input biasing current 45 nA (temperature compensated) 7. Low input offset voltage 2 mV and offset current: 5 nA 8. Input common-mode voltage range includes ground 9. Differential input voltage range equal to the power supply voltage 10. Large output voltage swing 0V to V+ 1.5V Advantages: 1. Eliminates need for dual supplies 2. Four internally compensated op amps in a single package 3. Allows directly sensing near GND and VOUT also goes to GND 4. Compatible with all forms of logic 5. Power drain suitable for battery operation

Department of Electronics and Communication Engg.

Page 54

Crop Monitoring System

CHAPTER 5 RELAY AND MOTOR DRIVER


5.1 Relay
A relay is an electrically operated switch. Many relays use an electromagnet to operate a switching mechanism, but other operating principles are also used. Relays find applications where it is necessary to control a circuit by a low-power signal, or where several circuits must be controlled by one signal. The first relays were used in long distance telegraph circuits, repeating the signal coming in from one circuit and re-transmitting it to another. Relays found extensive use in telephone exchanges and early computers to perform logical operations. A type of relay that can handle the high power required to directly drive an electric motor is called a contactor. Solid-state relays control power circuits with no moving parts, instead using a semiconductor device triggered by light to perform switching. Relays with calibrated operating characteristics and sometimes multiple operating coils are used to protect electrical circuits from overload or faults; in modern electric power systems these functions are performed by digital instruments still called "protection relays".

Fig: 5.1Working Of Relay


Department of Electronics and Communication Engg. Page 55

Crop Monitoring System

5.1.1 Types of relays: 1. Simple electromechanical relay:

Fig 5.1.1 Electromagnetic Relay A simple electromagnetic relay, such as the one taken from a car in the first picture, is an adaptation of an electromagnet. It consists of a coil of wire surrounding a soft iron core, an iron yoke, which provides a low reluctance path for magnetic flux, a movable iron armature, and a set, or sets, of contacts; two in the relay pictured. The armature is hinged to the yoke and mechanically linked to a moving contact or contacts. It is held in place by a spring so that when the relay is de-energized there is an air gap in the magnetic circuit. In this condition, one of the two sets of contacts in the relay pictured is closed, and the other set is open. Other relays may have more or fewer sets of contacts depending on their function. The relay in the picture also has a wire connecting the armature to the yoke. This ensures continuity of the circuit between the moving contacts on the armature, and the circuit track on the printed circuit board (PCB) via the yoke, which is soldered to the PCB. Basic design and operation:

Fig: 5.1.2 Electromagnetic Relay Operation


Department of Electronics and Communication Engg. Page 56

Crop Monitoring System

When an electric current is passed through the coil, the resulting magnetic field attracts the armature and the consequent movement of the movable contact or contacts either makes or breaks a connection with a fixed contact. If the set of contacts was closed when the relay was De-energized, then the movement opens the contacts and breaks the connection, and vice versa if the contacts were open. When the current to the coil is switched off, the armature is returned by a force, approximately half as strong as the magnetic force, to its relaxed position. Usually this force is provided by a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing. If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a voltage spike dangerous to circuit components. Some automotive relays already include a diode inside the relay case. Alternatively a contact protection network, consisting of a capacitor and resistor in series, may absorb the surge. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small out-ofphase current, which increases the minimum pull on the armature during the AC cycle. By analogy with the functions of the original electromagnetic device, a solid-state relay is made with a thyristor or other solid-state switching device. To achieve electrical isolation an opt coupler can be used which is a light-emitting diode (LED) coupled with a photo transistor. Small relay as used in electronics

Department of Electronics and Communication Engg.

Page 57

Crop Monitoring System

2. Latching relay

Fig: 5.1.3 Latching Relay Latching relay, dust cover removed, showing pawl and ratchet mechanism. The ratchet operates a cam, which raises and lowers the moving contact arm, seen edge-on just below it. The moving and fixed contacts are visible at the left side of the image. A latching relay has two relaxed states (bi stable). These are also called "impulse", "keep", or "stay" relays. When the current is switched off, the relay remains in its last state. This is achieved with a solenoid operating a ratchet and cam mechanism, or by having two opposing coils with an over-center spring or permanent magnet to hold the armature and contacts in position while the coil is relaxed, or with a remnant core. In the ratchet and cam example, the first pulse to the coil turns the relay on and the second pulse turns it off. In the two coil example, a pulse to one coil turns the relay on and a pulse to the opposite coil turns the relay off. This type of relay has the advantage that it consumes power only for an instant, while it is being switched, and it retains its last setting across a power outage. A remnant core latching relay requires a current pulse of opposite polarity to make it change state. 3. Reed relay A reed relay has a set of contacts inside a vacuum or inert gas filled glass tube, which protects the contacts against atmospheric corrosion. The contacts are closed by a magnetic field generated
Department of Electronics and Communication Engg. Page 58

Crop Monitoring System

when current passes through a coil around the glass tube. Reed relays are capable of faster switching speeds than larger types of relays, but have low switch current and voltage ratings.

Fig: 5.1.4 Reed Relay 4. Mercury-wetted relay A mercury-wetted reed relay is a form of reed relay in which the contacts are wetted with mercury. Such relays are used to switch low-voltage signals (one volt or less) because of their low contact resistance, or for high-speed counting and timing applications where the mercury eliminates contact bounce. Mercury wetted relays are position-sensitive and must be mounted vertically to work properly. Because of the toxicity and expense of liquid mercury, these relays are rarely specified for new equipment. See also mercury switch. 5. Polarized relay A polarized relay placed the armature between the poles of a permanent magnet to increase sensitivity. Polarized relays were used in middle 20th Century telephone exchanges to detect faint pulses and correct telegraphic distortion. The poles were on screws, so a technician could first adjust them for maximum sensitivity and then apply a bias spring to set the critical current that would operate the relay. 6. Machine tool relay A machine tool relay is a type standardized for industrial control of machine tools, transfer machines, and other sequential control. They are characterized by a large number of contacts (sometimes extendable in the field) which are easily converted from normally-open to normallyDepartment of Electronics and Communication Engg. Page 59

Crop Monitoring System

closed status, easily replaceable coils, and a form factor that allows compactly installing many relays in a control panel. Although such relays once were the backbone of automation in such industries as automobile assembly, the programmable logic controller (PLC) mostly displaced the machine tool relay from sequential control applications. 7. Contactor relay A contactor is a very heavy-duty relay used for switching electric motors and lighting loads. Continuous current ratings for common contactors range from 10 amps to several hundred amps. High-current contacts are made with alloys containing silver. The unavoidable arcing causes the contacts to oxidize; however, silver oxide is still a good conductor. Such devices are often used for motor starters. A motor starter is a contactor with overload protection devices attached. The overload sensing devices are a form of heat operated relay where a coil heats a bi-metal strip, or where a solder pot melts, releasing a spring to operate auxiliary contacts. These auxiliary contacts are in series with the coil. If the overload senses excess current in the load, the coil is de-energized. Contactor relays can be extremely loud to operate, making them unfit for use where noise is a chief concern. 8. Solid-state relay

Fig: 5.1.5 Solid State Relay

A solid state relay (SSR) is a solid state electronic component that provides a similar function to an electromechanical relay but does not have any moving components, increasing long-term reliability. With early SSR's, the tradeoff came from the fact that every transistor has a small voltage drop across it. This voltage drop limited the amount of current a given SSR could handle.
Department of Electronics and Communication Engg. Page 60

Crop Monitoring System

As transistors improved, higher current SSR's, able to handle 100 to 1,200 Amperes, have become commercially available. Compared to electromagnetic relays, they may be falsely triggered by transients, Solid state relay, which has no moving parts 25 A or 40 A solid state contactors 9. Solid state contactor relay A solid state contactor is a very heavy-duty solid state relay, including the necessary heat sink, used for switching electric heaters, small electric motors and lighting loads; where frequent on/off cycles are required. There are no moving parts to wear out and there is no contact bounce due to vibration. They are activated by AC control signals or DC control signals from Programmable logic controller (PLCs), PCs, Transistor-transistor logic (TTL) sources, or other microprocessor and microcontroller controls. 10. Buchholz relay A Buchholz relay is a safety device sensing the accumulation of gas in large oil-filled transformers, which will alarm on slow accumulation of gas or shut down the transformer if gas is produced rapidly in the transformer oil. 11. Forced-guided contacts relay A forced-guided contacts relay has relay contacts that are mechanically linked together, so that when the relay coil is energized or de-energized, all of the linked contacts move together. If one set of contacts in the relay becomes immobilized, no other contact of the same relay will be able to move. The function of forced-guided contacts is to enable the safety circuit to check the status of the relay. Forced-guided contacts are also known as "positive-guided contacts", "captive contacts", "locked contacts", or "safety relays".

Department of Electronics and Communication Engg.

Page 61

Crop Monitoring System

12. Overload protection relay Electric motors need over current protection to prevent damage from over-loading the motor, or to protect against short circuits in connecting cables or internal faults in the motor windings. One type of electric motor overload protection relay is operated by a heating element in series with the electric motor. The heat generated by the motor current heats a bimetallic strip or melts solder, releasing a spring to operate contacts. Where the overload relay is exposed to the same environment as the motor, a useful though crude compensation for motor ambient temperature is provided. Applications of Relays:

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

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

Detect and isolate faults on transmission and distribution lines by opening and closing circuit breakers (protection relays),

Fig 5.1.6 A DPDT AC coil relay with "ice cube" packaging

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. The latter is often applied to control office lighting as the low voltage wires are

Department of Electronics and Communication Engg.

Page 62

Crop Monitoring System

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,

Logic functions. For example, the Boolean AND function is realized by connecting normally 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.

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.

Time delay functions. Relays can be modified to delay opening or delay closing a set of contacts. A very short (a fraction of a second) delay would use a copper disk between the armature and moving blade assembly. Current flowing in the disk maintains magnetic field for a short time, lengthening release time. For a slightly longer (up to a minute) delay, a dashpot is used. 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.

Advantages of relays:

Relays can switch AC and DC, transistors can only switch DC. Relays can switch high voltages, transistors cannot. Relays are a better choice for switching large currents (> 5A). Relays can switch many contacts at once.

Department of Electronics and Communication Engg.

Page 63

Crop Monitoring System

Disadvantages of relays:

Relays are bulkier than transistors for switching small currents. Relays cannot switch rapidly (except reed relays), transistors can switch many times per second.

Relays use more power due to the current flowing through their coil. Relays require more current than many ICs can provide, so a low power transistor may be needed to switch the current for the relay's coil.

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, as shown in the diagram below. Use BC109C or similar. A resistor of about 4k7 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.

Fig. 5.1.7 Relay Driver

Department of Electronics and Communication Engg.

Page 64

Crop Monitoring System

5.2 Motor Driver


The Motor driver chip (L293D) is used to drive the motors which can be connected to the PTR connectors as shown in the above figure. Through software you need to configure as follows: PB6 and PB5 PE2 and PE3 PB4 (MOTOR1) (MOTOR2) (CHIP ENABLE)

There are motors which might need higher than 5V (up to 12V) operating voltage. In such cases an external supply can be given to the board and the USB power switch can be toggled to make the external supply available inst ead of a USB powered connection. Motor Driver section

Fig 5.2 Motor Driver Pin Out

Department of Electronics and Communication Engg.

Page 65

Crop Monitoring System

CHAPTER 6 CONCLUSIONS
A methodological approach has been followed in designing the AVR based system for measurement and control of the plant growth parameter, i.e. soil moisture. The results obtained from the measurement have shown that the system performance is quite reliable and accurate. Field experience has shown that soil moisture sensors are very useful in diagnosing the changes needed and to fine-tune irrigation practices. Relatively minor regulations in irrigation practices can pay large dividends in terms of increased yields or water savings. The key to proper irrigation management using soil moisture sensors is regular monitoring of the sensors to track the soil moisture level and provide irrigation when the readings are in the determined range for the particular soil type. Thus, this system eliminates the drawbacks of the existing set-ups mentioned in the previous section. Also a cost analysis report has been prepared to compare the effective costs of the proposed model and microprocessor based system. Thus it has proved to be an easy to maintain, flexible and low cost solution.

Department of Electronics and Communication Engg.

Page 66

Crop Monitoring System

REFERENCES
[1] Skinner. A., Hignett. C., and Dearden. J., Resurrecting the Gypsum Block for Soil Moisture Measurement, Australian Viticulture, October/November 1997. (http://www.sowacs.com/sensors/gypsum.txt) [2] Morris. M., Soil Moisture Monitoring: Low Cost Tools and Methods NCAT Energy Specialist, ATTRA Publication #IP277, 2006. (http://attra.ncat.org/attra-pub/PDF/soil_moisture.pdf)

[3] Daniel K. Fisher, Hirut Kebede, "A low-cost microcontroller-based system to monitor crop temperature and water status", Computers and Electronics in Agriculture 74 (2010) [4] Richard Allen, Soil Water Monitoring with Inexpensive Equipment, University of Idaho, 2000 (www.kimberly.uidaho.edu/water/swm)

[5] Microcontroller and Sensor Datasheets from www.datasheetcatalog.com

Department of Electronics and Communication Engg.

Page 67

Crop Monitoring System

APPENDIX
Program:
Header file to enable UART : void uart1_init(void) { int ubrr=103; UBRR1H=(unsigned char)(ubrr>>8); UBRR1L=(unsigned char)(ubrr); UCSR1C|=((1<<1)|(1<<2)); UCSR1B|=((1<<3)|(1<<4)); }

void uart1_send_data(unsigned char data) { while(!(UCSR1A & (1<<UDRE))); UDR1=data; }

unsigned char uart1_read_data(void) { while(!(UCSR1A & (1<<RXC))); return UDR1; } void uart1_send_string(char *p) { while(*p!=0) { uart1_send_data(*p); p++; } } void uart1_read_string(char *p) { *p=uart1_read_data(); while(*p!=32)
Department of Electronics and Communication Engg. Page 68

Crop Monitoring System

{ p++; *p=uart1_read_data(); } *p=0; }

Header file to enable LCD Module: //#define F_CPU 12000000UL #include<avr/io.h> #include<util/delay.h> #include<inttypes.h> #define rs PA0 #define rw PA1 #define en PA2 void lcd_init(); void dis_cmd(char); void dis_data(char); void lcdcmd(char); void lcddata(char);

void lcd_init() // fuction for intialize { DDRA=0xFF; dis_cmd(0x02); // to initialize LCD in 4-bit mode. dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode. dis_cmd(0x0F); dis_cmd(0x06); dis_cmd(0x01); _delay_ms(10); } void dis_cmd(char cmd_value) { char cmd_value1;

Department of Electronics and Communication Engg.

Page 69

Crop Monitoring System

cmd_value1 = cmd_value & 0xF0; are used. lcdcmd(cmd_value1);

//mask lower nibble because PA4-PA7 pins // send to LCD

cmd_value1 = ((cmd_value<<4) & 0xF0); //shift 4-bit and mask lcdcmd(cmd_value1); // send to LCD }

void dis_data(char data_value) { char data_value1; data_value1=data_value&0xF0; lcddata(data_value1); data_value1=((data_value<<4)&0xF0); lcddata(data_value1); } void lcdcmd(char cmdout) { PORTA=cmdout; PORTA&=~(1<<rs); PORTA&=~(1<<rw); PORTA|=(1<<en); _delay_ms(1); PORTA&=~(1<<en); } void lcddata(char dataout) { PORTA=dataout; PORTA|=(1<<rs); PORTA&=~(1<<rw); PORTA|=(1<<en); _delay_ms(1); PORTA&=~(1<<en); } void lcd_gotoxy(int x,int y) { if(y==1) {
Department of Electronics and Communication Engg. Page 70

Crop Monitoring System

dis_cmd(0x80+x); } else { dis_cmd(0xc0+x); } } void disp_string(char *p) { while(*p!=0) { dis_data(*p); p++; } } void disp_clear() { dis_cmd(0x01); _delay_ms(10); }

Header file to enable ADC: //for X axis and Yaxis simultaneously moving

#include<avr/io.h> #include<util/delay.h> //for x-axis void adc_x_init() {

//uart1.h is used to see de disply de o/p

ADMUX&=~(1<<1); //making channel 2 disable here y is off nd x is on ADMUX|=(1<<REFS1)|(1<<REFS0)|(1<<ADLAR)|(1<<MUX0); //here we r selecting the ref voltage as 2.56v by making REFS1 & REFS0 as 1 &1 & ADR is selected as x-axis as MUX0 is enabled here nd ADLAR is used fr shifting de data ADCSRA|=(1<<ADEN)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //here we are giving auto trigger ADATE nd prescalling is done by making ADPS1,S2,S0 as 1's nd ADEN is enabled to enable ADC }
Department of Electronics and Communication Engg. Page 71

Crop Monitoring System

//for y-axis void adc_y_init() { ADMUX&=~(1<<0); //making channel 2 disable here x is off nd y is on ADMUX|=(1<<REFS1)|(1<<REFS0)|(1<<ADLAR)|(1<<MUX1); //here we r selecting the ref voltage as 2.56v by making REFS1 & REFS0 as 1 &1 & ADR is selected as x-axis as MUX0 is enabled here nd ADLAR is used fr shifting de data ADCSRA|=(1<<ADEN)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //here we are giving auto trigger ADATE nd prescalling is done by making ADPS1,S2,S0 as 1's nd ADEN is enabled to enable ADC } //read data unsigned int adc_read() { ADCSRA|=(1<<ADSC); //to enable the start conversion bit r covertion starts here nd since it is here it repeats again nd again as dis called in main.c nd it is present in while loop so repeats again nd again unsigned int adc_data; //defined to store new data while(!(ADCSRA&(1<<ADIF))); //when de conversion is completed de value is assigned in to ADCSR nd dis doent execute only when de previes data is completed r new data is seen adc_data=ADCH; //here de new data dat appered in ADCH is stored in adc_data return adc_data; //dis line indicates dat de new data is retuned back

Department of Electronics and Communication Engg.

Page 72

Crop Monitoring System

Embedded C Program:

//thanks to think labs //mini project by J PAVAN KUMAR , HAREENSAI JAVAGI, P.DINESH KUMAR // VARDHAMAN COLLEGE OF ENGINEERING //before start of experiment place a wire from PORTC to soil and another wire from Ground Pin of ADC PORT i.e PORT F to soil //connect the dc enable wire of relay to 5th analog pin of portF (ADC SENSOR PORTS); ( start count from 0 from right to left) //if soil is wet the ac device and dc motor will be off //if soil is wet ac device and dc motor will be on #include <avr/io.h> #include <util/delay.h> #define SET_BIT(a,b) a|=(1<<b) #define CLR_BIT(a,b) a&=~(1<<b) #include <stdlib.h> #include"myuart.h" #include "lcd.h"

char value[10];

void init_adc(void) { ADMUX=0x40; ADCSRA=0x83; DDRF=0; } unsigned int read_adc(unsigned char adc_input) { ADMUX=adc_input |0x40; _delay_us(10); ADCSRA|=0x40; while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; return ADCW; }

Department of Electronics and Communication Engg.

Page 73

Crop Monitoring System

void timer1_init() { TCCR1A=(1<<WGM11)|(1<<COM1A1); //top value is selected by us nd we want fast pwm by enabling WGM11 by seeing mode14 of WGM table nd we r enabling COM1A1 for noninverting mode TCCR1B=(1<<CS11)|(1<<WGM12)|(1<<WGM13); //prescaling value 8 is enabled nd frm mode14 of WGM table WGM12 nd WGM13 should be enabled fr de wave form since dis both r present in register TCCR1B we r enabling here ICR1=60000; //top valueis selected by use }

void main() { DDRF |= (1<<PORTF5); lcd_init(); lcd_gotoxy(0,1); unsigned char buffer[14]; disp_string("Crop Monitoring "); lcd_gotoxy(0,2); disp_string(" System "); _delay_ms(5000); lcd_gotoxy(0,1); disp_string("Press Switch1 to"); lcd_gotoxy(0,2); disp_string("ON Relay & motor"); _delay_ms(5000);

lcd_gotoxy(0,1); disp_string("If Swth3 pressed"); lcd_gotoxy(0,2); disp_string("dc&relay gets ON"); _delay_ms(5000);


Department of Electronics and Communication Engg. Page 74

Crop Monitoring System

lcd_gotoxy(0,1); disp_string("only if soil is"); lcd_gotoxy(0,2); disp_string("dry "); lcd_gotoxy(0,1); disp_string("Press Switch4 to");

lcd_gotoxy(0,2); disp_string("To OFF Relay&DC"); _delay_ms(5000);

lcd_gotoxy(0,1); disp_string(" Temperature. ");

lcd_gotoxy(0,2); disp_string(" :-p :-0 :-) "); _delay_ms(1000); unsigned char temp; DDRA = 0xff; DDRC = 0; PORTC = 0xff; CLR_BIT(DDRD,6); SET_BIT(PORTD,6); CLR_BIT(DDRD,7); SET_BIT(PORTD,7); CLR_BIT(DDRE,6); SET_BIT(PORTE,6); CLR_BIT(DDRE,7); SET_BIT(PORTE,7); init_adc(); while(1) {

if(!(PIND&(1<<6)))//switch 1 //the dc motor and Relay AC load like ac motor or bulb gets ON
Department of Electronics and Communication Engg. Page 75

Crop Monitoring System

{ PORTF |= (1<<PORTF5); DDRC=0; PORTC=0xff; //for motor DDRB=(1<<6)|(1<<5)|(1<<4); //to connect PB4,PB5,PB6 5nd6 fr motor1 nd 4 for connecting chip enable PORTB|=(1<<5); //to enable r make 5th pin +ve nd move motor1 in forward direction PORTB|=(1<<4); // pin4 is enabled here timer1_init(); while(1) { OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=3000;
Department of Electronics and Communication Engg. Page 76

Crop Monitoring System

_delay_ms(500);

if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } }

//else if(!(PIND&(1<<7)))// swtich 2 //temperature displays on the lcd module. //temperature sensor LM35 connected to 1st pin of adc pin(start count from 0 from right to left) { temp=read_adc(1); lcd_gotoxy(0,2); sprintf(buffer," %ddec C ",temp/2); disp_string(buffer); _delay_ms(500); }

if(!(PINE&(1<<6)))//switch 3 // if the soil is dry the motor and relay gets ON

{ PORTF |= (1<<PORTF5); DDRC=0; PORTC=0xff; //for motor DDRB=(1<<6)|(1<<5)|(1<<4); //to connect PB4,PB5,PB6 5nd6 fr motor1 nd 4 for connecting chip enable PORTB|=(1<<5); //to enable r make 5th pin +ve nd move motor1 in forward direction PORTB|=(1<<4); // pin4 is enabled here
Department of Electronics and Communication Engg. Page 77

Crop Monitoring System

timer1_init(); while(1) { OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=30000; _delay_ms(100); if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } OCR1A=3000; _delay_ms(500);

if(!(PINE&(1<<7))|(PIND&(1<<7))|(PIND&(1<<6))) { break; } }

Department of Electronics and Communication Engg.

Page 78

Crop Monitoring System

} else if((!(PINE&(1<<7))) || (PINC!=0xff))// switch 4 //it disables the dc motor and relay circuit. { PORTF &= ~(1<<PORTF5); DDRB=((0<<4));

} } }

Department of Electronics and Communication Engg.

Page 79

Das könnte Ihnen auch gefallen