D
D
danij_com2017-10-24 20:39:28
Arduino
danij_com, 2017-10-24 20:39:28

Why does the temperature change in the opposite direction?

I use an NTC10 thermistor. I connect, I use this sketch:

#include <math.h>
//Schematic:
// [Ground] ---- [10k-Resistor] -------|------- [Thermistor] ---- [+5v]
//                                                             |
//                                                     Analog Pin 0

double Thermistor(int RawADC) {
 // Inputs ADC Value from Thermistor and outputs Temperature in Celsius
 //  requires: include <math.h>
 // Utilizes the Steinhart-Hart Thermistor Equation:
 //    Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3}
 //    where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08
 long Resistance;  double Temp;  // Dual-Purpose variable to save space.
 Resistance=10000.0*((1024.0/RawADC) - 1);  // Assuming a 10k Thermistor.  Calculation is actually: Resistance = (1024 /ADC -1) * BalanceResistor
// For a GND-Thermistor-PullUp--Varef circuit it would be Rtherm=Rpullup/(1024.0/ADC-1)
 Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later. // "Temp" means "Temporary" on this line.
 Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));   // Now it means both "Temporary" and "Temperature"
 Temp = Temp - 273.15;  // Convert Kelvin to Celsius                                         // Now it only means "Temperature"

 // BEGIN- Remove these lines for the function not to display anything
  Serial.print("ADC: "); Serial.print(RawADC); Serial.print("/1024");  // Print out RAW ADC Number
  Serial.print(", Volts: "); printDouble(((RawADC*4.860)/1024.0),3);   // 4.860 volts is what my USB Port outputs.
  Serial.print(", Resistance: "); Serial.print(Resistance); Serial.print("ohms");
 // END- Remove these lines for the function not to display anything

 // Uncomment this line for the function to return Fahrenheit instead.
 //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit
 return Temp;  // Return the Temperature
}

void printDouble(double val, byte precision) {
  // prints val with number of decimal places determine by precision
  // precision is a number from 0 to 6 indicating the desired decimal places
  // example: printDouble(3.1415, 2); // prints 3.14 (two decimal places)
  Serial.print (int(val));  //prints the int part
  if( precision > 0) {
    Serial.print("."); // print the decimal point
    unsigned long frac, mult = 1;
    byte padding = precision -1;
    while(precision--) mult *=10;
    if(val >= 0) frac = (val - int(val)) * mult; else frac = (int(val) - val) * mult;
    unsigned long frac1 = frac;
    while(frac1 /= 10) padding--;
    while(padding--) Serial.print("0");
    Serial.print(frac,DEC) ;
  }
}

void setup() {
 Serial.begin(115200);
}

#define ThermistorPIN 0   // Analog Pin 0
double temp;
void loop() {
 temp=Thermistor(analogRead(ThermistorPIN));           // read ADC and convert it to Celsius
 Serial.print(", Celsius: "); printDouble(temp,3);     // display Celsius
 temp = (temp * 9.0)/ 5.0 + 32.0;                      // converts to Fahrenheit
 Serial.print(", Fahrenheit: "); printDouble(temp,3);  // display Fahrenheit
 Serial.println("");                                   // End of Line
 delay(100);                                           // Delay a bit... for fun, and to not Serial.print faster than the serial connection can output
}

Here , too, he, MB will be clearer.
So, in cold water (say 15-20 degrees) I get data like this
ADC: 507/1024, Volts: 2.406, Resistance: 10197ohms, Celsius: 24.555, Fahrenheit: 76.200
and in heat (33-38 degrees) are:
ADC: 416/1024, Volts: 1.974, Resistance: 14615ohms, Celsius: 16.563, Fahrenheit: 61.814
.
What is wrong here, what should be changed? Most likely something is wrong because of the thermistor (there was another one in the sketch), but I am far from all this, and I cannot understand it myself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kalapanga, 2017-10-25
@kalapanga

And everything is included, as it is written in the sketch: thermistor to + 5V, and 10k to ground? Not confused?
If you really have a PTC resistor, then the Steinhart-Hart equation used does not suit you, it is for NTC thermistors (by the way, the coefficients in it refer to a specific thermistor).
You can either calibrate your thermistor yourself, or find a datasheet for it and see the characteristic in it. Then use this data either in the form of a table, or select a function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question