Temperature Sensor(LM35 ) Interfacing with ATmega32 and LCD Display
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
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
adc_result0 = adc_read(0);
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 2: Circuit Diagram
Step 3: Program
#define F_CPU 1600000UL
// AREF = AVcc
ADMUX = (1<
// ADC Enable and prescaler of 128
ADCSRA = (1<
// read adc value
uint16_t adc_read(uint8_t ch)
// select the corresponding channel 0~7
ch &= 0b00000111; // AND operation with 7
ADMUX = (ADMUX & 0xF8)|ch;
// start single conversion
// write '1' to ADSC
ADCSRA |= (1<
// wait for conversion to complete
// ADSC becomes '0' again
while(ADCSRA & (1<
// initialize adc and lcd
adc_result0 = adc_read(0); // read adc value at PA0
temp=adc_result0/2.01; // finding the temperature
//itoa(adc_result0,buffer,10); //display ADC value
lcd_puts("Temp="); //display temperature
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