Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
This is a simple project showing you how to read LM35 [http://www.ti.com/lit/ds/symlink/lm35.pdf] analog temperature sensor using a PIC microcontroller and to switch a certain load at a certain temperature.
Software in use:
CCS PIC-C Compiler Labcenter Proteus VSM
http://blog.ghatasheh.com/2012/01/pic16f877a-and-lm35-based-temperature.html
1/7
4/7/2014
[http://2.bp.blogspot.com/-8xC4RgF8scM/TxlLYKaSFaI/AAAAAAAAACk/7FODBf0jvRo/s1600/Schematic.png]
T h e
C-Code:
/ /l o a ds w i t c h i n gt h r e s h o l di nC e l s i u s
i n t 1 6d i g i t a l _ r e a d i n g ; / /A D Cr e s o l u t i o ni s1 0 B i t ,a n8 B i ti n t e g e ri sn o te n o u g ht oh o l dt h e r e a d i n g f l o a tt e m p ; v o i dm a i n ( ) {
http://blog.ghatasheh.com/2012/01/pic16f877a-and-lm35-based-temperature.html 2/7
4/7/2014
/ *A D CI n i t i a l i z a t i o n* / s e t u p _ a d c ( A D C _ C L O C K _ I N T E R N A L ) ;/ /i n i t i a l i z eA D Cw i t has a m p l i n gr a t eo fC r y s t a l / 4M H z s e t u p _ a d c _ p o r t s ( R A 0 _ A N A L O G ) ; / /s e tP I N _ A 0a sa n a l o gi n p u tc h a n n e l s e t _ a d c _ c h a n n e l ( 0 ) ; / /p o i n tA D Ct oc h a n n e l0f o rA D Cr e a d i n g d e l a y _ m s ( 1 ) ; / /A D Cm o d u l ei ss l o w ,n e e d ss o m et i m et oa d j u s t . / *P e r i p h e r a l sC o n f i g u r a t i o n s* / l c d _ i n i t ( ) ; / /T u r nL C DO N ,a l o n gw i t ho t h e ri n i t i a l i z a t i o nc o m m a n d s o u t p u t _ l o w ( L O A D ) ; / /t h el o a di si n i t i a l l yO F F l c d _ g o t o x y ( 1 , 1 ) ; / /p o i n tL C Dc u r s o rt oc o l 1r o w 1 l c d _ p u t c ( " T e m p e r a t u r ei s : " ) ; / /p r i n to nL C D w h i l e ( 1 )/ /i n f i n i t el o o p { d i g i t a l _ r e a d i n g=r e a d _ a d c ( ) ; / /c a p t u r ec u r r e n tt e m p e r a t u r er e a d i n g d e l a y _ u s ( 1 0 0 ) ; / /0 . 1 m sd e l a yf o rA D Cs t a b i l i z a t i o n t e m p=d i g i t a l _ r e a d i n g*0 . 4 8 8 3 ;/ /c o n v e r tr e a d i n gt oC e l s i u s l c d _ g o t o x y ( 1 , 2 ) ; / /p o i n tL C Dc u r s o rt oc o l 1r o w 2 p r i n t f ( l c d _ p u t c , " % 2 . 1 fC " , t e m p ) ;/ /p r i n tv a l u eo nL C D i f ( t e m p > = T H R E S ) o u t p u t _ h i g h ( L O A D ) ; e l s e o u t p u t _ l o w ( L O A D ) ; d e l a y _ m s ( 1 0 0 0 ) ; } } / /C o n t r o lL o a d
/ /1s e c o n dd e l a yb e t w e e nr e a d i n g s
For any questions, do not hesitate to ask :) Badr Ghatasheh 079@live.it [mailto:079@live.it] Posted 20th January 2012 by Badr Ghatasheh Labels: ADC, CCS, LM35, PIC
66
View comments
65 comments
Top comments
http://blog.ghatasheh.com/2012/01/pic16f877a-and-lm35-based-temperature.html
3/7
4/7/2014
hasan AL-omari 5 months ago - Shared publicly can you upload the proteus file ?
1 Reply
Kaiser Mili 4 months ago mmmmmmm neil paloma 2 months ago can you also send me the proteus file or hex file? thanks, nepal_300@yahoo.com
neil paloma 3 months ago - Shared publicly is it possible to send the read data to the mobile phone? and put condition if the temperature exceeds the limit the device will automatically update to the mobile phone... thank you.. :)
1 Reply
View all 6 replies Adison Mhanna 2 months ago Well yes it is simple. But u should know which module you want to use. You are welcome at any time neil paloma 2 months ago can you send me your code about the project you made with this sensor and pic? if it is ok? thanks.. :)
jen taiji 5 months ago please also send me hex file in jentaiji@gmail.com
jen taiji 5 months ago please also send me hex file in shougiyen@yahoo.com
Wanderley Silva 6 months ago hello badr , just saying that i am one more person who build this circuit with great success , congratulations for your job and patience with the newbies . i made some changes to add a 20x4 lcd and add 4 dvm for use it in my test jig from amplifiers ,, really very helpful
4/7
4/7/2014
Dude, please send the components required,coding and schematic design for PIC16F877A and LM35 Based Temperature Monitor My mail id is: mail2vicky.7@gmail.com Urgent dude ....Please send it!!!!!!!!!!
Badr Ghatasheh 8 months ago Although it's posted, you just need to read it, dude! :) Adison Mhanna 8 months ago i did send it to u
Adison Mhanna 8 months ago here is the code I am using: #include <16F877A.h> #fuses XT,NOLVP,NOWDT,NOPROTECT #use delay(clock=4000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) void main() { int16 digital_reading; float temp; setup_adc(ADC_CLOCK_INTERNAL); setup_adc_ports(RA0_ANALOG); set_adc_channel(0); delay_ms(500); printf("setup done\n"); output_high(PIN_C3); while(1){ digital_reading = read_adc(); delay_us(100); temp = digital_reading * 0.4883; printf("%2.1f C\n",temp); delay_ms(1000); output_toggle(pin_c3); } } Badr Ghatasheh 8 months ago Just set the ADC resolution to 10 bits, add this "#device adc=10" to the second line of your code.
Adison Mhanna 8 months ago Mr. Badr, very good job. Yet I am working on a similar project, but instead of displaying the temperature value on the LCD, I am sending it to the PC using MAX232 and serial port to save it on a database for logging purpose. I have a problem that I am getting wrong and different values. here is an example of some values that I am getting: 3.4 C 10.2 C 9.7 C 7.8 C 8.3 C 7.8 C 8.7 C 9.2 C 10.7 C 8.7 C 5.3 C 8.7 C can you tell me what might I doing wrong? I can send you the code with the diagram that I am using, but I don't know where to post them. thank you Badr Ghatasheh 8 months ago Email the code to badr.ghatasheh@gmail.com
sabrine 11 months ago please i just want to know what is the function of : relay,diode,resistor2,transistor? i compiled the program without those devices and it works.
Badr Ghatasheh 8 months ago It's simply a load that gets switched ON/OFF on a certain temperature threshold.
Anonymous 1 year ago Sorry! I need to connect 4 temperature sensors LM35, and looking the temperatures separatly with a switch buttons at 100m of wire (the LM35 is instaled in greenhouses). How it I make?
5/7
4/7/2014
Leo Sotto 1 year ago hi please send me the hex code for this program because it can't run on my css it said "Lcd.c fle cannot found
Badr Ghatasheh 1 year ago This is a formatting string, 2.1 means two digits before the decimal point and ine after it (00.0), f means float, and C will be printed as is
Anonymous 1 year ago what does this command mean? "%2.1f C"..thanks for your answer.
student 1 year ago do you have the codes for a price computing digital weighing scale? i am also using a pic16f877a.. please help :| thanks.
Anonymous 1 year ago Hi,can the circuit drives a 12V relay? For that , i need to change my power supply? But problem is the ic can only take 5VDC right? please help. Thanks.
Badr Ghatasheh 1 year ago Thats why they sell 5V relays! Why use a 12v relay when you can use a 5v one?
Momen Elwan 1 year ago hi badr i wanna use pic16f877a and i want to write with MicroC Pro ... can u help me on the Lm35 and how can i read it and convert the data to the pic and display it on lm016 lcd ??
Badr Ghatasheh 1 year ago Am not that familiar with MikroC, I myself used CCS compiler. What I can say is that the logic behind both is the same, understand how to do it in CCS it wouldn't be hard to migrate the code to MikroC.
Anonymous 1 year ago Hi,can the circuit drives a 12V relay? For that , i need to change my power supply? But problem is the ic can only take 5VDC right? please help. Thanks.
http://blog.ghatasheh.com/2012/01/pic16f877a-and-lm35-based-temperature.html 6/7
4/7/2014
Anonymous 1 year ago can you tell me how to compile the code , what do i need to run the code and connect it to the design ? sorry but i'm new to this, so i need help thanks
Show more
http://blog.ghatasheh.com/2012/01/pic16f877a-and-lm35-based-temperature.html
7/7