Using Arduino > Sensors

-=SOLVED=- Thermistor

<< < (3/3)

liuzengqiang:
Well, maybe your code is wrong reporting -11DegC. Care to share your code for a diagnostic?

Wracul:

--- Quote ---Posted by: liudr
Well, maybe your code is wrong reporting -11DegC. Care to share your code for a diagnostic?

--- End quote ---

I think you are correct. Thats the only thing that makes sense to me. The thermistor gives steady signals that behave normal when exposed too heat or cold.

I have fiddled around with two codes from the playground.

The easy one

--- Code: ---#include <math.h>

double Temp;
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() {
delay(100);
}

--- End code ---

The Elaborate Code

--- Code: ---#include <math.h>

#define ThermistorPIN 0                 // Analog Pin 0

float vcc = 4.91;                       // only used for display purposes, if used
// set to the measured Vcc.
float thermr = 10000;                   // thermistor nominal resistance

long Resistance;
float Temp;  // Dual-Purpose variable to save space.

Temp = log(Resistance); // Saving the Log(resistance) so not to calculate  it 4 times later
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15;  // Convert Kelvin to Celsius

// BEGIN- Remove these lines for the function not to display anything
//Serial.print("/1024");                           // Print out RAW ADC Number
//Serial.print(", vcc: ");
//Serial.print(vcc,2);
//Serial.print(" Kohms, Volts: ");
//Serial.print(", Resistance: ");
//Serial.print(Resistance);
//Serial.print(" ohms, ");
// END- Remove these lines for the function not to display anything

// Uncomment this line for the function to return Fahrenheit instead.
//temp = (Temp * 9.0)/ 5.0 + 32.0;                  // Convert to Fahrenheit
return Temp;                                      // Return the Temperature
}

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

void loop() {
float temp;
Serial.print("Celsius: ");
Serial.print(temp,1);                             // display Celsius
//temp = (temp * 9.0)/ 5.0 + 32.0;                  // converts to  Fahrenheit
//Serial.print(", Fahrenheit: ");
//Serial.print(temp,1);                             // display  Fahrenheit
Serial.println("");
delay(5000);                                      // Delay a bit...
}

--- End code ---

Savers:
That code is not intended for generic use, I believe it is intended for use with 10k thermistors.

This code is the steinhart-hart equation:

--- Code: ---Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
--- End code ---

Which converts the analog reading to "Kelvins". The line underneath that then converts Kelvins to Celsius.

For your thermistor to work correctly, it will need to be calibrated. That is, you need to calculate your own 3 constants (the numeric values) for the equation to work for your thermistor.

Wracul:
Wiring was messed up. Calibration using math solved the issue!
Thanks for all of the help i got!