How to write mathematic formular

Hey everyone,

can anyboddy tell how to write the formular from the attachment:

It is for a pt100 temperature sensor, to convert from a resistor value to temperatur value, for a reflow oven.

Thanks for your help

Formel.jpg

Getting rid of the square root would be a nice thing.

If you know the value of R beforehand, you might want to consider a Taylor Series polynomial approximation.

Something along the lines of:

Sqrt(1+x) ~ 1+ x/2 (for small x)

@madworm: thanks for your suggestion, but I need this specific fromular to calculate the exact temperatur.

Yes I have the R , I measure it directly from my sensor, but I understand temperatur better in "grad celsius" rater than in "ohm" :slight_smile:

First of all resolve all the constants and then write:-

float v = 3367.8214 - sqrt( 658.0757 - ( ((R - 100) / 0.00005802) ) );

Having previously declared R as a float.

float v = 3367.8214 - sqrt( 658.0757 - ( ((R - 100) / 0.00005802) ) );

On the other hand, don't be surprised if the results of that equation are not all that accurate. The Arduino float only maintains about 7 decimal places of accuracy, and 0.00005802 needs more than that.

A reasonable approximation for R[50;600] would be:

-226.85504878113625 + 2.033937327789973 * R + 0.0019147392438741005 * R^2

This assumes you want to measure the full span and don't care about +-10°C.

The next step would be:

-251.96964009558474 + 2.538330204844686 * R - 0.00018864861949198966 * R^2 + 2.3370976259623254 * R^3

With just +-3°C

But all of that is moot without knowing your temperature range.

If you're only interested in a more limited temperature range, you could get away with just a linear approximation.

The best way with a thermistor is to use a look up table and then a linear interpolation between points.

thanks for all your replays,

I am so far at the moment but my calculation always returns 0, the room temperatur is 26 grad celsius so 110 ohms.

int sensorPin = A1;    
int sensor = 0;  
int resistor;
int p1 = 0.390802; 
int p2 = 0.00005802;
int temperatur;

void setup() 
{
  Serial.begin(9600);
}

void loop() 
{
  
  sensor = analogRead(sensorPin);
  Serial.println("Sensor Value");
  Serial.print(sensor);
  delay(1000);      
  
  resistor = 100 * sensor / 5 - sensor;
  resistor = resistor / 100;
  Serial.println("Widerstand");
  Serial.print(resistor);
  
  temperatur = p1 / (2 * p2) - sqrt(p1 ^ 2 / 4 * (p2 ^ 2) - (resistor - 100)/ p2);
  
  Serial.println("Temperatur");
  Serial.print(temperatur);
  
}

Can you have a look at it maybe I wrote the formular wrong?

thanks

int p1 = 0.390802;
int p2 = 0.00005802;

is the same as writing

int p1 = 0;
int p2 = 0;

Use "float".

Not sure why you ask for advice and then ignore it:-

First of all resolve all the constants

That is to increase the accuracy.

If this is a class project then be sure to site your sources, otherwise it is plagiarism.

@AWOL: Thanks, stupid mistake by myself!

@Grumpy_Mike: Thanks for your advise, this project is just for me!

PaulS:
The Arduino float only maintains about 7 decimal places of accuracy, and 0.00005802 needs more than that.

That is inaccurate. Floats maintain X digits of resolution, not to be confused with number of decimal places. Floats are essentially stored in exponential format, ie 5.802 x 10^-5. with a number of bits dedicated to storing the significand, a number of bits dedicated to storing the exponent, and a sign bit. So the value only has 4 digits of accuracy required of the significand, while Arduino's implementation of float is able to support up to about 7 digits (with up to about 30 leading zeroes for extremely small numbers, or 30 trailing zeros for extremely large numbers.

as division is more expensive than multiply, you can write the formula this way

float v = 3367.8214 - sqrt( 658.0757 - ( ((R - 100) / 0.00005802) ) );

can be rewritten as

float v = 3367.8214 - sqrt( 658.0757 - (R - 100) * 17235.436 ); // 17235.436 = 1/0.00005802

oeps updated (been a long day... :wink:

As you are using it thusly:

"It is for a pt100 temperature sensor, to convert from a resistor value to temperatur value, >> for a reflow oven.<< "

Maybe you could consider the PID library also, for measuring rates and projecting turn on/turn off times.