[SOLVED]KY-013 analog temperature sensor incorrect readings.


My KY-013 sensor is acting weird, but I believe the problem is in the code. This is the original test code that I received with it:

#include <math.h>
double Thermister(int RawADC) {
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
Temp = Temp - 273.15;// Convert Kelvin to Celcius
return Temp;
}
void setup() {
Serial.begin(9600);

}
void loop() {
Serial.print(Thermister(analogRead(0)));
Serial.println("c");
delay(500);
}

It's showing 32c instead of 18c. It seems that it's working in the opposite way. I mean, when I heat it, temperature drops, if it gets cold, temperature rises. Please revise the code and try to figure out where is the problem.

There is this comment

Temperature sensor module KY-013
These modules are the same, they're all on boards labelled “S1”. THE PINS ARE MARKED BACKWARDS ON THESE.
Has pin 1 (marked S) (GND), pin 2 (5v power) and pin 3 (marked -) (analog signal.)

on this site: https://wiki.makehackvoid.com/workshops:arduino:dxmodulepack

Swapped ground with power. Works well now. Thank You both.

Anyone has got this module working on Due?

Today i did some tests on this sensor with due. I connected analog out to S pin in middle i connected power 3.3v and in (-) pin i connected gnd. Because that module is like voltage divider and you can see that between S pin and mid are 10k resistor.

Code now looks like this :

double Thermister(int RawADC) {
  double Temp,Vo;
  Vo=float(RawADC)*(3.3/4095);
  Temp = log(10000*(3.3/Vo-1));
  //Temp = log(((10240000/RawADC) - 10000));
  Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
  Temp = Temp - 273.15;// Convert Kelvin to Celcius
  return Temp;
}

I am using 12 bit precission. And getting ~29-32C(need something like 20). When i measure out pin with tester i get ~1.6 volts but with arduino converting i get 2.26v. Maybe my tester is wrong :smiley:

volt=float(analogRead(A1))*(3.3/4095); // conversion to volts

up

Its turned out that it was IDE problems with DUE analog reading.

Hi, I used the code at the top and my reading goes down when I apply heat. Strange. Can anybody help me ?

Thanks in advance,
Jens Van den Eede.

The positions of the resistor and thermistor are swapped. Swap power and ground connections to the sensor.

1 Like