LM35

Temperature sensor (DIY Thermometer)

Overview

download
LM35 Temperature Sensor
  • Operating Voltage: 4-20V
  • 3 pins: VCC, GND, SIGNAL
  • SIGNAL pin changes voltage according to the temprature

Description

LM35 is a 3 pin temperature sensor which requires a VCC and GND and in return the remaining third pin gives us an analog output. For its pin configurations refer to the Circuit Diagram below. This output is then provided to the ADCs present in AtMega 16 IC which according to a formula calculate the temperature in °C format.

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin.

Features

  • Calibrated directly in ° Celsius (Centigrade)
  • Linear + 10.0 mV/°C scale factor
  • 5°C accuracy guarantee able (at +25°C)
  • Rated for full −55° to +150°C range
  • Operates from 4 to 30 volts (in this project its working on 5 V)
  • Low self-heating, 0.08°C in still air

 

ADCs work as a bridge in understanding the analog input and convert them into digital values which could be further used in our calculations. Now according to LM35’s datasheet, it changes the output voltage by 10mV for every rise or fall in 1°C. Also these ADCs are 10 bit in nature so they can give up-to 1024 decimal values (0-1023). These ADCs have a resolution of 4.88mV which means for every rise or fall of 4.88mV in the analog input the digital output will increase or decrease by one unit, respectively.

So the whole concept lies in finding a formula that could calculate the temperature using the digital values from ADC. Now what I have done is, I have first calculated the analog input voltage from LM35 then according to its (LM35) datasheet I have converted that voltage into °C format.

“voltage=((adc*5)/1024);”: This statement in my coding part measures the analog voltage and stores it into a floating variable ‘voltage’. Here ‘adc’ is the digital value read form ADC0 pin.

Now to calculate the temperature value I have used this statement: voltage*=100;

One more interesting task was to deal with the float values and to display them on the LCD. As we know LCDs cannot display float/integer values as it is, they need a character input, so I have defined a function:”convert(float val,char A[16])” in my coding part which requires a float value(val) to be stored in character array/string (here A[16]). Basically this function stores the float value in a character format as it is. This function can show floating values up-to two decimal places.

LCD connections are as follows:

  • The data pins are connected to PB4-7 (since its working in a 4-bit mode)
  • RS, R/W and EN pins are connected to PB0, 1 and 2 respectively.

I have connected the analog input from the temperature sensor at pin ADC0. The Aref pin is provided +5V. This means that ADC0 is working with its reference voltage to be +5V.

Circuit Diagram

Untitled

Code


#include<avr/io.h>
#include<util/delay.h>
#include<adc_lib.h>
#include<lcd.h>

void convert(float val,char A[16])
{
unsigned long int a=val*100,i=0;
unsigned char arr[16],temp;

while(a)
{
arr[i]=(a%10) + 48;

a=a/10;

i++;
}

arr[i]='\0';

i=0;

for(i=0;i<strlen(arr)/2;i++)
{

temp=arr[i];

arr[i]=arr[strlen(arr)-i-1];

arr[strlen(arr)-i-1]=temp;
}

i=strlen(arr);

arr[i]=arr[i-1];

arr[i-1]=arr[i-2];

arr[i-2]='.';

arr[i+1]='\0';

if(val==0)
{
arr[0]='0'; arr[1]='\0';
}

strcpy(A,arr);

}

void main()

{

float voltage,adc;
char ch[16];
ADCinit();
LCDinit();
LCDclr();
LCDcursorOFF();

while(1)
{
adc=read_adc(0);        //ADC0 pin

voltage=((adc*5)/1024); //measuring analog voltage

voltage*=100;           //converting voltage to temperature

convert(voltage,ch);    //storing temperature in string ch

LCDGotoXY(0,0);

LCDdisplay(ch);

LCDsendChar(223);       //223 is the ASCII value for °

LCDdisplay("C   ");
}}

Links

Temperature Sensor LM35 [Video Link]

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar