KY-028

Hello everyone,
I use a translator to write to you.

I have a problem with a KY-028 temperature sensor. I recovered a code that must convert voltage in degree C °. Outside this program does not show me the good data

Do you have an idea ?

Voltage : 0.9091V
Value analogue :185
the current temperature:-6.43 C°

Voltage : 1.1926V
Value analogue :244
the current temperature:0.41 C°

#include <math.h>
int analogCapteur = A0;

double Thermistor(int RawADC){
    double Temp;
    Temp = log(10000.0 * ((1024.0 / RawADC - 1)));
    Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp )) * Temp );
    Temp = Temp - 273.15;            // Kelvin in °C
    return Temp;
}

void setup() {
//pinMode (analogCapteur, INPUT);
Serial.begin(9600);
}

void loop() {
float Analog;
int readVal = analogRead(analogCapteur);
double temp =  Thermistor(readVal);

Analog = analogRead(analogCapteur)*(5.0/1023.0); //valeur convertie en tension
int sensorValue= analogRead(analogCapteur); //valeur reélles du capteur

// Sortie vers l'interface série
    Serial.print("La temperature actuelle est:");
    Serial.print(temp); Serial.println(" C°");Serial.println("---------------------------------------");
    
    Serial.print("Tension : "); Serial.print(Analog,4); Serial.println("V");
    Serial.print ("Valeur analogue :"); Serial.println(sensorValue);
delay(1000);
}

what values are you getting? Did you try getting readings for things like ice or your hand... etc?

when I put my finger on the sensor, that's what I have and in ambient temperature (air) I'm +/- 20C ° but the monitor shows 0.41

Voltage : 0.9091V
Value analogue :185
The current temperature is:-6.43 C°

Voltage : 1.1926V
Value analogue :244
The current temperature is:0.41 C°

Please share your schematics. Which Arduino are you using?

Are you sure your formulas are correct?
Correct values for the pull-up resistor and beta coefficient?

I do think that using such a sensor module is terrible overkill for something as simple as a thermistor. All you need is a pull-up resistor to wire one up.

Try this

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

I haven’t tested I don’t have the unit but read more about the Steinhart-Hart equation.

I am not at home, as soon as I enter I test the code.