Advertisement
Guest User

Arduino - Steinhart-Hart example

a guest
Jul 27th, 2012
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.15 KB | None | 0 0
  1. // constants for the thermistor and resistor values and the Steinhart-Hart equation
  2. int Rt = 15000;            // Resistance of thermistor at 25 degrees c (from datasheet)
  3. int R1 = 17790;            // Value of fixed resistor, measured using multimeter
  4.  
  5. float K0 = 0.003354016;    // Parameters for determining nominal resistance values (from datasheet)
  6. float K1 = 0.0002744032;
  7. float K2 = 0.000003666944;
  8. float K3 = 0.000003666944;
  9.  
  10. float Vin = 5.06;          // Arduino output, measured using multimeter
  11.  
  12. float Abs0 = -273.15;      // 0 Kelvin in C (made it a variable, just in case it changes)
  13.  
  14. int degree_symbol = 223;  // ascii code for °
  15.  
  16. int thermistor_pin = 0;    // analogue pin 0
  17.  
  18.  
  19. // Steinhart-Hart equation to convert resistance value from analogue read to temperature in Celcius
  20. double Thermistor(int RawADC)
  21. {
  22.   float Vout = RawADC/1024.0*Vin;    // convert the ADC to voltage  
  23.   float Res = Vin*(R1/Vout)-R1;      // Calculate the resistance of the thermistor
  24.   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;
  25.  
  26.   return Temp;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement