I am trying to get readings from a thermistor and referenced this link:
http://www.arduino.cc/playground/ComponentLib/Thermistor2
and am using the simple code.
My circuit also looks like the one in this link:
When I run the code and examine the values in the Serial Monitor the numbers are not accurate. I get a value of about 1 degree Farenheit when I should be getting something closer to 68F. Below is my code:
#include <math.h>
int tempSensor = A0; // Analog input pin that the thermistor is connected to
int inputSensorValue = 0; // Input sensor value read from the Thermistor
double ThermistorC(int RawADC) {
double TempC;
TempC = log(((10240000/RawADC) - 10000));
TempC = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * TempC * TempC ))* TempC );
TempC = TempC - 273.15; // Convert Kelvin to Celcius
return TempC;
}
double ThermistorF(int RawADC) {
double TempF;
TempF = log(((10240000/RawADC) - 10000));
TempF = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * TempF * TempF ))* TempF );
TempF = TempF - 273.15; // Convert Kelvin to Celcius
TempF = (TempF * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
return TempF;
}
void setup(){
Serial.begin(9600);
}
void loop() {
// Get sensor reading:
inputSensorValue = analogRead(A0);
// Print to Serial Monitor Sensor Values (optional):
Serial.print("Sensor Temp Farenheit = " );
Serial.println(int(ThermistorF(analogRead(inputSensorValue)))); // Display Fahrenheit
}
I have scanned the net for other samples of this and when I copy the code and paste into the arduino IDE I get googly gop in the serial monitor. Any idea why I can not get the right values from the code above?
Thanks in Advance!