Created
August 2, 2011 03:17
-
-
Save 100ideas/1119533 to your computer and use it in GitHub Desktop.
Mystery Thermistor A B C coefficients (Steinhart-hart model)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* http://arduino.cc/playground/ComponentLib/Thermistor2 | |
* | |
* Inputs ADC Value from Thermistor and outputs Temperature in Celsius | |
* requires: include <math.h> | |
* Utilizes the Steinhart-Hart Thermistor Equation: | |
* Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]3} | |
* where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08 | |
* | |
* These coefficients seem to work fairly universally, which is a bit of a | |
* surprise. | |
* | |
* Schematic: | |
* [Ground] -- [10k-pad-resistor] -- | -- [thermistor] --[Vcc (5 or 3.3v)] | |
* | | |
* Analog Pin 0 | |
* | |
* In case it isn't obvious (as it wasn't to me until I thought about it), the analog ports | |
* measure the voltage between 0v -> Vcc which for an Arduino is a nominal 5v, but for (say) | |
* a JeeNode, is a nominal 3.3v. | |
* | |
* The resistance calculation uses the ratio of the two resistors, so the voltage | |
* specified above is really only required for the debugging that is commented out below | |
* | |
* Resistance = (1024 * PadResistance/ADC) - PadResistor | |
* | |
* I have used this successfully with some CH Pipe Sensors (http://www.atcsemitec.co.uk/pdfdocs/ch.pdf) | |
* which be obtained from http://www.rapidonline.co.uk. | |
* | |
*/ | |
#include <math.h> | |
#define ThermistorPIN 3 // Analog Pin 0 | |
float vcc = 4.96; // only used for display purposes, if used | |
// set to the measured Vcc. | |
float pad = 9880; // balance/pad resistor value, set this to | |
// the measured resistance of your pad resistor | |
float thermr = 4120; // thermistor nominal resistance | |
float Thermistor(int RawADC) { | |
long Resistance; | |
float Temp; // Dual-Purpose variable to save space. | |
Resistance=((1024 * pad / RawADC) - pad); | |
Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later | |
Temp = 1 / (0.0018990381 + (0.00012651185 * Temp) + (0.00000064511266 * Temp * Temp * Temp)); | |
Temp = Temp - 273.15; // Convert Kelvin to Celsius | |
// BEGIN- Remove these lines for the function not to display anything | |
//Serial.print("ADC: "); | |
//Serial.print(RawADC); | |
//Serial.print("/1024"); // Print out RAW ADC Number | |
//Serial.print(", vcc: "); | |
//Serial.print(vcc,2); | |
//Serial.print(", pad: "); | |
//Serial.print(pad/1000,3); | |
//Serial.print(" Kohms, Volts: "); | |
//Serial.print(((RawADC*vcc)/1024.0),3); | |
//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; | |
temp=Thermistor(analogRead(ThermistorPIN)); // read ADC and convert it to Celsius | |
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(1000); // Delay a bit... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment