Claim Your: Useful

"Arduino Software Guide"

   Right Now...



Back 12F675 Tutorial Index Next

12F675 Tutorial 4 : Making an LM35 temperature recorder.

Measuring temperature is easy using an LM35. This page shows you how you can make an LM35 an temperature recorder by using the 12F675 PIC microcontroller as the controller and data store.

It generates serial output so that you can view the results on a PC and it also calculates the temperature reading in Fahrenheit sending both to the serial port at half second intervals.

The project uses the code from the previous tutorials to report the temperature to the PC using the serial port so the serial RS232 data format is generated in software.



Jump to circuit.
Jump to 
Solderless breadboard.
Jump to Circuit Diagram.
Jump to Software.

LM35DZ

The LM35  is a precision temperature sensor.  It is guaranteed accurate to ±¼°Cat 25°C (At different temperatures it is less accurate! but it is never more than 2°C inaccurate and it probably is not this inaccurate anyway it's just the manufacturers maximum limits that may apply).

Typically is stays accurate to within 
±¾°C over its temperature range so this is a good general purpose sensor and it's easy to use.

It generates a linear output voltage using a centigrade scale - generating 10mV of output voltage for every degree centigrade change and there are several versions for operation over different temperature ranges:

LM35 -55°Cto 150°C
LM35C -40°Cto 110°C
LM35D 0°Cto 100°C

Note: The project code calculates the temperature in Fahrenheit and generates both Centigrade and 
Fahrenheit outputs to the serial port.

Temperature recorder : LM35 pinout

Temperature recorder : pinout for theLM35DZ (from the top).

LM35DZ pinout

Temperature recorder Circuit

The LM35 is connected to analogue input AN0 which is also the data input line for programming the 12F675 using ICSP so you need a way of connecting the sensor and the programming input at the same time with the programming input overriding the sensor output (and not damaging the sensor!).  

This is done here by using 1k resistor that reduces the current flowing back into the sensor and at the same time is not too large (so that the ADC can easily convert the sensor output value - the impedance must be equal to or smaller than 10k Ohm from the sensor).

The voltage reference for the circuit is taken from pin 6 using a resistor divider giving a 2.5V reference.  This is simply done to increase the resolution of the ADC as for the LM35 only 0-1V is generated so you loose ADC range when using a 5V reference.  You could use a lower reference value but this value gives reasonable results.

Alternatively you could use an amplifier to scale the LM35 output up which would make the ADC less sensitive to noise but for this project it is simpler not to do so.

Note: The large decoupling capacitor on the supply input of the 12F675. This reduces noise overall and gives a more consistent reading.  However using a  plug block and ADC is not a very good idea as there is no ground plane and no control over current paths which you would be able control in a pcb.

In a commercial system the internal ADC is often not used at all as it is essential to separate the noise introduced to the ADC using separate grounds and shielding - some designs encase the ADC in a custom metal shield and along with a ground plane connecting to the shield gives the best possible result.

To overcome noise problems on the ADC the software averages the input readings so you get a better result.

Solderless breadboard

Add the components (at top right to) the temperature recorder - wires and R3,R4,R5 and the LM35 temperature sensor (U4) and the decoupling capacitor C4.

temperature recorder plugblock

Learn about the tool used for creating this diagram.

LM35 Temperature Recorder Circuit diagram

temperature recorder


Learn about the tool used for creating this diagram.

Temperature recorder measurement accuracy

The analogue reference for the ADC is taken from the power supply via a resistive divider to the 12F675 input pin 6 and for the 7805 its accuracy is specified as ±5% so the accuracy of the ADC is only 5% due to the reference -the divider also introduces a 1% error giving a 6% error overall.

Note: Since the 7805 is only accurate to ±5% the accuracy of the temperature reading will be accurate to ±5% (plus errors in the ADC and temperature sensor itself and any noise introduced the the analogue input and the reference). However the reference source gives you the biggest error - the overriding accuracy - if you used a more accurate voltage supply then the ADC accuracy would become more important as well as the temperature sensor accuracy etc.

Temperature recorder Software

The software uses the Soft USART (transmit only) described in the previous tutorial and uses the built in MikroC routines to get the data from analogue input pin AN0.

Source code files :
To get the file software project files and c source code click here.

// Temperature recorder analogue input

val = ADC_Read(0);

// more code adds up 10 readings of ADC

val = ((val/MAX_AVG)*122)/50;

// Convert to Fahrenheit x 5/9 (1.8) (scaled)=18
// add 32 scaled to 3 digits =320

val = ((val*18)/10)+320;

Software operation

The most interesting parts of the software are shown above. The variable val is an unsigned int so the maximum value it can store is 65535

The reference in use is 2.5V so for the 10bit ADC each ADC bit is worth

2.5/1023 = 2.44mV

If you work out values generated for a maximum temperature of 100
°C using the scale factor 2.44mV (or 244/100)

100 * 10mV = 1.0V

1.0V/2.44mV = 410

410 * 244 = 100,040 which will not fit into an unsigned int.

So this scale factor does not work for all input values

By using a little maths it can be made to fit -you need to reduce the top number to fit. e.g.

410 * 122 = 50,020 which does fit.

Dividing by 50 gets back to the correct scale factor of 244.

So the scale 122/50 works for all input values.

This is an example of avoiding the use of floating point variables which take up too much resources.  You can still make the system work but you have to be careful when using fixed types and you have to check all input values and outputs to make sure they fit.

Averaging

Averaging would be better done in the PC as it has more resources - the same goes for calculating and displaying the temperature in Fahrenheit but this gives a demonstration of what you can do.

Note: The RAM is used up since a bug in MikroC 5.0.0.3 puts strings int RAM - in future versions this will be corrected.

Typical output from the temperature recorder

   96 RAW   234 C   741 F

The left most value is the RAW ADC value, the next is the temperature sensor output in degrees centigrade and the next is the temperature sensor output in degrees Fahrenheit.  

Note: You have to put in the decimal point so the above readings are:

234 C 23.4°C
741 F 74.1°F


Back 12F675 Tutorial Index Next







Learn to program in C

in easy steps.

Essential & EASY:

PIC C Programming Course:

CLICK HERE.


Jump from 12F675 Tutorial 2 : LM35 Temperature recorder to
Best-Microcontroller-Projects Home Page


Privacy Policy | Contact | About Me

Site Map | Terms of Use | Links




Google

Recent Articles

  1. An Ultrasonic Distance meter project.

    Nov 25, 14 12:00 PM

    An PIC Ultrasonic Distance meter project using a PIC microcontroller which is ideal since it has a capture timer that can accurately measure the ultrasonic echo time, so calculating the distance is ea…

    Read more

  2. A dot matrix LED display project for an 8x8 or 5x7 led matrix.

    Nov 20, 14 04:58 AM

    How to drive a dot matrix LED display. This project shows you how to drive one with 64 LEDs (8 rows by 8 columns) or less e.g. 35 LEDs (7 rows by 5 columns).

    Read more

  3. USB Serial Port: How to setup an RS232 serial link through a USB port.

    Nov 20, 14 04:55 AM

    USB serial port: How to setup an RS232 serial link when you only have a USB port. There are two types of digital interfaces to consider...

    Read more

Custom Search

Sign up for MicroZine:
''The'' Microcontroller Newsletter


Enter your first Name and primary email address in the form below:

And receive absolutely FREE a full project for:


"Measuring Analogue Voltages
Without An ADC"

(Using only one pin).

Instant Download:
You Can
Get It Right Now

Warning: This project could be Removed
at any time.  

It will NOT be
available indefinitely SO

To avoid
disappointment get it:

Now



:
:
Don't worry -- your e-mail address is totally secure. I promise to use it only to send you MicroZine
Remember this is a project with full description and fully debugged C Source code - and it's not available from the main website.

You can only get it through this newsletter.


To get exclusive access Enter your first name Name and primary email address Now in the form above.:

But wait !

There's more...

You'll receive more
free and exclusive reports as well as site information and site product updates.

Scroll up to the form above and sign up NOW.  Don't forget it's FREE and if you don't like it you can unsubscribe at any time.

Click Here Now to use the form above to get your Valuable information absolutely free.



Social Bookmarking
Click & Add:
add to BlinkBlink
add to Del.icio.usDel.icio.us
add to DiggDigg
add to FurlFurl
add to GoogleGoogle
add to SimpySimpy
add to SpurlSpurl
Bookmark at TechnoratiTechnorati
add to YahooY! MyWeb
Readers comments

"I wanted to thank
you so so so much
for all the information
you have provided in
your site it's

SUPERB and FANTASTIC."


- Ranish Pottath


"This site really is
the best and my favorite.
I find here many useful
projects and tips."

- Milan

bursach<at>gmail.com

Learn PIC C Now
Wondering how to program your next project using C and need a great start?


"Awesome site,
very, very easy and nice
to navigate!"


- Matt
matt_tr<at>
wolf359.cjb.net


"I am a newbie to PIC
and I wanted to say
 how great your
site has been for me."


- Dave

de_scott<at>bellsouth.net

Learn Microcontrollers
"Interested in
Microcontrollers?"


Sign up for The
Free 7 day guide:

FREE GUIDE : CLICK HERE

"Your site is a great
and perfect work.
congratulations."


- Suresh

integratredinfosys<at>
yahoo.com

"I couldn't find the correct
words to define
yourweb site.

Very useful, uncovered,
honest and clear.

Thanks so much for
your time and works.
Regards."


- Anon