Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Little help with a math formula for a temperature sensor on a pic

Status
Not open for further replies.

bigal_scorpio

Active Member
Hi to all,

I am building a PSU with a temperature sensor using a pic 16F872.

The sensor is one salveged from a computer and is just a simple analog bi metallic strip that goes from 1k ohm at 100c to 60k at 0c.

I have used a voltage divider to get the voltage on the pic ADC to be 4.54 at 100c and 0.714 at 0c. If I then read the value from the ADC channel I get 131 at 0c and 454 at 100c.

This is where I am falling down. I can't figure out the formula to convert the pics reading into centigrade.

I thought it would be 454-131 = 323 then divided by 100 = 3.23 per degree c but it seems to be about 3c out (too high) at that.

Does anyone know what I'm doing wrong please

Al
 
it seems to be about 3c out (too high) at that.
The sensor resistance may not vary linearly with temperature. Are you assuming it does? The measurements at 0 and 100 are known, but is it an intermediate measurement which is '3c out' ?
 
Hi Alec,

Yes it its reading about 21degrees at what should be 17ish (in my shed) according to 2 different thermometers.

So if it was linear would my math be right?

Al
 
The sensor is one salveged from a computer and is just a simple analog bi metallic strip that goes from 1k ohm at 100c to 60k at 0c.
That sounds like an odd temperature sensor, any chance of a picture?

If you are using just a simple voltage divider with your variable resistance sensor and a fixed resistor, the voltage out from the junction of the two resistors will tend to be non-linear anyway.

I have used a voltage divider to get the voltage on the pic ADC to be 4.54 at 100c and 0.714 at 0c. If I then read the value from the ADC channel I get 131 at 0c and 454 at 100c.
Something does not sound right here.
What is the reference voltage of the ADC? I assume 5 volts.
And I assume that the ADC input is scaled 0 to 5 volts.

Depending on the precision (number of bits) you are using in the ADC, I would expect 4.54 volts to convert to either 232 (8 bits) or 929 (10bits).
And 0.714 volts converts to 36 or 146 bits.

Admittedly I am making some big assumptions about your circuit, but something seems very wrong here.

JimB
 
Last edited:
As pointed out by Jim, those values are very low. One possible explanation is that the pin has somehow been configured as an output and is pulling the reading low. I know this because I did the same thing many years ago and it took a while to work out why it wasn't linear.

Mike.
 
That's a thermistor sensor that will be very non-linear.

If you want reasonable accuracy you could spend a couple dollars on a LM35 that gives a linear voltage output per degree C. :)

Otherwise you have the annoying task of measuring the thermistor sensor, charting and generating some lookup table for it, and still risk getting reduced accuracy in the final device.
 
another alternative is a DS1820 digital sensor and


' Read Sensor 1 #######################################################################################
OWOUT Sensor1, 1, [$CC,$44] ' Skip ROM search & do temp conversion
Pause 1000
OWOUT Sensor1, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
OWIN Sensor1, 2, [R_Temp1_last.Lowbyte, R_Temp1_last.Highbyte]' Read two bytes / end comms
'------------------------------------------------------------------------------------------------------
 
Hi Guys,

Picture as Jim requested.

I am also taking all other comments into consideration. I used this simply because I have had a few in my box for ages and wondered if they would work.

I am interesed if anyone knows exactly what these are.

PS dupont connector is shown for scale .

Al
 
Last edited:
Looks like an embedded small conventional thermistor. What makes you think it's 'bi-metallic'?
 
Picture as Jim requested.
As others have said, that looks like a thermistor.

As an inspired guess, is your temperature measuring circuit like my attached sketch?

JimB


On edit:
There is a way of "linearising" such a set-up, but the downside is that the output voltage is very much reduced.
 
Last edited:
It’s easier to make a linear reading by the use of a look up table.
Firstly you need to measure the output voltages on your sensor with an absolute temp sensor.

If you planning to do without using lookups then I'd simply see the lowest limit. In other words I scale down the lowest limit to zero.

That is 0.714 volts = 146 bits (10bit).

I subtract 146 from every 10bit new readings & do the calculations.

Your maximum reading will be 454-146=308 @ 100'C

If you get ADresult = (150 – 146 ) = 4

Then your temperature will be

(100/308)*4
=1.2C
 
Last edited:
If you're planning to measure temperature over only a limited range, say, 15-25°C, then rather than calibrate the sensor at 0° and 100° it would be better to calibrate at 15° and 25°. Over such a limited range you may get away with assuming resistance varies linearly, depending how accurate a result you need.
 
This pdf shows how to linearise a thermistor.
 
Hi Guys,

Well I didn't think there would be so much to using one of these. I will probably go with the DS18B20 as I do have one somewhere.

I always come up with these Ideas that sound simple but are usualy anything but! Doh!

Eric, any progress on the current sense test?

Al

PS does anyone want some computer sensors free of course?
 
Last edited:
Hi Guys,

Well I didn't think there would be so much to using one of these. I will probably go with the DS18B20 as I do have one somewhere.

I always come up with these Ideas that sound simple but are usualy anything but! Doh!

Eric, any progress on the current sense test?

Al

Hi Al,
I replied to that thread this morning.?

Eric
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top