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; }

## 11 replies on “Arduino and KTY81-210”

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,

Thank you. I have changed the code.

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?

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.

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?

The resolution of arduino is not fine enough. The A/D converter can only read 1024 different voltages. see: https://www.arduino.cc/en/Reference/AnalogRead

If you use a voltage divider with a suitable resistor you can read a temperature range with a higher resolution.

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}

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?

// 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 (500);

}

float kty(unsigned int port) {

float sensorValue = analogRead(A2);

float resistance = (resistor * sensorValue) / (1023-sensorValue);

// resistor values from kty81-210 data sheet, written as polynomial trend line

float R25 = 2000;

// We are also given alpha and beta

float alpha = 7.88 / 1000;

float beta = 1.937 / 10000;

// Now we need to calculate the temperature factor (KayTee)

float KayTee = resistance / R25;

// We now have all the information to calculate the actual temperature

// (AcT)

// Just hope I’ve got my brackets is the correct place!

return 25 + ((sqrt((alpha * alpha) – (4 * beta) + (4 * beta * KayTee)) – alpha) / (2 * beta));

//

}

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?

hye can assist me how to recalculate the polynomial trend line for kty 83-122. Thanks you