Thermistor based temperature sensor.

gamesguru

Member
Hello all,
I was wondering what would be the best way to approach such a problem, currently I have a thermistor (not very high quality) and a PICAXE 08M, it would be nice to be able to display the information on a series of 7 - segment displays and perhaps eventually on an LCD display. If someone could list some approaches with a detailed good/bad anaylsis it would be most helpful.

Thanks
 

Andrew Cowan

Senior Member
Welcome to the forum!


Calibrate it, and you're fine.

However, it would be much simpler to use a digital thermometer (eg DS18B20 and the readtemp command).

Thermistor:
Cheap
Needs calibrating
Can handle a large temperature range (although not linear forever)

Digital thermometer:
Free (as a free sample from maxim)
Expensive (if you need lots, a few quid each)
Simple to use
Range is OK (-55 to 150, I think)
Easy to interface with a PICAXE

Look up the readtemp command in manual 2.

A
 

BeanieBots

Moderator
Agree with Andrew.
Thermisters are not linear so you will need to build a lookup table or complex equation to convert what you read into what you want to display.

The first thing to do is to use debug/sertxd to get a range of values read for a range of temperatures. Especially the max and min temperatures you are expecting to see. Then explore the method required to convert those numbers into values for display.
 

gamesguru

Member
Thanks, its the calibration thats the issue though, could you recommend an easy way of doing it? The only way I can see of doing it is to use the Steinhart-hart equation or B-parametric equation to calculate a set of values and store it in an EEPROM and make it work like that? Is that what you mean or am I missing an easier method.

Oh, and thatnks for the digital temperature sensor suggestion but I want to do it with a thermistor :D.

The maths is an issue too, I've already tried doing with it with only the components listed in the OP however the Exponetial function, Log does not seem to be supported in the programming language and so I've hit a rock with that approach, could anyone enlighten me?

Cheers
 
Last edited:

BeanieBots

Moderator
If you can calculate the required equation then no need for EEPROM lookup.
However, I doubt reality will bear much relationship to theoretical values.

The only reliable option is to measure the ADC values (AFTER RESISTOR SELECTION) at an assorment of temperatures to ensure you have enough data to cover the non-linearities, then extrapolate for intermediate values once commissioned.

EDIT:
After your edit, you can either look for a solution using series approximations or stick with a table and extrapolation. I'd go for the latter.
First step is a calibration curve. You can't do ANYTHING without that.
 
Last edited:

Dippy

Moderator
Stein-hart will be a struggle on PICAXE ;)
However, it can produce very good performance.

Tables or lookups are the practical way to go. But a lot depends on your desired accuracy/resolution.
Combined with manual calibration using a 'decent' thermometer.

The LM35 is a cheaper option than DS18B20 - which is good but pricey and slow.

Do you want to use thermistor simply because you have one?
Depends if you think several days of your time is worth 3 quid.
 

Andrew Cowan

Senior Member
Code:
main:
readadc 1,b1   'store the reading in b1
if b1<b2 then   'is this the lowest value ever?
b2=b1
endif
debug b2      'send the reading to the PC
goto main
Then, put it in the fridge and wait for it to cool. Remove, plug into PC and read the reading of b2. That represents 4 degrees C (or whatever your fridge is).

Then replace if b1<b2 then 'lowest value ever? with if b1>b2 then 'highest value ever? and measure the temperature of hot things (eg boiling water = 100 degrees C, warm water = (measure with thermometer)...

You need to collect a range of values, then you can build the equation, or create a lookup table. If you have the datasheet for your thermistor, it may have an equation or graph, in which case you could use that.

A
 

gamesguru

Member
Thanks, I don't quite understand what you mean, I think you are suggesting for me to measure the resistance of the thermistor at different temperatures and write an if then program to display temperature values at differnt resistances? Well first sorry if I haven't gotten the concept and I don't have a thermometer to measure temperatures, so I might have to rely on manufacturer datasheets.

The datasheet is not very specific it doesn't provide a lot of useful information, and I'm using a thermistor because its relatively more difficult then using a Digital temperature sensor and I like a challenge. Higher marks :D. What do you mean by a formula?

Cheers
 
Last edited:

BeanieBots

Moderator
What is the REAL task here?
Is this homework aimed to test your understanding of data manipulation or do you want to make a calibrated thermometer?

EDIT: You get marks for demonstrating that you understand and have taken "factors" into consideration.

EDIT2:
What do you mean by a formula?
A formula is something you take when it all gets too much and you have a headache.
Suggest you use an equation once you have some data to work with or use a lookup table.

If your datasheet doesn't give a graph of resistance vs temperature and you don't have a thermometer to calibrate against, then it's even easier. You can't do it!
(you could do ice and boiling point but nothing else)
 
Last edited:

gamesguru

Member
I want to make a calibrated thermometer that produces accurate measurements with the equipment I have available, I might use it in my project for GCSE if it works well.
 

gamesguru

Member
Actually it is possible to calculate resistance vs temperature with the B parameter equation, however I don't understand how you can make a formula out of the values, only interger values are accepted. Enlighten me.

Thanks

Edit: Where do you store the curve? Presumably it is a lookup table, given that we only have a limited number of storage.
 

BeanieBots

Moderator
You can store the lookup table in EEPROM.
You could use breakpoints using Select/case.
Which PICAXE do you intend to use?

Perhaps you would like to enlighten us with your "B parameter equation"?
Either that, or post a link to your datasheet. I can't quite see from here!
 

hippy

Ex-Staff (retired)
You could use a thermistor and a DS18B20 and calibrate it that way; take it through the temperature range and see what each gives at various points. Discard the DS18B20 once calibrated. That's what I'd do (*) to avoid reading any data sheets or worrying over what the theory should be which may not be what you see in practice, and you need some reference to calibrate against anyway. This way the table can be created automatically.

The calibration will only be as accurate as the DS18B20 which I recall is +/-0.5C but I think there are techniques which can improve on that.

(*) Not entirely true as to what I'd actually do, as I'd use the DS18B20, simply connect it up and off I go.
 
Last edited:

Andrew Cowan

Senior Member
However, you don't know any of the parameters for the B parameter equation. All you know is the resistance at 25 degrees C.

If you want to calibrate it, connect it to a PICAXE, put it in a beaker of boiling water (insulate the leads), and put a thermometer in the water.

Connect the PICAXE to a computer, and every 5 minutes, write down the water temperature and the ReadADC reading. Draw a graph of temp vs ADC reading, then either determine a line of best fit and thus an equation, using y=(gradient)(ADC reading)+(Y intersect). That assumes it is linear - if it is not, it gets alot more complex.

To get full marks at GCSE, you need several systems.

EG:
Input (DS18B20).
Process (working out what LEDs to turn on), and is it over limit.
Output (7 segment LED displays).
Output2 (Alarm if too hot/cold)

That should get you full marks if you do it neatly and write it up well. Not a guarentee!

A
 
Last edited:

gamesguru

Member
However, you don't know any of the parameters for the B parameter equation. All you know is the resistance at 25 degrees C.

If you want to calibrate it, connect it to a PICAXE, put it in a beaker of boiling water (insulate the leads), and put a thermometer in the water.

Connect the PICAXE to a computer, and every 5 minutes, write down the water temperature and the ReadADC reading. Draw a graph of temp vs ADC reading, then either determine a line of best fit and thus an equation, using y=(gradient)(ADC reading)+(Y intersect). That assumes it is linear - if it is not, it gets alot more complex.

To get full marks at GCSE, you need several systems.

EG:
Input (DS18B20).
Process (working out what LEDs to turn on), and is it over limit.
Output (7 segment LED displays).
Output2 (Alarm if too hot/cold)

That should get you full marks if you do it neatly and write it up well. Not a guarentee!

A
Actually in the further technical specifications in the rapid electronic link I think it provides the parameters

Thanks everyone I think that its probably not possible to do with what I have, however could someone explain to me in more detail how I would calibrate the thermistor if I had a thermometer and I probably would like to avoid using an EEPROM.

Thanks again.

EDIT: Actually thanks Andrew, but if I get non-interger values how do I compensate for that and also I would like to compensate for the thermistors non-linear properties. The readings must be accurate, I think a linear approach would be to crude to be of any real use.
 
Last edited:

Andrew Cowan

Senior Member
If you can find the parameters and get it working, then go for it.

To compensate for non linear values, I would multiply numbers by 100. A word variable can store a maximum of 65535.

Eg:
0 = 0
655.35 = 65535
14.61 = 1461
5.3 = 530
etc

That means you can happily use non integer numbers in your calculations.

A
 

BeanieBots

Moderator
Given that this is at GCSE level, I think trying to get an equation working with integer maths might be too much.
There are methods such as Taylor's theorem to help with log functions.
Scaling log functions can be done, but it requires a very good understanding. It would be pointless to simply you GIVE you an answer and to explain it all would simply be too much.
http://en.wikipedia.org/wiki/Taylor's_theorem

That leaves you with using a lookup table.
To generate the lookup table, calculate the values using a calculator and then scale accordingly.
IMHO, you are better off doing it by experiment as described by Andrew.
 

Andrew Cowan

Senior Member
I had a similar situation that involved natuaral logarithms to 4 decimal places.

As there were only about 20 values it could be, I just used a lookup table (scaled up).

Crude, but it works.

Just order a free DS18B20, though! You can still get full marks!

A
 

BeanieBots

Moderator
Just sticking with 8-bit integer gives 'adjustments' of:-
254/255=0.996 and 255/254=1.004 ! (~0.4%)
We are talking about temperature and thermisters here.
ONE decimal place is an optimistic accuracy.
Using words you calculate CALCULATE the temperature to the nearest 0.001C with an accuracy of something like +/- 1C:rolleyes:
 

gamesguru

Member
Right, well it doesn't seem to be worth the effort to do this now since I don't have EEPROMs on hand, might as well use a digital temperature sensor. :D
 

papaof2

Senior Member
Right, well it doesn't seem to be worth the effort to do this now since I don't have EEPROMs on hand, might as well use a digital temperature sensor. :D
If you choose the right PICAXE, you can use the EEPROM on the PICAXE itself.

John
 

manuka

Senior Member
and I don't have a thermometer to measure temperatures
Gamesguru: Splutter-I'm near incredulous -did I read this correctly ? NO thermometers at all ? Not even a coin shop offering? Even elementary school kids know & use thermometers. GET ONE PRONTO!

Given this insight I ponder your "accuracy" quest. What is it exactly that you're measuring the temp. of - it's not simply your games PC CPU is it? What temp. range is likely? How were you intending to calibrate against known standards? Thermometer calibration- especially over a significant temp. range- is an immensely technical & costly quest. Here in NZ standards lab. charge US$500 for this, but stand by their calibration charts should legal queries arise-food shipments etc.

At a poor mans level, & aside from the obvious sea level 0°C water freezing & 100°C boiling, the M.Pt determinations of pure substances can assist in calibration. All manner of household pantry goodies can be be used for this -pure sucrose (sugar) melts at 186°C, coconut oil at 26°C, paraffin wax ~ 55°C, beeswax ~62°C. Hours of fun,but don't let any catch fire of course- use a water bath.

Dissolved salts cause a FP depression/BP elevation & the technique has long been used for determining concentrations. Common salt (Sodium Chloride - NaCl) can lower FP temps by at least 9°C. Hence you could use it in reverse, as known solute concentrations should cause freezing at specific temps.

Many forum regulars well know I've thermometers galore (traditional LIG, electrical & electronic), but for educational & modest technical PICAXE use I consider the versatile DS18B20 the obvious choice. It comes in a "BC547" style TO-92 case, with accuracy ±0.5 °C, & has user configurable resolution up to 12 bits (=0.0625°C). Temperatures from -55°C to +125°C can be measured, with ±0.5°C accuracy from -10°C to +85°C. Of course at ~US$3, it's not as cheap as diode/thermistor/thermocouple approaches, but it's PRODUCTIVE!

Why hence, & echoing postings of others, are you not using the industry standard DS18B20 !?
 

Attachments

Last edited:

Dippy

Moderator
How do you connect that red-topped temperature sensor Stan? Is it one-wire?

I believe they light up when they get to a certain temperature, but I can't find a Data Sheet.
 

manuka

Senior Member
Matchless spotting Dippy. "Down under" they're known as Scavenger Powered One Time Self Illuminators (SPOTSI)-100 up quantity orders however. The seasonal warmth means my use for them has declined & hence I've a stash on hand. Swap SPOTSIs 1:1 with DS18B20s anyone?
 

Andrew Cowan

Senior Member
All PICAXEs do - just different amounts.

Look at the EEPROM command in manual 2 for prestoring data, and READ and WRITE commands for writing to EEPROM 'on the fly'.

A
 
Last edited:

Dippy

Moderator
In addition, read Manual 2 (BASIC Language) "Write" and "Read" commands to see a info about EEPROM use.
Whilst those sections the Manual doesn't explicitly say it's talking about EEPROM note that it is.
Using the X parts is safest and requires least thought/planning.



Thanks for the Safety Sheet Andrew. I couldn't see a value for maximum voltage so I'll phone the Energency Number :)



Oh Stan, you must know the one about showing people how a match can burn twice ?
 

BeanieBots

Moderator
You can also have the table in your code as mentioned earlier.
The method is called 'break points' where you apply a different gain (or formula or equation or whatever you want to call it) to your reading depending on what the value is. Break the curve down into a series of straight lines.
see SELECT/CASE.
 

gamesguru

Member
But how is it possible to break down the curve when its not even plotable, I'm missing the point, what do you mean? Would it be possible to put in the whole lookup table in a PICAXE because that would seem to be a hard task.
 

Andrew Cowan

Senior Member
Plot the curve. Instead of drawing one 'line of best fit', draw several (one for each part of the curve). Each line has an equation... etc.

So -20 to 0 degrees might follow equation one, 1 to 20 degrees might follow equation two...

A
 
Top