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