I have a temp sensor (LM335A) connected to analog pin 0. When converting the values to degress Celsius I got wrong sign if the temperature is -0,xx. For example:
-1,xx will be displayed as -1,xx (OK) but
-0,xx will be displayed as 0,xx (wrong, missing - sign when temp is 0, something)
I have picked up the code from different examples in Arduinos examples, but because of lack of skills in this area I can't find the error in the code:
// *************************************************************************************
unsigned int precision =100;
unsigned int frac;
double val;
double valr;
client.print("Analog 0: ");
val = analogRead(0);
val = val - 10; // calibration of LM335
val = val * 0.48875; // 5Volt/1023 * 100
valr = val - 273.15; // convert Kelvin to Celsius
client.print(int(valr)); // prints the int part
client.print(","); // print the decimal point
Can you post a version of the code that uses Serial so I can have a look and try running it? Just replace your sensor code with a hard coded floating point value
Here it comes, you have to change the different val statement:
void setup()
{
Serial.begin(9600);
}
void loop()
{
unsigned int precision =100;
unsigned int frac;
double val;
double valr;
val = 567; // expected result = -0,91 (actual 0,-91)
// val = 560; // expected result = -4,33 (actual -4,-33)
// val = 618; // expected result = 24,01 (actual 24,01)
val = val - 10; // calibration of LM335
val = val * 0.48875; // 5/1023 * 100
valr = val - 273.15; // Kelvin to Celsius
Serial.print("Analog 0: ");
Serial.print(int(valr)); //prints the int part
Serial.print(","); // print the decimal point