#include <math.h> not working correctly

Hi there.

I'm trying a code found on: Arduino Playground - Thermistor2

#include <math.h>

double Thermister(int RawADC) {
 double Temp;
 Temp = log(((10240000/RawADC) - 10000));
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;            // Convert Kelvin to Celcius
 //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
 return Temp;
}

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

void loop() {
 Serial.println(int(Thermister(analogRead(0))));  // display Fahrenheit
 delay(100);
}

I have no errors during compiling.
My serial monitor gives me some nice Icelandic? symbols:

þÿÿÿÿþÿþÿÿþÿþþÿÿÿþÿÿÿþþÿÿþ

In my compiler #include <math.h> is not colored orange.

My system spec.
OS: Linux Ubuntu 11.10
Compiler: Arduino 0022ubuntu0.1

Does the message in my serial monitor mean that math.h is not installed on my comp?
If this is the case, does someone know how I get this file installed in the correct directory?

Kind regards.

The message in the IDE means that you

  • have set the wrong baudrate
  • or get binary data

please use

void loop() 
{
 Serial.println(Thermister(analogRead(0)), 2);  // float with 2 decimals, you can use 0,1,2,3, ...decimals
}

or if you want to have ints

void loop() 
{
 Serial.println( int(Thermister(analogRead(0))), DEC);  // if you don't add the DEC flag the int mught be interpreted as char 
 delay(100);
}

Bedankt Rob!

Works perfect now :slight_smile:

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

void loop() {
 Serial.println(Thermister(analogRead(0)), 2);  // float with 2 decimals, you can use 0,1,2,3, ...decimals
 delay(100);
}

You are welcome.

(you are dutch living in Sweden?)

Ja, helemaal correct, en getrouwd met een belgische uit walonie :slight_smile:
Maar omdat mijn ik geen Frans spreek en walonen geen Nederlands is het thuis in het Engels.