# math

Hello,
i am beginer…
can someone help me with code?
I need measure a temperature with thermistor

// Measure value of thermistor and data send to PC
//
// + (5V) … 1Ok … … 1k… 0V (GND)
// + (5V) … 10k … … thermistor … 0V(GND)
//

float value = 0;
int referencePin = 0; // thermistor pin 0.
int measurePin = 1; // reference pin 1.

int reference = 0;
int measure = 0;

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

void loop() {
// read the value from the refernce:

delay(1000);

value = (measure * 10000)/(reference - measure);

delay(1000);
Serial.print(“1”);
Serial.print(" ");
Serial.println(value,DEC);
}

But the date are horrible.
Big change in value.

Thank you !!!

``````value = (measure * 10000)/(reference - measure);
``````

All this arithmetic is integer - try some float casts.

How did you get to this algorithm: `value = (measure * 10000)/(reference - measure);` ? What are you trying to do?

:)

Um/5 = R/(R + 10000) My idea is to compare known and unkown on the thermistor... Bad |idea?

Float is solving. I thank you very very much! I am very happy Thanks!!!

and I am sorry for my english...

Your code actually looks more-or-less well-arranged to work with integer math. However:

``````int measure = 0;
:
value = (measure * 10000)/(reference - measure);
``````

All of the variables in here are "ints", which have a maximum value of 32767 on Arduino. So unless "measure" is consistently less than 4 (which isn't very interesting), that first multiply is likely to overflow the range of "int"-based math. If you're expecting the result to be a relatively small number, you might get away with changing the constant to a "long" (which will cause the intermediate math to be done with longs):

``````int measure = 0;
:
value = (measure * 10000L)/(reference - measure);
``````

Or you could make all of your variables be "long" (or floating point, as someone else suggested, though that may be more than you need.)