Ky-028 temperature sensor interface

I have connected a KY-028 digital temperature sensor for measurement of body temperature . I have interfaced but I'm not getting proper output even though I adjusted with potentiometer values. it reads the environmental temperature but when I place my hand on thermistor my value is getting decreased. what should I do? how should I rectify this issue? I need this help.

I have connected the LED for external observation.

Thank you.

Here's the code:

int led = 12; // define the LED pin
int digitalPin = 2; // KY-028 digital interface
int analogPin = A0; // KY-028 analog interface
int digitalVal; // digital readings
int v_input; //analog readings
void setup()
{
  pinMode(led, OUTPUT);
  pinMode(digitalPin,  INPUT);
  pinMode(analogPin, INPUT);
  Serial.begin(9600);
}
void loop()
{
  // Read the digital interface
  digitalVal = digitalRead(digitalPin); 
  
  if(digitalVal == HIGH) // if temperature threshold reached
  {
    digitalWrite(led, HIGH); // turn ON Arduino's LED
  }
  else
  {
    digitalWrite(led, LOW); // turn OFF Arduino's LED
  }
  Serial.print("Digital Value : ");
  Serial.println(digitalVal);
//   Read the analog interface
  

int v_input = analogRead(analogPin);//1024 VALUE
float b = 10000*(1024.0/(float)v_input-1.0);
float c    = (1.0/(0.001129148+(0.000234125*log(b)) + 0.0000000876741*log(b)*log(b)*log(b)))-273.15;
//b = b - 273.15;   
//b=(b − 32.0) * 5.0/9.0;

//b = (b * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Serial.print("temperature in celsius :");
Serial.println(c);
delay(2000);
}

//Temp = log(10000.0*((1024.0/RawADC-1))); 
 // Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 // Temp = Temp - 273.15;            // Convert Kelvin to Celcius
   //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit

Proof pictures:

Can anyone help me with this?

Which Arduino board do you have? How have you connected the sensor to it?

Try:
int v_input = 1023 - analogRead(analogPin);

Arduino Nano I'm using it now.

let me try and say

Not familiar with your sensor but maybe it's a negative temperature coefficient one.

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

image

In your code can you also print the raw data from the analog input pin?

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Circuit:

Code:

int led = 12; // define the LED pin
int digitalPin = 2; // KY-028 digital interface
int analogPin = A0; // KY-028 analog interface
int digitalVal; // digital readings
int v_input; //analog readings
void setup()
{
  pinMode(led, OUTPUT);
  pinMode(digitalPin,  INPUT);
  pinMode(analogPin, INPUT);
  Serial.begin(9600);
}
void loop()
{
  // Read the digital interface
  digitalVal = digitalRead(digitalPin); 
  
  if(digitalVal == HIGH) // if temperature threshold reached
  {
    digitalWrite(led, HIGH); // turn ON Arduino's LED
  }
  else
  {
    digitalWrite(led, LOW); // turn OFF Arduino's LED
  }
  Serial.print("Digital Value : ");
  Serial.println(digitalVal);
//   Read the analog interface
  

int v_input = analogRead(analogPin);//1024 VALUE
float temp = 125.315-0.175529*v_input-2.5;
//float b = 10000*(1024.0/(float)v_input-1.0);
//float c    = (1.0/(0.001129148+(0.000234125*log(b)) + 0.0000000876741*log(b)*log(b)*log(b)))-273.15;
//b = b - 273.15;   
//b=(b − 32.0) * 5.0/9.0;

//b = (b * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
Serial.print("temperature in celsius :");
Serial.println(temp);
delay(2000);

Did you try what I suggested in post 3

Yes sir but it didnt work.

Hi,
Can you print out the ' v_input ' value in the line after you analogRead?
So you can see what your raw input is.

Something like;

Serial.print("raw v_input :");
Serial.println(v_input);

Tom... :smiley: :+1: :coffee: :coffee: :australia:

The value is still decreasing when you put your hand on it?

as of now it is increasing but it is not showing accurately even though I calibrate it.

okay ill try

What do you meas "as of now"
How did you calibrate it?

@jim-p I connected again today . my values started increasing and i made some changes in program so that it comes with the accurate values when I checked with standard device.

What does this do?

heres the raw output:

this is the code which converts from raw voltage to Celsius (and the subtraction of -2.5 is for calibration purpose.

I cannot find any information about the thermistor used on that module, so I would just be guessing as to what the correct formula would be.