Using a table

I want to use a table to print out the exact temperature reading relevant to the reading of a thermister connected to say analogue 1.

My thoughts are that I calibrate the thermister in hot water and with the actual readings from analogue 1 and a separate thermometer should end up with a table something like this (actual values are irrelevant just an example)

Reading 340 Temp 20c Reading 400 temp 25c Reading 421 temp 26c reading 460 temp 30c reading 520 temp 40c

can anyone help me with the sketch to set up this table then read analogue1 and use its reading, say 400 to output to serial the value 25c.???

I am still new to this but doing quite well so far. regards john :-/ :-/ Though this assumes a linear relationship.

Remember, a table could need up to 1024 entries, unless you divided the range down first.

Thanks mate. I will have a look at the link.

i am only interested in a small temp range which from memory was about 300 to about 900 (analogue1 input) that's about 30c to 90c and I do not need to be that accurate maybe 1 or 2 degrees C.

Its just so that I can get an idea of just how hot my BIO is during the process. Thanks John :D :D :D

Just had a look at the link. Can I just ask if you think I have understood it.

It is taking 0 to 1023 and mapping it to 0 to 255. After reading analogue (0) it is taking the read value (val) converting it and calling it (val) and outputting it to pin 9 as another analogue value between 0 to 255.

So if my range were say 300 to 900 equating to 20c to 90c ( it would be fairly linear over this range) then my analogue output value would be somewhere between 20 to 90c.

Presumably instead of analogue writing this to an output I could send this value (val) to the serial port. I could also use this value in my calculations for telling the sketch when my oil is at a certain temp.

If my understanding is correct that is brillient, I didn't think it would be so easy, a lot easier than plotting all the values between 300 to 900 (20 to 90) as I would have to do in a table

John ;D :D ;D

If the data read from the sensor is in the range 300 to 900, and you know that the range represents 20 to 90 degrees, you would use map like this:

int sensorVal = analogRead(sensorPin); int tempVal = map(sensorVal, 300, 900, 20, 90);

You can write tempVal to the serial monitor, or take action base on it (turn a heater on or off, or a fan).

It is taking 0 to 1023 and mapping it to 0 to 255]

It's just an example of mapping one range (0..1023) to another (0..255) - the key thing is the "map" function. You can specify any values you like (even negative ones), though the function is limited to integer values. I think there's a similar floating-point version somewhere where can can specify linearity.


Thanks guy's Just spent most of the afternoon with a cup of scolding hot water and a thermometer.

I used the script in the first link and added serialprint commands after the first (val) definition and also after the conversion.

It works quite well, I seem to have fluctuations on the analogue read which I thought might be due to a noisy 5volt so I connected the thermister to the 3v... didn't make much difference but its not a real problem and really 90c and 50c are my two main points, if they are reasonably close the other readings are just for show

I just need to wait for a cup of water to freeze in the deep freeze then I can set my lower value more accurately

Thanks again guy's John ;D ;D ;D

PS the fscale command was too complicated for me... but thanks anyway....

Hi Guy's I just thought I would update you on my progress.

I found that because of non linearity of the thermister, if I set the max and min at freezing and boiling my main points (50c and 90c) were wildly out (90 wasn't bad cuz thats near boiling) but if I set max at 90 and min at 50 those two points worked out well and I still get readings outside these points which are reasonable and useful for my purpose. They don't go off too far until temp gets down to about 20c which I am not interested in.

Good job done.... Thanks..... John ;D ;D ;D

This sounds like why I started using Dallas DS1820s for temperature measurement.

I got fed up with trying to get meaningful readings from thermistors. :)

Luckily I don't need too much accuracy just close. John :D :D