Arduino and KTY81-210

You have a lot of possibilities to measure the temperature with an arduino. One simple solution is the usage of a KTY81 silicon temperature sensors.
Arduino describes on the playground the usage of KTY81-110. If you have an other type, you need to recalculate the temperature.


(Vcc 5+)--+-->2.7k--+-->kty81-210-->(GND)
          |         |
          +->100nF--+-----> ADC2 (Analog Port 2)

Here is my code to use KTY81-210 with the arduino:

// resistor value of voltage divider in ohm
float resistor = 2700;

void setup() {
  Serial.begin(9600); 
}

void loop() {  
  float temp = kty(2); 
  Serial.print("Temperature: ");
  Serial.println(temp,1); 
  delay (5000);  
}

float kty(unsigned int port) {
   float sensorValue = analogRead(port);  
   float resistance = sensorValue / (1023-sensorValue) * resistor;
   // resistor values from kty81-210 data sheet, written as polynomial trend line
   return -1.332e-11 * pow(resistance,4) + 6.621e-8 * pow(resistance,3) - 0.0002 * pow(resistance,2) + 0.2947 * resistance - 230.55;  
}

10 thoughts on “Arduino and KTY81-210

  1. Hi! Thx for your code. In case you are still using this code: There happened a mistake in
    float res_typ210[] = {980,1030,1135,1247,1367,1495,1630,1772,1922,2000,2080,2245,2417,2597,2785,2980,3192,3392,3607,3817,2915,4008,4166,4280};

    the 4th value, counting from the end, should be 3915,

  2. Hi. I am compiling this code with latest Arduino 1.6.7 IDE on Arduino Uno R3 and i get following error:

    Arduino: 1.6.7 (Windows 10), Board: “Arduino/Genuino Uno”
    C:UsersUserDocumentsArduinotempSensortempSensor.ino: In function ‘float kty(unsigned int)’:
    tempSensor:41: error: unable to find a register to spill in class ‘POINTER_REGS’
    }
    ^
    tempSensor:41: error: this is the insn:
    (insn 57 56 59 3 (set (reg:SF 71 [ D.4034 ])
    (mem:SF (post_inc:HI (reg:HI 8 r8 [orig:84 ivtmp.16 ] [84])) [2 MEM[base: _44, offset: 0B]+0 S4 A8])) C:UsersUserDocumentsArduinotempSensortempSensor.ino:33 99 {*movsf}
    (expr_list:REG_INC (reg:HI 8 r8 [orig:84 ivtmp.16 ] [84])
    (nil)))

    C:UsersUserDocumentsArduinotempSensortempSensor.ino:41: confused by earlier errors, bailing out
    exit status 1
    unable to find a register to spill in class ‘POINTER_REGS’

    if i comment this line, it compiles ok:
    temp = map(resistance,res_typ210[i-1],res_typ210[i],temperature[i-1],temperature[i]);

    any idea?

    1. Thank you, for the comment.

      I have simplified my code and replace the linear regression with a polynomial trend function.
      Now the code is easier and use less memory.

  3. Hello
    Thx for the code, it’s helpfull in some ways.
    I’m fairly new to arduino and have a question.
    Is there any way to make it (much) more precise? I’m making a thermostat and, and want to read the temperature to 0.1°C precision. I’m also using an KTY81-210 I was thinking about an equation, but don’t know how to implement that into a function. Do you have any suggestions/tips?

  4. Hey,
    Did similar recalculations, but just reduced huge and nano numbers in recalculations. After the tests the results are more precise, here is my code:
    {code}
    float kty(unsigned int port) {
    // resistor value of voltage divider in ohm
    float resistor = 2.7;
    float sensorValue = analogRead(0);
    float resistance = sensorValue / (1023.0 – sensorValue) * resistor;
    return 0.4616 * pow(resistance,6) – 6.8569 * pow(resistance,5) + 41.072 * pow(resistance,4) – 124.4 * pow(resistance,3) + 187.43 * pow(resistance,2) – 47.345 * resistance – 102.0;
    }
    {code}

  5. Hi, I’m somehow struggle with the polynomial trend.
    when I use the function above with a kty81-210 connected as described I receive negative temperature values of ~-140°C instead of the room temperature (~25°C). Can you explain this function a little bit more in detail?

  6. Hi, I’m doing a little project with PTC already installed in a system, with a characteristic similar to a kty81-120, I’m not a skilled electronic or mathematic, I’m looking for the calculation for that one:

    // resistor values from kty81-210 data sheet, written as polynomial trend line
    return -1.332e-11 * pow(resistance,4) + 6.621e-8 * pow(resistance,3) – 0.0002 * pow(resistance,2) + 0.2947 * resistance – 230.55;

    Can you help me?

    1. Hi Paolo, you can use MS Excel to get the polynomial trend line.

      • Create a table with resistance values from sensor spec sheet.
      • Then create a diagram that shows you the graph.
      • Add the trend line.
      • Experiment a little bit with the degree of the polynom
      • If the trend line seems to be the same as the data line, then you have found the polynomial trend line.
      • Select the option “show formula in diagram”

      That’s it.

Leave a Comment

Your email address will not be published. Required fields are marked *

*
*