Você está na página 1de 79

Project Report On

REAL TIME MONITORING OF TEMPERATURE AND LIGHT INTENSITY USING A MICROCONTROLLER


Submitted in partial fulfillment of the requirements for the award of the degree of Bachelor of Engineering in Electrical Engineering of Gauhati University
Session: 2009-10

by Madhuyya Prasad Baruah (06/269) Bhaskarnil Hazarika (06/272) Manash Pratim Bora (06/278) Under the guidance of Dr. Dulav Hazarika Senior Professor Department of Electrical & Instrumentation Engineering

Department of Electrical & Instrumentation Engineering

Assam Engineering College, Jalukbari, Guwahati-781013

ABSTRACT

Appropriate monitoring of environmental conditions is necessary for various natural and physical processes. Automating the data acquisition process of various climatic parameters allows information to be collected with less labor requirements. Some important environmental parameters are temperature, light intensity, relative humidity, soil quality etc. which are required in various purposes. The objective of this project is to design a simple, easy to install, microcontroller based circuit to monitor the values of temperature and light intensity of natural environment. The microcontroller communicates with various sensor modules in real time in order to measure various parameters which can be continuously monitored. The proposed system to be an economical, portable and a low maintenance solution for various applications.

Certificate from the Supervisor


This is to certify that the project entitled REAL TIME MONITORING OF TEMPERATURE AND LIGHT INTENSIY USING A MICROCONTROLLER has been carried out and presented by Madhuyya Prasad Baruah (06/269) Bhaskarnil Hazarika (06/272) Manash Pratim Bora (06/278)

students of BE 7th Semester (Instrumentation Engineering), Assam Engineering College, under my supervision and guidance in a manner satisfactory to warrant its acceptance as a prerequisite for the award of the degree of Bachelor of Engineering in Electrical Engineering of the Gauhati University.

Further, the report has not been submitted/reproduced in any form for the award of any other degree/diploma.

Date: Place: Guwahati

(Dr. Durlav Hazarika) Deptt. of Electrical & Instrumentation Engineering Assam Engineering College Guwahati-781013

Certificate from the Head of the Department

This is to certify that the project report entitled REAL TIME MONITORING OF TEMPERATURE AND LIGHT INTENSITY USING A MICROCONTROLLER submitted by the following BE 7th semester students: Madhuyya Prasad Baruah (06/269) Bhaskarnil Hazarika (06/272) Manash Pratim Bora (06/278) has been

in partial fulfillment of the requirements for the award of the degree of Bachelor of Engineering in Electrical Engineering of Gauhati University.

Date: Place: Guwahati

(Dr. Damodar Agarwal) Head of the Department. Deptt. of Electrical & Instrumentation Engineering Assam Engineering College, Jalukbari, Guwahati-13

ACKNOWLEDGMENT

The completion of any project brings with it a sense of satisfaction, but it is never complete without thanking those people who made it possible and whose constant support has crowned our efforts with success.

We take this opportunity to express our sincere gratitude and heartiest thanks to our supervisor, Dr. Durlav Hazarika, Senior professor, Electrical and Instrumentation Engineering, Assam Engineering College, for his suggestion and valuable guidance without which, the completion of the project would not have been possible. His untiring zeal, support and ideas, which constantly inspired us towards the attainment of everlasting knowledge throughout the course; without his incredible support and steady involvement the project would not have been fruitful.

We also would like to thank all the staff members of Electrical and Instrumentation Engineering department for providing us with the required facilities and support towards the completion of the project.

With lots of regards: Madhuyya Prasad Baruah (06/269) Bhaskarnil Hazarika (06/272) Manash Pratim Bora (06/278)

CHAPTER 1

INTRODUCTION

INTRODUCTION
We live in a world where everything can be controlled and operated automatically, but there are still a few important sectors in our country where before adopting automation the information of some important environmental parameters are required to perform certain operations. Some important environmental parameters are temperature, light intensity, relative humidity, soil quality etc. which are required in various purposes. The objective of this project is to design a simple, easy to install, microcontroller based circuit to monitor the values of temperature and light intensity of natural environment. The microcontroller communicates with various sensor modules in real time in order to measure various parameters which can be continuously monitored. The proposed system is portable, economical and handy while using in different areas.

1.1

CURRENT SCENEREO:
This part of India generally enjoys a soft climate which is neither too hot nor too cold.

The temperature generally varies in between 50 C to 400 C. Light intensity may vary depending on the natural conditions, but considering various situations, the proposed project has been modified to measure light of high intensity which are caused by various artificial light sources.

CHAPTER 2

SYSTEM MODEL

BLOCK DIAGRAM OF THE SYSTEM

TEMPERATURE SENSOR

AVR ATMEGA 8

LCD DISPLAY

LIGHT SENSOR

Fig 2.1: Block diagram of the system

PARTS OF THE SYSTEM:


SENSORS (DATA ACQUISITION SYSTEM) Temperature Sensor (LM 35) Light Sensor (LDR)

MICROCONTROLLER (AVR ATMEGA 8, Analog To Digital Converter incorporated)

LIQUID CRYSTAL DISPLAY

CHAPTER 3

HARDWARE DESCRIPTION

TRANSDUCERS: A transducer is a device which measures a physical quantity and converts it into a signal which can be read by an observer or by an instrument. It is a device capable of being actuated by an energizing input from one or more transmission media and in turn generating a related signal to one or more transmission systems. It provides a usable output in response to specified input measured , which may be in the form physical, chemical, Mechanical or optical. The proposed scheme for monitoring of environmental variables like temperature and light intensity requires sensors for respective properties. We are using a microcontroller based monitoring system, the sensors required to output analog voltages proportional to measuring variables and is calibrated for real-world parameters for display to an observer. The sensors used in this system are1. Light Sensor ( LDR -Light Dependent Resistor) 2. Temperature Sensor (LM35) LIGHT SENSOR Light Dependent Resistor (LDR) also known as photoconductor or photocell, is a device which has a resistance which varies according to the amount of light falling on its surface. Since LDR is extremely sensitive in visible light range, it is well suited for the proposed application.

Fig: Light Dependent Resistor


.

Features of the light sensor: The Light Dependent Resistor (LDR) is made using the semiconductor Cadmium Sulphide (CdS).

The light falling on the brown zigzag lines on the sensor causes the resistance of the device to fall. This is known as a negative co-efficient. There are some LDRs that work in the opposite way i.e. their resistance increases with light (called positive coefficient). The resistance of the LDR decreases as the intensity of the light falling on it increases. Incident photons drive electrons from the valence band into the conduction band.

Fig: Structure of a Light Dependent Resistor, showing Cadmium Sulphide track and an atom to illustrate electrons in the valence and conduction band
Operating temperature range -600C to +750C.

Light dependent resistors have a particular property that they remember the lightning conditions that they have been stored. Light storage reduces equilibrium time to reach steady resistance values. Functional description: An LDR and a normal resistor are wired in series across a voltage, as shown in the circuit below. Depending on which is tied to the 5V and which to 0V, the voltage at the point between them, call it the sensor node, will either rise or fall with increasing light. If the LDR is the component tied directly to the 5V, the sensor node will increase in voltage with increasing light The LDR's resistance can reach 10 k ohms in dark conditions and about 100 ohms in full brightness. The circuit used for sensing light in our system uses a 10 k fixed resistor which is tied to ground. Hence the voltage value in this case increases with increase in light intensity.

LDR CIRCUIT:

Fig: Light sensor circuit


With the LDR connected to 5V with 10K resistor in series to the ground, the output

voltage of the LDR isV0 = 5*1/ (RL+1) volt RL= resistance of the LDR In order to increase the sensitivity of the sensor we must increase the value of the fixed resistor as per requirement. We are connecting this LDR output to the channel 0 of the AVR microcontroller and calibrate it in the lumen scale for light intensity.

TEMPERATURE SENSOR National Semiconductors LM35 IC has been used for sensing the temperature. The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The temperature can be measured more accurately with it than using a thermistor. The sensor circuitry is sealed and not subject to oxidation, etc.

Features:

Calibrated directly in Celsius (Centigrade). Linear + 10.0 mV/C scale factor. 0.5C accuracy guaranteed (at +25C). Rated for full 55 to +150C range. Suitable for remote applications. Low cost due to wafer-level trimming. Operates from 4 to 30 volts. Less than 60 A current drain.

Low self-heating, 0.08C in still air Nonlinearity only 14C typical Low self-heating, 0.08C in still air

Circuit Connection for LM35: Vcc

LM 35

ADC_IC1 10k GND Fig: Circuit connection for LM 35 sensor Functional description:

The sensor has a sensitivity of 10mV / oC. The sensor is connected to the Vcc in series with an 10k resistor to provide supply voltage.(pin 3) Pin 2 is grounded while pin 1 gives output voltage signal to the ADC channel 1. The output voltage we get is linearly proportional to temperature of the environment as the LM is linearly calibrated internally.

MICROCONTROLLER (Atmega8)
CRITERIA FOR CHOOSING A MICROCONTROLLER: The basic criteria for choosing a microcontroller suitable for the application are:

1) The first and foremost criterion is that it must meet the task at hand efficiently and cost effectively. In analyzing the needs of a microcontroller-based project, it is seen whether an 8bit, 16-bit or 32-bit microcontroller can best handle the computing needs of the task most effectively. Among the other considerations in this category are: (a) Speed: The highest speed that the microcontroller supports. (b) Packaging: It may be a 40-pin DIP (dual inline package) or a QFP (quad flat package), or some other packaging format. This is important in terms of space, assembling, and prototyping the end product. (c) Power consumption: This is especially critical for battery-powered products. (d) The number of I/O pins and the timer on the chip. (f) How easy it is to upgrade to higher performance or lower consumption versions. (g) Cost per unit: This is important in terms of the final cost of the product in which a microcontroller is used. 2) The second criterion in choosing a microcontroller is how easy it is to develop products around it. Key considerations include the availability of an assembler, debugger, compiler, technical support. 3) The third criterion in choosing a microcontroller is its ready availability in needed quantities both now and in the future Thus the microcontroller Atmega8, satisfying the criterion necessary for the proposed application is chosen for the task.

Overview:
The ATmega8 is a low-power CMOS 8-bit microcontroller based on the AVR

RISC architecture. by executing powerful instructions in a single clock cycle, the ATmega8

achieves throughputs approaching 1 MIPS per MHz, allowing the system designer to optimize power consumption versus processing speed. The AVR core combines a rich instruction set with 32 general purpose working registers. All the32 registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers. The ATmega8 provides the following features: 8K bytes of In-System Programmable Flash with Read-While-Write capabilities, 512 bytes of EEPROM, 1K byte of SRAM, 23 general purpose I/O lines, 32 general purpose working registers, three flexible Timer/Counters with compare modes, internal and external interrupts, a serial programmable USART, a byte oriented Two wire Serial Interface, a 6-channel ADC (eight channels in TQFP and QFN/MLF packages) with10-bit accuracy, a programmable Watchdog Timer with Internal Oscillator, an SPI serial port ,and five software selectable power saving modes. The Idle mode stops the CPU while allowing he SRAM, Timer/Counters, SPI port, and interrupt system to continue functioning. The Power down mode saves the register contents but freezes the Oscillator, disabling all other chip functions until the next Interrupt or Hardware Reset. In Power-save mode, the asynchronous timer continues to run, allowing the user to maintain a timer base while the rest of the device is sleeping. The ADC Noise Reduction mode stops the CPU and all I/O modules except asynchronous timer and ADC, to minimize switching noise during ADC conversions. In Standby mode, the crystal/resonator Oscillator is running while the rest of the device is sleeping. This allows very fast start-up combined with low-power consumption. The device is manufactured using Atmels high density non-volatile memory technology. The Flash Program memory can be reprogrammed In-System through an SPI serial interface, by a conventional non-volatile memory programmer. The ATmega8 AVR is supported with a full suite of program and system development tools, including C compilers, macro assemblers, program debugger/simulators, In-Circuit Emulators, and evaluation kits.

PIN DESCRIPTION:

BLOCK DIAGRAM:

Pin Descriptions:

VCC GND Port B XTAL1/XTAL2

Digital supply voltage. Ground. (PB7..PB0)

/TOSC1/TOSC2

Port B is an 8-bit bi-directional I/O port with internal pull-up

resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running. . Depending on the clock selection fuse settings, PB6 can be used as input to the inverting oscillator amplifier and input to the internal clock operating circuit. Depending on the clock selection fuse settings, PB7 can be used as output from the inverting oscillator amplifier .If the Internal Calibrated RC Oscillator is used as chip clock source, PB7..6 is used as TOSC2..1input for the Asynchronous Timer/Counter2 if the AS2 bit in ASSR is set.

Port C (PC5..PC0): Port C is an 7-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port C pins are tri-stated when a reset condition becomes active , even if the clock is not running.

PC6/RESET :

If the RSTDISBL Fuse is programmed, PC6 is used as an I/O pin.

Note that the electrical characteristics of PC6 differ from those of the other pins of Port C. If the RSTDISBL Fuse is un programmed, PC6 is used as a Reset input. A low level on this pin for longer than the minimum pulse length will generate a Reset, even if the clock is not running. .

Port D (PD7.PD0) : Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pull-up. resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running.

RESET:

Reset input. A low level on this pin for longer than the minimum pulse

length will generate are set, even if the clock is not running.

AVCC:

AVCC is the supply voltage pin for the A/D Converter, Port C (3..0), and

ADC (7..6). It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter. Note that Port C (5..4) use digital supply voltage, VCC.

AREF:

AREF is the analog reference pin for the A/D Converter.

ADC7-6 (TQFP And QFN/MLF Package Only): In the TQFP and QFN/MLF package, ADC7..6 serve as analog inputs to the A/D converter .These pins are powered from the analog supply and serve as 10-bit ADC channels

AVR CPU Core: The main function of the CPU core is to ensure correct program execution. The CPU must therefore be able to access memories, perform calculations, control peripherals, and handle interrupts. Arithmetic Logic Unit ALU: The high-performance AVR ALU operates in direct connection with all the 32 general purpose working registers. Within a single clock cycle, arithmetic operations between general purpose registers or between a register and an immediate are executed. The ALU operations are divided into three main categories arithmetic, logical, and bitfunctions. Some implementations of the architecture also provide a powerful multiplier supporting both signed/unsigned multiplication and fractional format.

Status Register: The Status Register contains information about the result of the most recently executed arithmetic instruction. This information can be used for altering program flow in order to perform conditional operations. The Status Register is updated after all ALU operations. This will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code.

The AVR Status Register SREG is defined as:

General Purpose Register File: The Register File is optimized for the AVR Enhanced RISC instruction set. In order to achieve the required performance and flexibility, the following input/output schemes are supported by the Register File: One 8-bit output operand and one 8-bit result input. Two 8-bit output operands and one 8-bit result input. Two 8-bit output operands and one 16-bit result input.
One

16-bit output operand and one 16-bit result input.

Stack Pointer: The Stack is mainly used for storing temporary data, for storing local variables and for storing return addresses after interrupts and subroutine calls. The Stack Pointer Register always points to the top of the Stack. The Stack is implemented as growing from higher memory locations to lower memory locations. This implies that a Stack PUSH command decreases the Stack Pointer. The AVR Stack Pointer is implemented as two 8-bit registers in the I/O space.

INSTRUMENTATION AND TIMING DIAGRAM:


Parallel Instruction Fetches and Instruction Execution

Single Cycle ALU Operation

Reset and Interrupt Handling:

The AVR provides several different interrupt

sources. These interrupts and the separate Reset Vector each have a separate Program Vector in the Program memory space. All interrupts are Interrupt Enable bit in the Status Register in order to enable the interrupt. Depending on the Program Counter value, interrupts may be automatically disabled when Boot Lock Bits BLB02 or BLB12are programmed.

AVR ATmega8 Memories:


The AVR architecture has two main memory spaces, the Data memory and the Program Memory space. In addition, the ATmega8 features an EEPROM Memory for data storage. All three memory spaces are linear and regular.

In-System Reprogrammable Flash Program Memory:

The ATmega8 contains 8K bytes On-chip In-System Reprogrammable Flash memory for program storage. Since all AVR instructions are 16- or 32-bits wide, the Flash is organized as 4K x16 bits. For software security, the Flash Program memory space is divided into two sections, Boot Program section and Application Program section. Program Memory map:

SRAM Data Memory:

EEPROM Data Memory: The ATmega8 contains 512 bytes of data EEPROM

memory. It is organized as a separate data space, in which single bytes can be read and written. The EEPROM has an endurance of at least 100,000 write/erase cycles.

I/O Memory: All ATmega8 I/Os and peripherals are placed in the I/O space. The I/O locations are accessed by the IN and OUT instructions, transferring data between the 32 general purpose working registers and the I/O space .

System Clock and Clock Options:

All of the clocks need not be active at a given time. In order to reduce power consumption, the clocks to modules not being used can be halted by using different sleep modes .In our project the clock frequency is 1MHz. Principal Clock System in AVR:

Crystal Oscillator: XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can be configured for use as an On-chip Oscillator, as shown in figure below. Either a quartz crystal or a ceramic resonator may be used. The CKOPT Fuse selects between two different Oscillator amplifier modes. When CKOPT is programmed, the Oscillator output will oscillate a full rail-to rail swing on the output. This mode is suitable when operating in a very noisy environment or when the output from XTAL2 drives a second clock buffer. This mode has a wide frequency power consumption considerably. This mode has a limited frequency range and it cannot be used to drive other clock buffers. For resonators, the maximum frequency is 8 MHz with CKOPT unprogrammed and 16 MHz with CKOPT programmed. C1 and C2 should always be equal for both crystals and resonators. The optimal value of the capacitors depends on the crystal or resonator in use, and the amount of stray capacitance, and the electromagnetic noise of the environment .For ceramic resonators, the capacitor values given by the manufacturer should be used.

Calibrated Internal RC Oscillator: The calibrated internal RC Oscillator provides a fixed 1.0, 2.0, 4.0, or 8.0 MHz clock. External Clock: For external clock the connection is as shown:

Timer/Counter Oscillator For AVR microcontrollers with Timer/Counter Oscillator pins (TOSC1 and TOSC2), the crystal is connected directly between the pins. By programming the CKOPT Fuse, the user can enable internal capacitors on XTAL1 and XTAL2, thereby removing the need for external capacitors .The Oscillator is optimized for use with a 32.768 kHz watch crystal.

Power Management and Sleep Modes: To enter any of the five sleep modes, the SE bit in MCUCR must be written to logic one and a SLEEP instruction must be executed. The SM2, SM1, and SM0 bits in the MCUCR Register select which sleep mode (Idle, ADC Noise Reduction, Power-down, Power-save, or Standby)will be activated by the SLEEP instruction.. If an enabled interrupt occurs while the MCU is in a sleep mode, the MCU wakes up. The MCU is then halted for four cycles in addition to the start-up time, it executes the interrupt routine, and resumes execution from the instruction following SLEEP. The contents of the Register File and SRAM are unaltered when the device wakes up from sleep. If a reset occurs during sleep mode, the MCU wakes up and executes from the Reset Vector

MCU Control Register MCUCR: The MCU Control Register contains control bits for power management

Sleep Mode Select

Watchdog Timer: If the Watchdog Timer is not needed in the application, this module

should be turned off. If the Watchdog Timer is enabled, it will be enabled in all sleep modes, and hence, always consume power.

Port Pins: When entering a sleep mode, all port pins should be configured to use minimum power. The most important thing is then to ensure that no pins drive resistive loads. In sleep modes where the both the I/O clock (clk I/O) and the ADC clock (clk ADC) are stopped, the input buffers of the device will be disabled. This ensures that no power is consumed by the input logic when not needed. In some cases, the input logic is needed for detecting wake-up conditions, and it will then be enabled.

System Control and Reset:

Resetting the AVR: During Reset, all I/O Registers are set to their initial values, and the program starts execution from the Reset Vector. If the program never enables an interrupt source, the Interrupt Vectors are not used, and regular program code can be placed at these locations. This is also the case if the Reset Vector is in the Application section while the Interrupt Vectors are in the boot section or vice versa.

Reset Sources The ATmega8 has four sources of Reset: Power-on Reset. The MCU is reset when the supply voltage is below the Power-

on Reset threshold (VPOT). External Reset. The MCU is reset when a low level is present on the RESET pin for longer than the minimum pulse length. Watchdog Reset. The MCU is reset when the Watchdog Timer period expires and the Watchdog is enabled. Brown-out Reset. The MCU is reset when the supply voltage VCC is below the Brown-out Reset threshold (VBOT) and the Brown-out Detector is enabled.

RESET LOGIC

Internal Voltage Reference: ATmega8 features an internal band gap reference. This reference is used for Brown-out Detection, and it can be used as an input to the Analog Comparator or the ADC. The 2.56V reference to the ADC is generated from the internal band gap reference.

Interrupts:
Interrupt Vectors in ATmega 8:

I/O Ports:
Introduction: 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 (or enabling/disabling of pull-up resistors. 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. All I/O pins have protection diodes to both VCC and Ground as indicated in the figure

Alternate Port Functions: Most port pins have alternate functions in addition to
being general digital I/Os. Alternate Functions of Port B:

Alternate Functions of Port D :

External Interrupts: The external interrupts are triggered by the INT0, and INT1 pins. Observe that, if enabled, the interrupts will trigger even if the INT0..1 pins are configured as outputs. This feature provides away of generating a software interrupt. The external interrupts can be triggered by a falling or rising edge or a low level.

8-bit Timer/ Counter0: Timer/ Counter0 is a general purpose, single channel, 8-bit
Timer/Counter module. The main features are: Single Channel Counter Frequency Generator External Event Counter 10-bit Clock Prescaler

16-bit Timer/ Counter1: The 16-bit Timer/Counter unit allows accurate program
execution timing (event management),wave generation, and signal timing measurement. The main features are: True 16-bit Design (i.e., allows 16-bit PWM) Two Independent Output Compare Units Double Buffered Output Compare Registers One Input Capture Unit Input Capture Noise Canceler Clear Timer on Compare Match (Auto Reload) Glitch-free, Phase Correct Pulse Width Modulator (PWM) Variable PWM Period Frequency Generator External Event Counter Four Independent Interrupt Sources (TOV1, OCF1A, OCF1B, and ICF1)

ATmega8 Typical Characteristics:


The power consumption in Power-down mode is independent of clock selection. The current consumption is a function of several factors such as: operating voltage,

operating frequency, loading of I/O pins, switching rate of I/O pins, code executed and ambient temperature. The dominating factors are operating voltage and frequency. The current drawn from capacitive loaded pins may be estimated (for one pin) as CL*VCC*f where CL = load capacitance, VCC = operating voltage and f = average switching frequency of I/O pin .The parts are characterized at frequencies higher than test limits. Parts are not guaranteed to function properly at frequencies higher than the ordering code indicates. The difference between current consumption in Power-down mode with Watchdog Timer enabled and Power-down mode with Watchdog Timer disabled represents the differential current drawn by the Watchdog Timer. Active Supply Current vs. Frequency

Serial Peripheral Interface SPI:


The Serial Peripheral Interface (SPI) allows high-speed synchronous data transfer between the ATmega8 and peripheral devices or between several AVR devices. The ATmega8 SPI includes the following features: Full-duplex, Three-wire Synchronous Data Transfer Master or Slave Operation LSB First or MSB First Data Transfer Seven Programmable Bit Rates End of Transmission Interrupt Flag Write Collision Flag Protection

Wake-up from Idle Mode Double Speed (CK/2) Master SPI Mode

Figure: SPI Block Diagram The interconnection between Master and Slave CPUs with SPI is shown in figure below. The system consists of two Shift Registers, and a Master clock generator. The SPI Master initiates the communication cycle when pulling low the Slave Select SS pin of the desired Slave. Master and Slave prepare the data to be sent in their respective Shift Registers, and the Master generates the required clock pulses on the SCK line to interchange data. Data is always shifted from Master to Slave on the Master Out Slave In, MOSI, line, and from Slave to Master on the Master In Slave Out, MISO, line. After each data packet, the Master will synchronize the Slave by pulling high the Slave Select, SS, line. When the SPI is enabled, the data direction of the MOSI, MISO, SCK, and SS pins is overridden according to the table shown below. Pin MOSI MISO SCK SS Direction, Master SPI User Defined Input User Defined User Defined Direction, Slave SPI Input User Defined Input Input

Table SPI Pin Overrides Functionality: Slave Mode: When the SPI is configured as a Slave, the Slave Select (SS) pin is always input. When SS is held low, the SPI is activated, and MISO becomes an output if configured so by the user. All other pins are inputs Master Mode: When the SPI is configured as a Master (MSTR in SPCR is set), the user can determine the direction of the SS pin. If SS is configured as an output, the pin is a general output pin which does not affect the SPI system. SPI Control Register SPCR:

Bit 7 SPIE: SPI Interrupt Enable: Bit 6 SPE: SPI Enable: Bit 5 DORD: Data Order: Bit 4 MSTR: Master/Slave Select: Bit 3 CPOL: Clock Polarity: Bit 2 CPHA: Clock Phase: Bits 1, 0 SPR1, SPR0: SPI Clock Rate Select 1 and 0: SPI Status Register SPSR:

Bit 7 SPIF: SPI Interrupt Flag: Bit 6 WCOL: Write Collision Flag: Bit 5.1 Res: Reserved Bits: Bit 0 SPI2X: Double SPI Speed Bit: Data Modes: There are four combinations of SCK phase and polarity with respect to serial data, which are determined by control bits CPHA and CPOL. The SPI data transfer formats are shown in Figure59 and Figure 60. Data bits are shifted out and latched in on opposite edges of the SCK signal, ensuring sufficient time for data signals to stabilize. This is clearly seen by summarizing Table 48 and Table 49, as done below:

ANALOG TO DIGITAL CONVERTER: Analog-to- Digital Converter Features: 10-bit Resolution 0.5 LSB Integral Non-linearity 2 LSB Absolute Accuracy Up to 15 kSPS at Maximum Resolution 6 Multiplexed Single Ended Input Channels 2 Additional Multiplexed Single Ended Input Channels (TQFP and QFN/MLF Package only) 0 - VCC ADC Input Voltage Range

Selectable 2.56V ADC Reference Voltage Free Running or Single Conversion Mode Interrupt on ADC Conversion Complete Sleep Mode Noise Canceller The ATmega8 features a 10-bit successive approximation ADC. The ADC is connected to an 8channel Analog Multiplexer which allows eight single-ended voltage inputs constructed from the pins of Port C. The single-ended voltage inputs refer to 0V (GND). The ADC contains a Sample and Hold circuit which ensures that the input voltage to the ADC is held at a constant level during conversion. A block diagram of the ADC is shown in Figure 90. The ADC has a separate analog supply voltage pin, AVCC. AVCC must not differ more than 0.3V from VCC. The voltage reference may be externally decoupled at the AREF pin by a capacitor for better noise performance.

BLOCK DIAGRAM: Analog to Digital converter schematic operation The ADC converts an analog input voltage to a 10-bit digital value through successive approximation. The minimum value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB. Optionally, AVCC or an internal 2.56V reference voltage may be connected to the AREF pin by writing to the REFSn bits in the ADMUX Register. The internal voltage reference may thus be decoupled by an external capacitor at the AREF pin to improve noise immunity. The analog input channel is selected by writing to the MUX bits in ADMUX. Any of the ADC input pins, as well as GND and a fixed band gap voltage reference, can be selected as

single ended inputs to the ADC. The ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA. Voltage reference and input channel selections will not go into effect until ADEN is set. The ADC does not consume power when ADEN is cleared, so it is recommended to switch off the ADC before entering power saving sleep modes. The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and ADCL. By default, the result is presented right adjusted, but can optionally be presented left adjusted by setting the ADLAR bit in ADMUX. If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to read ADCH. Otherwise, ADCL must be read first, then ADCH, to ensure that the content of the Data Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers is blocked. This means that if ADCL has been read, and a conversion completes before ADCH is read, neither register is updated and the result from the conversion is lost. When ADCH is read, ADC access to the ADCH and ADCL Registers is re-enabled. The ADC has its own interrupt which can be triggered when a conversion completes. When ADC access to the Data Registers is prohibited between reading of ADCH and ADCL, the interrupt will trigger even if the result is lost. Starting a Conversion: A single conversion is started by writing a logical one to the ADC Start Conversion bit, ADSC. This bit stays high as long as the conversion is in progress and will be cleared by hardware when the conversion is completed. If a different data channel is selected while a conversion is in progress, the ADC will finish the current conversion before performing the channel change.

Fig: ADC Pre Scaler

By default, the successive approximation circuitry requires an input clock frequency between 50 kHz and 200 kHz to get maximum resolution. If a lower resolution than 10 bits is needed, the input clock frequency to the ADC can be higher than 200 kHz to get a higher sample rate. When initiating a single ended conversion by setting the ADSC bit in ADCSRA, the conversion starts at the following rising edge of the ADC clock cycle. A normal conversion takes 13 ADC clock cycles. The first conversion after the ADC is switched on (ADEN in ADCSRA is set) takes 25 ADC clock cycles in order to initialize the analog circuitry. The actual sample-and-hold takes place 1.5 ADC clock cycles after the start of a normal conversion and 13.5 ADC clock cycles after the start of an first conversion. When a conversion is complete, the result is written to the ADC Data Registers, and ADIF is set. In single conversion mode, ADSC is cleared simultaneously. The software may then set ADSC again, and a new conversion will be initiated on the first rising ADC clock edge In Free Running mode, a new conversion will be started immediately after the conversion completes, while ADSC remains high. For a summary of conversion times.

Fig: ADC Timing Diagram, First Conversion (Single Conversion Mode)

ADC Input Channels: When changing channel selections, the user should observe the following guidelines to ensure that the correct channel is selected: In Single Conversion mode, always select the channel before starting the conversion. The channel selection may be changed one ADC clock cycle after writing one to ADSC. However, the simplest method is to wait for the conversion to complete before changing the channel selection. In Free Running mode, always select the channel before starting the first conversion. The channel selection may be changed one ADC clock cycle after writing one to ADSC. However, the simplest method is to wait for the first conversion to complete, and then change the channel selection. Since the next conversion has already started automatically, the next result will reflect the previous channel selection. Subsequent conversions will reflect the new channel selection. ADC Voltage Reference: The reference voltage for the ADC (VREF) indicates the conversion range for the ADC. Single ended channels that exceed VREF will result in codes close to 0x3FF. VREF can be selected as AVCC, internal 2.56V reference, or external AREF pin.

AVCC is connected to the ADC through a passive switch. The internal 2.56V reference is generated from the internal band gap reference (VBG) through an internal amplifier. In either case, the external AREF pin is directly connected to the ADC, and the reference voltage can be made more immune to noise by connecting a capacitor between the AREF pin and ground. VREF can also be measured at the AREF pin with a high impedant voltmeter. Note that VREF is a high impedant source, and only a capacitive load should be connected in a system. It has to be noted that the ADC will not be automatically turned off when entering other sleep modes than idle mode and ADC Noise Reduction mode. ADC Conversion Result: After the conversion is complete (ADIF is high), the conversion result can be found in the ADC Result Registers (ADCL, ADCH). For single ended conversion, the result is:

Where VIN is the voltage on the selected input pin and VREF the selected voltage reference 0x000 represents ground, and 0x3FF represents the selected reference voltage minus one LSB.

LIQUID CRYSTAL DISPLAY


A liquid crystal display (LCD) is a thin, flat display device made up of any number of color or monochrome pixels arrayed in front of a light source or reflector. Each pixel consists of a column of liquid crystal molecules suspended between two transparent electrodes, and two polarizing filters, the axes of polarity of which are perpendicular to each other. Without the liquid crystals between them, light passing through one would be blocked by the other .The liquid crystal twists the polarization of light entering one filter to allow it to pass through the other. Many microcontroller devices use 'smart LCD' displays to output visual information.LCD displays designed around JHDsLCD 2x16 module, are inexpensive, easy to use, and it is even possible to produce a readout using the 8x80 pixels of the display.

They have a standard ASCII set of characters and mathematical symbols. For an 8-bit data bus, the display requires a +5V supply plus 11 I/O lines. For a 4-bitdata bus it only requires the supply lines plus seven extra lines. When the LCD display is not enabled, data lines are tri-state and they do not interfere with the operation of the microcontroller. Data can be placed at any location on the LCD. For 162 LCD, the address locations are:

First line 8F

80

81 C1

82 83 84 85 86 through C2 C3 C4 C5 C6

Second line C0

Fig: Address locations for a 2x16 line LCD

.1.SIGNALES TO LCD:The LCD requires three control singles from the controller:(a) Register select(RS) (b) Read/Write (R/W) (c) Enable(E) (a)Register Select With the help of this line, the LCD interprets the type of data on data lines. When it is low, an instruction is being written to the LCD. When it is high, a character is being write to the LCD. (b) Read/ Write
. This line determines the direction of data between the LCD

and microcontroller. When it is low, data is written to the LCD. When it is high, data is read from the LCD. (c)Enable

This line allows access to the display through R/W and RS lines. When this line is low, the LCD is disabled and ignores signals from R/W and RS. When (E) line is high, the LCD checks the state of the two control lines and responds accordingly.

Logic status on control lines:


E - 0 Access to LCD disabled - 1 Access to LCD enabled R/W - 0 Writing data to LCD - 1 Reading data from LCD RS - 0 Instructions - 1 Character

Writing and reading the data from the LCD:


Writing data to the LCD is done in several steps: 1) Set R/W bit to low 2) Set RS bit to logic 0 or 1 (instruction or character) 3) Set data to data lines (if it is writing) 4) Set E line to high 5) Set E line to low Read data from data lines (if it is reading): 1) Set R/W bit to high 2) Set RS bit to logic 0 or 1 (instruction or character) 3) Set data to data lines (if it is writing) 4) Set E line to high 5) Set E line to low.

PIN DESCRIPTION:
Most LCDs with 1 controller has 14 Pins and LCDs with 2 controllers has 16 Pins. (two pins are extra in both for back-light LED connections) 1 Vss 2 3 4 5 RS R/W 6 E 7 D0 8 D1 9 D2 10 D3 11 D4 12 D5 13 D6 14 15 16

Vcc VEE

D7 LED LED

Timing Diagram for w

Timing Diagram for write mode

Timing Diagram for Read data mode

LCD In 4 bit Mode:


If 8-bit mode cannot be used (not enough free pins on the AVR side or due to PCB design problems), the 4 bit mode of compatible LCDs can be used. In this mode only the upper 4 data lines are used and the control lines stay the same, which makes a total of 7 lines for the LCD. However, the code size and execution time increase, as each data or control byte has to be sent to the LCD in 2 nibbles. The basic principles of using LCDs are the same as in 8-bit mode. The commands are the same and the busy flag should be checked before any operation. Writing data or commands to the LCD in 4-bit mode is done high nibble first, then low nibble, so the enable pin (E) has to be strobed twice. Special care should be taken when using a single AVR port, as mixing up input and output lines can damage both the AVR and the LCD. Here's a one-port setup for using an LCD in 4-bit mode (PortD): PortD.4 ... PortD.7 -> Data.4 ... Data.7 PortD.3 -> LCD Enable line PortD.2 -> LCD RW line PortD.1 -> LCD RS line The control lines are always output lines from the controller to the LCD, but the data line direction changes depending on the current operation (as already noted, special care should be taken here!). For initializing the LCD, we need to write commands to it. After power-up the LCD is in 8-bit mode by default. For switching to 4-bit mode, we need to write an 8-bit command to it . But we have got 4 data lines, so how should we write an 8-bit command? The good news about this is that the data length bit is in the upper nibble, which is connected to the LCD. The lower 4 bits are not important now. We just want to set the data length to 4 bits now. As it is an 8-bit command, we only have to strobe E once, not

twice as in 4-bit mode. The extra routine is ONLY needed for initialization. The only thing to watch out for is the data direction for each pin, as control and data lines share the same port Now writing characters to the LCD works EXACTLY like writing commands, but when writing character RS is taken high, while for commands it is taken low. First of all, the data direction bits for the data lines are set for output, as in DDRD |= 0xF0; Then, for safety, all LCD lines are cleared. PortD.0 is not used by the LCD, so this bit is saved through this process In 4-bit mode, the high nibble of our data byte is written first, then the low nibble is written. For writing the high nibble, the low nibble of the argument is cleared. Then the rest (the high nibble) is combined with the Port D data: Port D |= (argument & 0xF0); Then the control lines are set as needed: RS high (char) or low (command), RW low. Then E is strobed to write the high nibble. Now we need the low data nibble, which we destroyed by clearing the low nibble before for writing the high nibble. This means that the argument has to be saved at the beginning of the routine (in this case it's pushed onto the stack). For getting the low nibble again, we now pop the argument again and clear the high nibble. The data lines are on the high port lines though, so we also need to swap the argument now. The high port data nibble is cleared, then the port data is OR-ed with the argument to set the data lines as required. Again, E is strobed. Before returning from the routine, the data direction of the LCD data port is set to input again, the control lines stay outputs. This procedure is the same for data and commands, as already mentioned. With these tools (LCD_ command and LCD_command8) it's possible to init the LCD (a small delay routine is also needed). First, the LCD is set to 4-bit mode. Then the usual settings are made When reading from the LCD, the high nibble is also transmitted first. We have to read it while E is high during the E strobe. The read routines first make sure that the data direction bits for the data lines are zero (input). Then E is taken high and the PIN data is read. Now the pin data still contains some unknown bits and these bits are masked away. The

remaining value is the high nibble of the data read, which will be stored in the high nibble of our return value .Then the low nibble is read in the same manner (read PINs while E is high). For combining the high nibble with the new low nibble we again have to clear the unused bits in the value from the PIN register. The low nibble of the LCD data is now in the high nibble of the PIN value, so we need to swap the pin value. Then OR is used to combine the return value (high nibble) with the new low nibble.

CHAPTER 4

INTERFACING OF SENSORS AND LCD

SENSOR INTERFACING AND CALIBRATION:


Interfacing is the first important concept in such projects .Interfacing is the arrangement which provide clear communication between the controller and the peripherals. Interfacing the sensors:(1)

sensor we mean that the datas send by the sensors are

read by the controller and can display them. Basically our circuit consists of two

Light sensor Here we are using one low

resistance LDR

which produces mV output when light falls on it. The output voltage varies linearly with incident light .One 1K ohm resistance is also connected in series with this LDR. The output line is directly connected to channel 0 of ADC of the AVR. A 5V DC power supply is feed to the circuit. The sensor node voltage is compared with the threshold voltages for different levels of light intensity corresponding to the three conditions- Optimum, dim, dark .For this purpose we are using 25, 40 , 60 ,100 ,200 WATT bulbs. Calibrating the HEX numbers we are expressing the output in lumen. In order to increase the sensitivity of the sensor we must increase the value of the fixed resistor connected in series with the sensor. This may be done by putting other resistors in series with it. (2)Temperature Sensor-We are using LM35 sensor to get the temperature values. The sensor that we are using has a negative temperature coefficient. Hence when we are applying temperature to the LM the voltage output voltage decreases .The output of the LM can also be connected to a amplifier but here we are not doing this .We are directly connecting the output of the LM to the channel 1 of the ADC of the AVR.As temperature decreases LM output also decreases. Moreover we have also connected a 10 K ohm resistor in series with it in between the supply terminal of the sensor

and the supply to the circuit which is also 5V DC supply. The important thing about this sensor is this the output also varies linearly with temperature. This sensor produces 10mV output per degree change in temperature. Apart from sensor interfacing we also have LCD interfacing which is also very important because we are displaying the readings in LCD. The list of commands us to interface LCD with the controller are as follows:-

01 06 28 0F 80 line

LCD clear increment cursor control word for 4-bit mode cursor blinking force cursor to the beginning of first

CHAPTER 5

SOFTWARES AND PROGRAMMER

DEVELOPING THE PROJECT FOR THE AVR MICROCONTROLLER:


Developing the project for the AVR atmega8 involves proper selection of the editor,assembler,linker,simulator and AVR burner.The processs can be categorized in the following steps1. Write a Program 2. Build it 1. Compile and Assemble (.o File) 2. Link into a Binary (.out File) 3. Generate a .hex File 4. Program the Device 5. Debug 3. Automate with a Makefile

There are various commands available through which all these steps to build a file is executed. Rather than writing whole lot commands,all these can be put in single file called Makefile ,which is exactly what is done by WINAVR Programmer. WINAVR PROGRAMMER : To write the program we are using WINAVR

Programer Notepad. Programmer's Notepad (PN1) is an open-source text editor targeted at users who work with source code. They feature syntax highlighting for many programming languages through plugins called "schemes." Scheme files can be added to support more languages. PN1 scheme files are not compatible with PN2 scheme files. PN1 included syntax highlighting for: C++, CSS, HTML, INI, Java, JavaScript, AutoLISP, Pascal, Perl, SQL, Visual Basic and XML. AVRDUDE is a FreeBSD Unix program for programming Atmels AVR CPUs. It can program the Flash and EEPROM, and where supported by the serial programming protocol, it can program fuse and lock bits. AVRDUDE also supplies a direct instruction mode allowing one to issue any programming instruction to the AVR chip regardless of whether AVRDUDE implements that specific feature of a particular chip. AVRDUDE can be used as a command line tool (convenient tu use with makefiles) or interactively via terminal. It can program microcontrollers flash, EEPROM, fuse bits, modify individual bits, explore memory contents etc. As we are using windows XP environment, we need to set up port drivers to enable AVRDUDE direct access to ports. For this in a AVRDUDE package is handy tool included: install_giveio.bat which copies needed driver files to windows directory. For this just run: C:\WinAVR\bin>install_giveio.bat Copying the driver to the windows directory target file: C:\WINDOWS\giveio.sys After this installation you can check driver status by writing command: C:\WinAVR\bin>status_giveio.bat

When port drivers are set up, then we can connect the AVR microcontroller via same AVR ISP cable. Now open console window and write command line: C:\WinAVR\bi>avrdude -p m8 -c pony-stk200 -e -U flash:w:demo.hex This command line programs Atmega8 flash memory with demo.hex contents using simple AVR ISP adapter. Now we have to build WinAVR project in Programmers Notepad editor. For this we need to prepare Makefile by chosing programmer type and ports. So now by creating the document in C++ in notepad we can run the project by selecting the program command in the tool manue.

This command builds the project and automatically sends hex file to AVR microcontroller

Fig: Screenshot of the programmers notepad

AVR PROGRAMMER/BURNER This simple AVR Programmer will allow you to painlessly transfer hex programs to most ATMEL AVR microcontrollers without sacrificing your budget and time. It is more reliable than most other simple AVR programmers available out there and can be built in very short amount of time. AVR programmer consists of in-circuit serial programmer (dongle) and small pcb with a DIP socket where you can fit your microcontroller and have it quickly programmed.

Entire AVR programmer has been build with using common parts and fits in the case of the serial connector. The socket pcb has been created to fit a 28-DIP AVR ATmega8 microcontroller, but we can build a socket PCB for any other AVR microcontroller .

There are two connections; ICSP that connects to AVR Programmer, and external +5V supply. Socket PCB consists of the PCB, 28-DIP socket, 4MHz crystal resonator, or crystal with two 22pF decoupling capacitors, and two header connectors. Two-PIN connector supplies +5V voltage to the AVR microcontroller, and 6-PIN ICSP connects to AVR Programmer dongle. Supplying microcontroller with external +5V voltage as opposed to taking it directly from computer's serial connection port ensures that the chip is receiving exactly +5V voltage and provides very reliable error free programming.

Fig: RS 232 interfacing circuit

Fig: AVR socket PCB design for the programming part

CHAPTER 6

SOURCE CODE

/ ************************************************************************************** ********

:REAL TIME MONITORING OF TEMPERATURE AND LIGHT INTENSITY USING AN ATMEGA8 MICROCONTROLLER :PROJECT_ CODE ************************************************************************************** **********/

#include<stdio.h> #include<avr/io.h> #include <util/delay.h> const unsigned char key[]={'0','1', '2', '3','4','5','6', '7','8','9','A','B','C','D','E','F' }; const unsigned char lightl[]={ 0x00,0xC7,0x60,0xB0,0x38,0xA0}; const unsigned char lighth[]={ 0x00,0x00,0x01,0x01,0x02,0x02}; const int lihgtdiv[]={0,295,425,710,1340,3360}; unsigned char p2,p3,p4,p5,addl,addh,scan; int loc;

void lcd_com(unsigned char); void lcd_data(unsigned char); void init_dis(void); void adc_pro(unsigned char); void adc_dis(void); void light_mes(void); void temp_mes(void); void display_mes(void); void text_dis(void); void display_light(void);

int main(void) { DDRB = 0xFF; //Make Port B output values init_dis(); _delay_ms(1); text_dis(); while(1)

{ temp_mes(); light_mes(); _delay_ms(20); } return 0; } void lcd_com(unsigned char value) { unsigned char p1; p1=value&0xF0; p1= p1| 0x04; PORTB = p1; _delay_ms(1); p1=p1&0xF0; PORTB = p1; _delay_ms(1); p1= value<<4; p1 = p1 &0xF0; p1= p1| 0x04; PORTB = p1; _delay_ms(1); p1=p1&0xF0; PORTB =p1; } void lcd_data(unsigned char value) { unsigned char p1; p1=value&0xF0;

p1= p1| 0x06; PORTB = p1; _delay_ms(1); p1=p1&0xF2; PORTB = p1; _delay_ms(1); p1= value<<4; p1 = p1 &0xF0; p1= p1| 0x06; PORTB = p1; _delay_ms(1); p1=p1&0xF2; PORTB =p1; } void init_dis() { _delay_ms(1); lcd_com(0x28); _delay_ms(1); lcd_com(0x01); _delay_ms(1); lcd_com(0x06); _delay_ms(1); lcd_com(0x0F); } void adc_pro(unsigned char xx) {

/********************************************************

ADMUX bits: D7=REFS1 D6=REFs0 0 0 1 1 0 - AREF internal Vref turn off 1 - AVcc with ext capacitor at AREF pin 0 - Reserved 1 - Internal 2.56 V reference with ext capacitor at AREF pin D5 = ADLAR =0 ADC0 - ADC9 <- D0 - D9 bits of adc data Reg =1 ADC0 - ADC9 <- D6 - D15 bits of adc data Reg D4 = 0 D3=MUX3 D2=MUX2 D1=MUX1 D0=MUX0 0 0 . 0 0 . .............. 0 0 0 1 - ADC0 - ADC1

.......................... 1 1 1 1 -ADC7

*************************************************************/ xx=xx&0x0F; xx=xx|0xC0; ADMUX=xx; _delay_ms(1); ADCSRA = 0xD0;/*ADEN =1,ADSC =1 & ADIF=1 ie ADC is enabled in non-interrupt, single conversion mode*/ do { scan=ADCSRA&0x40;/* check for ADSC = 1*/ } while(scan == 0x40);

_delay_ms(1); addl= ADCL; addh= ADCH; } void adc_dis() { p3=addh&0x03; lcd_data(key[p3]); p3=addl>>4; p3=p3&0x0F; lcd_data(key[p3]); p3=addl&0x0F; lcd_data(key[p3]); } void light_mes() { unsigned int xx,yy1,yy2,zz,i; unsigned int dif_value; adc_pro(0x00); xx = addh<<8 | addl;/* 16 bit ADC data */ p2=0x00; p3=0x00; p4 =0x00; p5=0x00;/* Minimum intensity values*/ loc=0; yy2=(lighth[loc] <<8 |lightl[loc]); while( yy2 <= xx ) { loc=loc+1; yy2=(lighth[loc] <<8 |lightl[loc]);/*16 bit look-up table data */ } yy1=(lighth[loc-1] <<8 |lightl[loc-1]);

dif_value= lihgtdiv[loc] - lihgtdiv[loc-1]; zz = lihgtdiv[loc-1] + (dif_value/(yy2-yy1))*(xx - yy1);

/****************************************** Linear interpolation for intermediate values ******************************************/ for(i=1;i< zz;i++) { p5=p5+1; if( p5 > 0x09 ){p5=0x00; p4=p4+1;} if(p4 > 0x09 ) {p4=0x00; p3=p3+1;} if(p3 > 0x09 ) {p3=0x00; p2=p2+1;} } display_light(); } void temp_mes() { int i; unsigned int init_value,zz; unsigned int xx; addl=0x15; addh=0x01; init_value = addh<<8 | addl;/* 16 bit data w r t 10 degree */ adc_pro(0x01);

xx = addh<<8 | addl;/* 16 bit ADC data */ p2=0x01; p3=0x00; p4 =0x00;/* Minimum temperature values*/ while( init_value > xx ) { init_value = init_value - 0x04;

p3=p3+1; if(p3 > 0x09){ p3=0x00; p2=p2+1;} } p3=p3-1; if( p3 > 0x09 ) {p3=0; p2=p2-1;} init_value= init_value + 0x04; zz = init_value - xx;

for(i=1;i<=zz;i++) { p4=p4+2; } if( p4 > 0x09 ) p4= 0x09; display_mes(); } void display_light() { lcd_com(0xC7); lcd_data(key[p2]); _delay_ms(1); lcd_data(key[p3]); _delay_ms(1); lcd_data(key[p4]); _delay_ms(1); lcd_data(key[p5]); _delay_ms(1); lcd_data(' '); _delay_ms(1); lcd_data('L');

_delay_ms(1); } void display_mes() { lcd_com(0x87); lcd_data(key[p2]); _delay_ms(2); lcd_data(key[p3]); _delay_ms(2); lcd_data('.'); _delay_ms(2); lcd_data(key[p4]); _delay_ms(2); lcd_data(' '); _delay_ms(2); lcd_data('C'); _delay_ms(2); }

void text_dis() { lcd_com(0x80); lcd_data('T'); _delay_ms(2); lcd_data('e'); _delay_ms(2); lcd_data('m'); _delay_ms(2); lcd_data('p');

_delay_ms(2); lcd_data('='); _delay_ms(2);

lcd_com(0xC0); _delay_ms(2); lcd_data('L'); _delay_ms(2); lcd_data('i'); _delay_ms(2); lcd_data('g'); _delay_ms(2); lcd_data('h'); _delay_ms(2); lcd_data('t'); _delay_ms(2); lcd_data('=');

CHAPTER 7

RESULT ANALYSIS

CALIBRATION
LDR Calibration: The data that we have obtained from our experiments are as follows . We take a dark condition as the basis for calculating intensity as 0(zero) lumen. For lumen value evaluation against digital non-calibrated output. We kept the bulbs of varios power ranges at a vertical distance of 5 cm from the LDR . Each bulb having specific lumen is calibrated as follows -

WATT 0 25 40 60 100 200

HEX VALUE IN LCD 00 0C7 160 1B0 238 270

RATED LUMEN 0 225 415 710 1345 3360

Now calibrating all these values by interpolation formula we get the final readings in lumen. TEMPERATURE CALIBRATION: FORMULA: Output voltage ( o C ) = Vcc/(RLM+10)
TEMP 27 28 29 30 31

HEX value

0FC

110

114

118

11C

The ADC has 10 bit resolution. Hence with each degree rise in temperature we LCD display will be increased by 4 counts.

CHAPTER 8

ADVANTAGES AND DISADVANTAGES

ADVANTAGES AND DISADVANTAGES:


ADVANTAGES1. Sensors used have high sensitivity and are easy to handle. 2. Low maintenance and low power consumption. 3. The system is more compact compared to the existing ones, hence is easily portable. 4. Can be used for different plant species by making minor changes in the ambient environmental parameters. 5. Can be easily modified for improving the setup and adding new features. 6. Malfunctioning of single sensor will not affect the whole system.

DISADVANTAGES. 1. No self-test system to detect malfunction of sensors. 2. Requires uninterrupted power supply.

CHAPTER 9

CONCLUSION

The proposed system can be extended to wireless communication with PC or small weather station by incorporating other types of transducers like PH measurement transducers, anemometers etc. It can also be implemented to control any one of the parameters for in house environmental conditions. .

The number of channels can be increased to interface more number of sensors which is possible by using advanced versions of microcontrollers.

The performance of the system can be further improved in terms of the operating speed, memory capacity, instruction cycle period of the microcontroller by using improved versions of other microcontroller.

A multi-controller system can be developed that will enable a master controller along with its slave controllers to automate multiple greenhouses simultaneously

Can be connected to communication devices such as modems, cellular phones or satellite terminal to enable the remote collection of recorded data or alarming of certain parameters.

Você também pode gostar