# Interfacing LM35 sensor with PIC 16F877A Problem!!!

Status
Not open for further replies.

#### imaasac

##### Newbie level 6
Hi guyz!
I am trying to interface lm35 sensor with PIC microcontroller and light the LED when temperature goes beyond 40 deg Celsius. I am using 16F877a pic and using compiler PICC in C language. I have done simulation on Proteus and got no results. I have write this code, can any body tell me where is the problem in this code. Thanks

Code:
#use delay(clock=10000000)
int16 temp, cent;
int16 triptemp, triptempc=40;
void main()
{

TripTemp = ((TripTempC/1023)*500);
while(1)
{

cent=((temp/1023)*500);

if(cent>triptemp)
{
output_high(53);
}
else
{
output_low(53);
}
delay_ms(100);

}
}

#### ckshivaram

search in the forum.... you will get it

---------- Post added at 22:04 ---------- Previous post was at 22:01 ----------

you already got the code and already the program for temp measuring and activating buzzer from me and tahmid,......

you expect us to do the project for you..............

already told.. until you learn yourself you will always run for help... dont expect tahmid to answer viva tooo.. he is a busy person

#### imaasac

##### Newbie level 6
search in the forum.... you will get it

---------- Post added at 22:04 ---------- Previous post was at 22:01 ----------

you already got the code and already the program for temp measuring and activating buzzer from me and tahmid,......

Dear Thank U for your code... but that code is not of use for my project.... first because i dont understand the code and your code is very lengthy and also extra code is given which is waste of memory.

I thought some one can help me here to learn something.

#### Tahmid

Hi,
I see a few problems. I use mikroC and don't use PICC much, but try with this:
Code:
#use delay(clock=10000000)
int16 temp, cent;
int16 triptemp, TripTempc=40;
void main()
{
TRISA = 0x01;
TRISD = 0; //You haven't specified buzzer output
triptemp = (TripTempC*500)/1023; //This should be how it is. First dividing by 1023 makes the result always equal 0
while(1)
{

cent=(temp*500)/1023; //Same mistake here

if(cent>triptemp)
{
output_high(PIN_D0); //What's 53?, Try with PIN_D0 (I assume this is where buzzer is connected)
}
else
{
output_low(PIN_D0); //Same here
}
delay_ms(100);

}
}
Hope this helps.
Tahmid.

Status
Not open for further replies.