Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // constants for the thermistor and resistor values and the Steinhart-Hart equation
- int Rt = 15000; // Resistance of thermistor at 25 degrees c (from datasheet)
- int R1 = 17790; // Value of fixed resistor, measured using multimeter
- float K0 = 0.003354016; // Parameters for determining nominal resistance values (from datasheet)
- float K1 = 0.0002744032;
- float K2 = 0.000003666944;
- float K3 = 0.000003666944;
- float Vin = 5.06; // Arduino output, measured using multimeter
- float Abs0 = -273.15; // 0 Kelvin in C (made it a variable, just in case it changes)
- int degree_symbol = 223; // ascii code for °
- int thermistor_pin = 0; // analogue pin 0
- // Steinhart-Hart equation to convert resistance value from analogue read to temperature in Celcius
- double Thermistor(int RawADC)
- {
- float Vout = RawADC/1024.0*Vin; // convert the ADC to voltage
- float Res = Vin*(R1/Vout)-R1; // Calculate the resistance of the thermistor
- double Temp = Abs0 + 1 / (K0 + K1 * log(Res/R1) + K2 * pow(log(Res/R1),2) + K3 * pow(log(Res/R1),3)); // use Steinhart-Hart to calculate temperature;
- return Temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement