About LM35 :
The LM35 is an integrated circuit sensor that can be used to measure temperature with an electrical output proportional to the temperature (in oC).The LM35 device has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from the output to obtain convenient Centigrade scaling.
Why Use LM35s To Measure Temperature?
- You can measure temperature more accurately than a using a thermistor.
- The sensor circuitry is sealed and not subject to oxidation, etc.
- The LM35 generates a higher output voltage than thermocouples and may not require that the output voltage be amplified.
What Does an LM35 Do? How does it work?
- It has an output voltage that is proportional to the Celsius temperature.
- The scale factor is .01V/oC
- The LM35 does not require any external calibration or trimming and maintains an accuracy of +/-0.4 oC at room temperature and +/- 0.8 oC over a range of 0 oC to +100 oC.
Temperature Sensor LM35 using ADC and LPC2148
Circuit Diagram :
/******************************************************
IDE :- Keil
DEVELOPED BY:- FIRMWARE DEVELOPER (www.firmcodes.com)
WHAT PROGRAM DO:- Temperature Sensor(LM35) using ADC and LPC2148
WITH ARM(LPC2148) CONTROLLER
******************************************************/
#include<lpc214x.h>
#include<stdio.h>
#define adc_sel 27 //for pinsel
#define clkdiv 8
#define ch0 0
#define burst_mode 16
#define pdn 21
#define start 24
#define done 31
#define lcdport IO0SET
#define lcdportclr IOCLR0
#define rs 12
#define en 13
#define TEMP_PIN (1<<29) //P0.29 as Input to Temperature Sensor
#define TEMP_PIN_DIR (1<<26) //Bit 27:26 of PINSEL1 register
#define _PDN_BIT 1<<21
#define _ADCR_START_MASK 7<<24
#define _ADCR_SEL_MASK 0x000000FF
#define _ADC0_START 1<<24
#define FAN_ON IO1SET=(1<<18)
#define FAN_OFF IO1CLR=(1<<18)
#define EXAHAUST_ON IO1SET = (1<<19)
#define EXAHAUST_OFF IO1CLR = (1<<19)
#define DRAIN_ON IO1SET=(1<<20)
#define DRAIN_OFF IO1CLR=(1<<20)
void delay(int t)
{
int i,j;
for(i=0;i<t;i++)
for(j=0;j<5000;j++);
}
void cmnd()
{
lcdportclr=(1<<rs);
//lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(40);
lcdportclr=(1<<en);
}
void lcdcmd(char ch)
{
lcdport = ((ch&0xf0)<<13);
cmnd();
lcdportclr = ((ch&0xf0)<<13);
lcdport = (((ch<<4)&0xf0)<<13);
cmnd();
lcdportclr = (((ch<<4)&0xf0)<<13);
}
void daten()
{
lcdport=(1<<rs);
//lcdportclr = (1<<rw);
lcdport = (1<<en);
delay(40);
lcdportclr=(1<<en);
}
void lcddata(char ch)
{
lcdport = ((ch&0xf0)<<13);
daten();
lcdportclr = ((ch&0xf0)<<13);
lcdport = (((ch<<4)&0xf0)<<13);
daten();
lcdportclr = (((ch<<4)&0xf0)<<13);
}
void lcdstring(char *str)
{
int j;
for(j=0;str[j]!='\0';j++)
{
lcddata(str[j]);
}
}
void lcd_init()
{
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x01);
lcdcmd(0x0e);
}
void io_init()
{
PINSEL0=0X000;
IODIR0=0xffffff;
}
void Adc0Init(unsigned char clk)
{
PCONP |= 0x00001000;//Power on the A/D converter 0
//configure the A/D control register of A/D 0
AD0CR =((unsigned long)(clk+1)<<8 ) | _PDN_BIT ;
}
unsigned int Adc0Read(unsigned char channel)
{
static unsigned val;
AD0CR &= ~(_ADCR_START_MASK|_ADCR_SEL_MASK); //stop the A/D converter by masking the
//start bits and channel selection bit
AD0CR |=((unsigned long)(1)<<channel); //Select the A/D channel
AD0CR |=_ADC0_START;
while(!(AD0GDR & (0x80000000))); //Wait for the conversion to get over
//by monitoring the 28th bit of A/D data register
AD0CR &= ~(_ADCR_START_MASK|_ADCR_SEL_MASK); //Stop the conversion by masking the start bits
val = AD0GDR;
val = ((val>>6 & 0x03FF)); //Extract A/D result
return(val);
}
int main()
{
float temperature=0.0;
char result[5];
PINSEL1 |= TEMP_PIN_DIR; //Bit 27:26 of PINSEL1 register
IODIR0 &= ~(TEMP_PIN); //Select the AD0.3 of P0.28 as Input
io_init();
lcd_init();
lcdcmd(0x84);
lcdstring("Temperature");
Adc0Init(10);
while(1)
{
temperature = (((float)Adc0Read(2)/1023.0)*3.3*100);
lcdcmd(0xc5);
sprintf(result,"%f",temperature);
lcdstring(result);
lcddata(0xDF); //for degree character
lcddata('C');
delay(100);
if(temperature>=0 && temperature <=30)
{
DRAIN_OFF;
EXAHAUST_OFF;
FAN_ON;
}
else if(temperature>30 && temperature<=50)
{
FAN_OFF;
DRAIN_OFF;
EXAHAUST_ON;
}
else if(temperature >=50 && temperature<=70)
{
EXAHAUST_OFF;
DRAIN_ON;
FAN_OFF;
}
}
}