Temperature Sensor(LM35 ) Interfacing With ATmega32 and LCD Display| Automatics Fan Control

3,628

2

Temperature Sensor(LM35 ) Interfacing with ATmega32 and LCD Display

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1:

In this project, You will learn How to interface a Temperature Sensor(LM35 ) with AVR ATmega32 Microcontroller and LCD display.

Before This Project you have to need Learn about following articles

how to add lcd library in avr studio| avr microcontroller tutorial

introduction to ADC in AVR Microcontroller | for beginners

Temperature Sensor(LM35 ) is a popular and low cost temperature sensor. The Vcc can be from 4V to 20V as specified by the datasheet. To use the sensor simply connect the Vcc to 5V ,GND to Ground and the Out to one of the ADC (analog to digital converter channel).

The output is 10MilliVolts per degree centigrade. So if the output is 310 mV then temperature is 31 degree C. To make this project you should be familiar with the ADC of AVRs and also using LCD So The resolution of AVRs ADC is 10bit and for reference voltage you are using 5V so the resolution in terms of voltage is

5/1024 = 5.1mV approximately

So if ADC’s result corresponds to 5.1mV i.e. if ADC reading is

10 x 5.1mV = 51mV

You can get read the value of any ADC channel using the function adc_result(ch);

Where ch is channel number (0-5) in case of ATmega8. If you have connected the LM35’s out put to ADC channel 0 then call

this will store the current ADC reading in variable adc_value. The data type of adc_value should be int as ADC value can range from 0-1023.

As we saw ADC results are in factor of 5.1mV and for 1 degree C the output of LM35 is 10mV, So 2 units of ADC = 1 degree.

So to get the temperature we divide the adc_value by two

temperature = adc_result0 /2;

Finally the microcontroller will display the temperature in degree centigrade in the 16X2 alphanumeric LCD.

Step 3: Program

#ifndef F_CPU

#define F_CPU 1600000UL

#endif

#include

#include

#include "LCD/lcd.h"

{

// AREF = AVcc

// ADC Enable and prescaler of 128

}

{

// select the corresponding channel 0~7

ch &= 0b00000111; // AND operation with 7

// start single conversion

// write '1' to ADSC

// wait for conversion to complete

// ADSC becomes '0' again

}

int main()

{

DDRB=0xff;

int temp;

int far;

char buffer;

// initialize adc and lcd

lcd_init(LCD_DISP_ON_CURSOR); //CURSOR

lcd_clrscr();

lcd_gotoxy(0,0);

_delay_ms(50);

while(1)

{

temp=adc_result0/2.01; // finding the temperature

//lcd_gotoxy(0,0);

//lcd_puts(buffer);

lcd_gotoxy(0,0);

itoa(temp,buffer,10);

lcd_puts("Temp="); //display temperature

lcd_puts(buffer);

lcd_gotoxy(7,0);

lcd_puts("C");

far=(1.8*temp)+32;

lcd_gotoxy(9,0);

itoa(far,buffer,10);

lcd_puts(buffer);

lcd_gotoxy(12,0);

lcd_puts("F");

_delay_ms(1000);

if(temp>=30)

{lcd_clrscr();

lcd_home();

lcd_gotoxy(0,1);

lcd_puts("FAN ON");

PORTB=(1<

}

if (temp<=30)

{

lcd_clrscr();

lcd_home();

lcd_gotoxy(7,1);

lcd_puts("FAN OFF");

PORTB=(0<

}

}

}

Step 4: ​Code Explain

I hope you Know you will know How to enable ADC and How to interface LCD with Avr Microcontroller in this code when temperature is more then 30 degree then fan is on and you can see on led Display FAN ON and when Temperature Less then 30 then fan is off and you can see FAN OFF