Function to convert sensor resistance to temperature

Please forgive the long and an apparent off-topic post, but I'm at my wits end trying to figure out a math function node.

I have a temperature/humidity sensor from MetOne Instruments that I'm trying to come up with a function node that would convert the sensor resistance to a temperature. It's been a LONG time since I've been in a math class so I'm hoping a math-savvy person can help me. The formula is below the chart which I've included for reference and checking against solutions derived by the equations. I was trying to include an image of the formulas from the sensor PDF but couldn't figure out how to do that, but where you see -1, that is actually the -1 exponent, or the reciprocal as in (Rt-1) is 1/Rt (at least from what I remember and what I've found on the web). But for the life of me I can't get the right temperature given the resistance, or even close. If I use 23663 ohms (60 degrees), when I solve for Tc it is nowhere near 23663. I'd LIKE to use the formula to get the temperature, but, since I only REALLY need is the sensor resistance from 0 to 100 degrees Fahrenheit, so maybe a lookup table? Suggestions? Thanks in advance.

Tc Rt Tc Rt Tc Rt °F Ohms °F Ohms °F Ohms

50 26801 78 18908 106 13171
51 26469 79 18672 107 12995
52 26140 80 18439 108 12821
53 25816 81 18208 109 12648
54 25497 82 17980 110 12477
55 25181 83 17754 111 12308
56 24870 84 17531 112 12140
57 24562 85 17310 113 11974
58 24259 86 17092 114 11809
59 23959 87 16876 115 11646
60 23663 88 16662 116 11484
61 23371 89 16451 117 11324
62 23082 90 16241 118 11165
63 22797 91 16034 119 11008
64 22516 92 15829 120 10853
65 22238 93 15627 121 10698
66 21963 94 15426 122 10545
67 21691 95 15227
68 21423 96 15031
69 21158 97 14836
70 20896 98 14644
71 20638 99 14453
72 20382 100 14265
73 20129 101 14078
74 19879 102 13893
75 19632 103 13710
76 19388 104 13528
77 19147 105 13349

Sensor Range = -58􀁱F to +122􀁱F (-50􀁱C to +50􀁱C)

Conversion Formulas:

Tc = (((Rt-1) + (23100-1))-1 – 13698.3) / (-129.163)
Rt = (((-129.163Tc) +13698.3)-1) – 23100-1)-1
Where: Tc = Temperature in degrees F
Rt = Sensor Resistance in Ohms

Can I just check that is the formula you are trying to evaluate. Are all the `-1` references actually raised to the power -1? So the formula is actually
Tc = (((Rt^-1) + (23100^-1))^-1 – 13698.3) / (-129.163)
Possibly it would be good to post a link to where we can see the formula written correctly or post a screenshot of the formula.

OK, I have worked it out. The formula is

``````Tc = (((Rt^-1) + (23100^-1))^-1 – 13698.3) / (-129.163)
``````

which gives you the temperature in Deg C (not F as you said). The Tc is a big clue. However the table you give is in Deg F. So 23663 ohms is 60 F. Here it is coded in javascript.

``````[{"id":"1caf4ac8.763d55","type":"inject","z":"5bb5a6a6.97527","name":"","topic":"","payload":"23663","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":682,"y":391,"wires":[["31737584.9b14d2"]]},{"id":"31737584.9b14d2","type":"function","z":"5bb5a6a6.97527","name":"Calc Temp C","func":"const rt = msg.payload\n// calc deg c\nmsg.payload = -(1/(1/rt + 1/23100) - 13698.3)/129.63\nreturn msg;","outputs":1,"noerr":0,"x":844,"y":391,"wires":[["c7a8c240.74c42","3d1baaf3.2190fe"]]},{"id":"c7a8c240.74c42","type":"debug","z":"5bb5a6a6.97527","name":"Deg C","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1019,"y":391,"wires":[]},{"id":"3d1baaf3.2190fe","type":"function","z":"5bb5a6a6.97527","name":"Convert to F","func":"// convert to F\nmsg.payload = msg.payload*9/5 + 32\nreturn msg;","outputs":1,"noerr":0,"x":872,"y":457,"wires":[["422892ad.08db14"]]},{"id":"422892ad.08db14","type":"debug","z":"5bb5a6a6.97527","name":"Deg F","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1027,"y":457,"wires":[]}]
``````
4 Likes

Have some stars for our math star!

Nicely done,
(and add in a Math.round(...) to make them integers as per OP). spot on.

I don't think it is a good idea to throw away accuracy like that, not in the function. If it is desired only to show it to the nearest integer then do that when it is displayed.

And likewise all those decimals give an unrealistic expectation of accuracy :-). I did just mean as the final step in the degF function. Which is as close to display as you get. ( unless you want to jsonata it in the debug node

It might be going to an influx database for all we know, in which case it should not be rounded before going in. Or perhaps it might be fed into a PID node for temperature control, in which case rounding before that would be a disaster. Many of the dashboard widgets allow rounding in the widget itself so do it there.

True. But only if the input measurement is 100% accurate. I suspect most measurements of resistance are no better than 1% error

Sorry, which bit do you mean is true, but only if ...

True = You are correct.

If you mean about the PID, the accuracy of the sensor is immaterial (apart from the obvious effect on the final control temperature). If the process value is rounded before going into the PID algorithm it messes it up and will prevent the fine adjustments necessary for good control. The Derivative is particularly badly affected as the value will not move smoothly between rounded values.
For example, this is a big problem using the DS18B20 temperature sensor for accurate control. Even if you calibrate the sensor the fact that the output has a resolution of 0.0625 degree C means that it is difficult to use Derivative effectively.

Wow, thanks Colin! I posted just to find someone with more smarts than me to fill in some blanks in my math knowledge, and BONUS, even got a function node to boot! So, let me say that I didn't even notice it before, but the formulas are the SAME for both conversions from/to Celsius and Fahrenheit. It's laughable because the only change between the formulas is one formula shows "Where: Tc = Temperature in C" and in the other (supposedly for Fahrenheit) it is: Where: Tc = Temperature in F" Somebody didn't proofread the document! So, rather than post links to the offending formulas, here they are pasted-in:

Celsius:
Conversion Formulas:
Tc = (((Rt-1) + (23100-1))-1 – 13698.3) / (-129.163)
Rt = (((-129.163Tc) +13698.3)-1) – 23100-1)-1
Where: Tc = Temperature in 􀁱C
Rt = Sensor Resistance in Ohms

AND supposedly Fahrenheit:
Conversion Formulas:
Tc = (((Rt-1) + (23100-1))-1 – 13698.3) / (-129.163)
Rt = (((-129.163Tc) +13698.3)-1) – 23100-1)-1
Where: Tc = Temperature in 􀁱F
Rt = Sensor Resistance in Ohms

Thanks again, Colin, for you math and Node-RED expertise!

Bruce

Well, on this side of the Atlantic, we use proper measurements - so we don't need those old-fashioned Fahrenheit that start and end in weird places

2 Likes

Yes, but we do have continue to support the colonies.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.