Monday, June 17, 2013

Digital Temperature Display using LM35

Here is an Exercise where we will display the temperature on the LCD.

For working on this project we need Atmega 16 microcontroller ,LM35 temperature sensor and a LCD.

Lets start with practical.

Hardware Preparation :
This is very easy what i will do is that i will connect the lm35 sensor to the ADC ports(PORTA) of the microcontroller and read the voltage and will display the temperature by using some formula.

Step:1
We have to connect the lm35 in correct order , remember if you will connect in wrong order , it will start heating up , that is the signal that you have connected in wrong configuration.



Now connect the output to the ADC0 Pin (A0 Pin of PORTA ) of the Atmega 16.
Once this done , now we are done with harware part.

Now before going to the coding we have to analyise somthing ,that how will proccess the read value from the adc ports.

we know that when we will provide any voltage to the adc ports , it will give me the quantization level eqivalent.As we also know that Atmega 16 has 10 bit Adc , so the quantization level will be 2power(10)=1024.
So it means that when i will provide the input of 5 volts to the adc pin , adc port will give me quantization level as 1024.

We should know somrthing abt the LM35 , it comes with rating called 10mv/degree C.
It means that if temperature is 1 degree C then the output from the output wire of LM35 will be 10mv.

Simailarly we know that ideal room temperature is 27 degree C , so my lm35 output will be in range of 270mv.

Question : How to get the temperature after reading the ADC ports ?
Answer : It is very easy , what i know is that Adc port will give me the quantization level eqivalent .
so if i multiply the qunatization level with the step size (5/1024). i will get the voltage.

Once i got the voltage , i will divide the voltage by 10mv to get the temperature.

For Eg :Lets take adc is showing 65 as reading .
Quantization level shown by adc =65
voltage  = 65 *(5/1024)  , where 5/1024 is step size.
temperature = voltage /10mv.

Let move on to the coding section :

Step 2:
Code for Lm35 is very easy , only thing is that you should know how to use ADC ports.

Please connect the harware for the lcd as mentioned in other tutorials of Embedded .


#include<avr/io.h>
#define F_CPU 1000000UL
#include<util/delay.h>

#include "lcd.h"   // includeing header file for lcd
#include "adc.h"   // including header file for adc



void custom_char();
int main()
{
    unsigned int temp;
    DDRD = 0XFF;
    lcd_init();
    adc_init();
        _delay_ms(1000);
        char str[] = "Temperature";
    custom_char();              // this is used to show the degree symbol      
while(1)
{
    temp=adc_read(0);             // reading the adc port0
       _delay_ms(200);

    temp=value*500;
    temp=value/1024;
        _delay_ms(200);

     SendCommand(0x80);              
     SendString(str, 1, 0);   // displaing text of str
     SendCommand(0x8d);
     SendInt(temp,1,13);       //displaying the int value on lcd
     SendCommand(0x8e);
     SendData(0);              // Displaying the special char of degree smbol
     SendCommand(0x8f);
     SendData('C');
         _delay_ms(500);

  }
   
    return 0;
}

void custom_char()
{
    SendCommand(0x40);

    SendData(0b00000110);
    SendData(0b00001001);
    SendData(0b00000110);
    SendData(0b00000000);   
    SendData(0b00000000);
    SendData(0b00000000);
    SendData(0b00000000);
    SendData(0b00000000);
   
}

But this code will give you error until and unless you will include the 2 header file.

LCD Header file

ADC Header file

Once these are included , now you can see the temperature on the lcd.

If you like my post , then please join us as a member to this blog.
Thanks.......






No comments:

Post a Comment