Thermistor error. Increasing temperature value doesn't change but when a little decrease then it goes in -ve value

I am working on three thermistors of NTC 10K that are connected with a NANO board. But they're not giving me right values when I increase temperature it show same reading on serial monitor when I decrease temperature then it goes in (-ve) reading
What should I do
here's coding

// Define the analog pins for the thermistors
const int thermistorPin1 = A0;
const int thermistorPin2 = A2;
const int thermistorPin3 = A5;

// Define the series resistor value
const int seriesResistor = 1000; // 1K ohms

// Steinhart-Hart coefficients for the NTC 10K thermistor
const double A = 1.009249522e-03;
const double B = 2.378405444e-04;
const double C = 2.019202697e-07;
const int relayPin = 3;

void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud

  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW); 
}

void loop() {
  // Read analog values from the thermistors
  int rawValue1 = analogRead(thermistorPin1);
  int rawValue2 = analogRead(thermistorPin2);
  int rawValue3 = analogRead(thermistorPin3);

  // Calculate the resistance of each thermistor
  double resistance1 = calculateResistance(rawValue1);
  double resistance2 = calculateResistance(rawValue2);
  double resistance3 = calculateResistance(rawValue3);

  // Calculate the temperature in Celsius for each thermistor
  double temperature1 = calculateTemperature(resistance1);
  double temperature2 = calculateTemperature(resistance2);
  double temperature3 = calculateTemperature(resistance3);

  // Print the temperatures to the serial monitor
  Serial.print("Temperature 1: ");
  Serial.print(temperature1);
  Serial.println(" C");

  if (temperature1 <= 25.0) {
    digitalWrite(relayPin, HIGH); // Turn on relay
  } else {
    digitalWrite(relayPin, LOW); // Turn off relay
  }

  Serial.print("Temperature 2: ");
  Serial.print(temperature2);
  Serial.println(" C");

  Serial.print("Temperature 3: ");
  Serial.print(temperature3);
  Serial.println(" C");

  // Wait for a second before the next loop
  delay(1000);
}

// Function to calculate the resistance of the thermistor
double calculateResistance(int rawValue) {
  double voltage = rawValue * (5.0 / 1023.0);
  return seriesResistor * (5.0 / voltage - 1.0);
}

// Function to calculate the temperature in Celsius using the Steinhart-Hart equation
double calculateTemperature(double resistance) {
  double logR = log(resistance);
  double temp = 1.0 / (A + B * logR + C * logR * logR * logR);
  return temp - 273.15; // Convert Kelvin to Celsius
}

and here's image
Screen Shot 2024-07-19 at 11.53.34 PM

show schematic, datasheet of thermistor.

what is "(-ve) reading" ?

when I touch one of thermistors with hot object it shows nothing variation in serial mointoir but when touch with cold object the


How did you connect the NTC?
+V on the resistor, + NTC resistor on the analog pin and the other side of the NTC on GND?
If so, there is something wrong with the resistance calculation, as it increases with increasing temperature, and it should be the other way around.
After all, it is an NTC.....

one pin 5V and other pin with resistance that is futher with GND and Analog pins

Post your wiring eschematic, Is better for help.

It's time to make manual measurements. Use a glass of cold water and a glass of hot water.

In the glass of cold water, place the NTC and an extra temperature sensor. With the help of a multimeter, measure the resistance of the sensor and take the temperature data.

Little by little, add hot water to the glass with cold water, wait about 10 seconds and take the temperature and resistance data.

Establish a range of 25 to 60 C. You can approximate the empirical equation that best fits the trend of the data using a spreadsheet. Don't forget to add a reading smoother, so that the NTC drift is minimized as much as possible.

Smoothing Readings From an Analog Input

@ruilviana

separately sensors work very well I already perform this experiment but with multiple senors it won't work

Normally the thermistor is placed at the GND end of the series string so that the voltage dropped across it gets lower as temperature rises. OP's equation probably expects that to happen. A 10k resistor would be more appropriate as well.

1 Like

grafik


which thermistor did you heated up? A5 ?

// Define the analog pins for the thermistors
const int thermistorPin1 = A0;
const int relayPin = 3;

const int seriesResistor = 1000; // 1K ohms
const int OhmProGrad = 4;

void setup() {
  Serial.begin(115200);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, LOW);
}

void loop() {
  float temperature1 = (seriesResistor * (1023.0 / analogRead(thermistorPin1) - 1.0) - 10000.0) / OhmProGrad;

  // Print the temperatures to the serial monitor
  Serial.print("Temperature 1: ");
  Serial.print(temperature1);
  Serial.println(" C");

  digitalWrite(relayPin, temperature1 <= 25.0);

  delay(1000); // Wait for a second before the next loop
}

Every sensor

That's I have made

Are the A, B, C coefficients you are using provided by the thermistor manufacturer?
Also the Steinhart-Hart equation uses ln not log.

1 Like

Hi, @

Change this;

// Read analog values from the thermistors
  int rawValue1 = analogRead(thermistorPin1);
  int rawValue2 = analogRead(thermistorPin2);
  int rawValue3 = analogRead(thermistorPin3);

To;

// Read analog values from the thermistors
  int rawValue1 = analogRead(thermistorPin1);
  int rawValue1 = analogRead(thermistorPin1);
  int rawValue2 = analogRead(thermistorPin2);
  int rawValue2 = analogRead(thermistorPin2);
  int rawValue3 = analogRead(thermistorPin3);
  int rawValue3 = analogRead(thermistorPin3);

The Nano has ONE ADC, when you select each input and read it, you have to wait for the ADC input capacitor to charge to its new value.
By reading twice you give the ADC time to get a stabilised level to convert.

Can you post some images of your project?
So we can see your component layout.

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

1 Like

As mentioned earlier, a 10K series resistor would be used if your measured temperatures are in the room temperature range. If you would prefer to optimize operation around another temperature, say 0ºC then select a series resistor valued at the thermistor resistance at that temperature.