tonilopezmr / tonilopezmr.github.io

My web portfolio.
https://tonilopezmr-github-io.vercel.app
Other
4 stars 1 forks source link

KTY 10-5 PTC Thermistor temperature sensor #55

Open tonilopezmr opened 4 years ago

tonilopezmr commented 4 years ago

PTC Thermistor

A thermistor is a type of resistor whose resistance is dependent on temperature, PTC Thermistor is positive temperature coefficient, the resistance increases as the temperature increases.

Usage

Schematic

The input voltage in our circuit is 5v and we choose a resistance of 2200 ohms.

Screenshot 2020-01-03 at 05 36 33

Calculation

We need to calculate the resistance of the sensor reading the analog input (VO), where we need to know the resistance of the sensor when the temperature is 25º, it calledR25 value where we can find it reading the datasheet, for KTY 10-5 is between 1950 and 1990 but we choose I use 2000 ohm because I got better results in combination with Rt of 2200 ohms.

Screenshot 2020-01-03 at 05 45 24
float resistorfixed = 2200;
float temp = analogRead(A0);
float Rt = (resistorfixed * temp) / (1023 - temp);

The temperature factor Kt can be derived from this:

Screenshot 2020-01-03 at 05 54 26
float R25 = 2000;
float Kt = Rt / R25;

The temperature at the sensor can be calculated from the change in the sensors resistance from the following equation, which approximates the characteristic curve.

Screenshot 2020-01-03 at 05 45 19
float alpha = 7.88 / 1000;
float beta  = 1.937 / 100000; 
T = 25 + ((sqrt((alpha * alpha) - (4 * beta) + (4 * beta * KayTee)) - alpha) / (2 * beta)); 

Code

float kty(unsigned int port) {
  float resistorfixed = 2200;  
  float temp = analogRead(port);
  float Rt = (resistorfixed * temp) / (1023 - temp);

  // From the data sheet the value of the resistance of the sensor 
  // @ 25 degrees is 2000 +/- 20 ohmsStart with calculating the measured 
  // resistance.

  float R25 = 2000;

  float alpha = 7.88 / 1000;
  float beta  = 1.937 / 100000; 

  float Kt = Rt / R25;

  return 25 + ((sqrt((alpha * alpha) - (4 * beta) + (4 * beta * Kt)) - alpha) / (2 * beta));  
}

References