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

13,123

2

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

Temperature Sensor(LM35 ) Interfacing with ATmega32 and LCD Display

## 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

10 x 5.1mV = 51mV

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

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

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

// wait for conversion to complete

}

int main()

{

DDRB=0xff;

int temp;

int far;

char buffer;

lcd_init(LCD_DISP_ON_CURSOR); //CURSOR

lcd_clrscr();

lcd_gotoxy(0,0);

_delay_ms(50);

while(1)

{

//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