Go Down

Topic: Thermistor Reading Incorrectly (Read 1 time) previous topic - next topic

KyleBriggs

Forgive me if I am completely wrong here or doing something wrong, I am very new to electronics in general.

I have a thermistor with 2 47ohm resistors taking the place of the 10k one (didn't have a 10k one).

Using the code posted below, the serial output just reads -60ish, which is obviously not the temperature of my room in Celsius.

What am I doing wrong here?

Code: [Select]
#include <math.h>         //loads the more advanced math functions
 
void setup() {            //This function gets called when the Arduino starts
  Serial.begin(9600);   //This code sets up the Serial port at 115200 baud rate
}
 
double Thermister(int RawADC) {  //Function to perform the fancy math of the Steinhart-Hart equation
 double Temp;
 Temp = log(((10240000/RawADC) - 10000));
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;              // Convert Kelvin to Celsius
 return Temp;
}
 
void loop() {             //This function loops while the arduino is powered
  int val;                //Create an integer variable
  double temp;            //Variable to hold a temperature value
  val=analogRead(0);      //Read the analog port 0 and store the value in val
  temp=Thermister(val);   //Runs the fancy math on the raw analog value
  Serial.println(temp);   //Print the value to the serial port
  delay(1000);            //Wait one second before we do it again
}

jremington

#1
Oct 28, 2015, 09:06 pm Last Edit: Oct 28, 2015, 09:07 pm by jremington
It won't work with 2x47 Ohm resistors replacing 10K (10,000) Ohms.

Whandall

You could try to adjust the formula to the real value of the resistor (its the 10000).
Code: [Select]
Temp = log(((10240000/RawADC) - 10000));
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

KyleBriggs

It won't work with 2x47 Ohm resistors replacing 10K (10,000) Ohms.
jremington was right, I was using the wrong ones.

I am now using a 9k1 resistor, which is the closest thing I have, and seems to be giving better results (still not perfect though).

Delta_G

jremington was right, I was using the wrong ones.

I am now using a 9k1 resistor, which is the closest thing I have, and seems to be giving better results (still not perfect though).
Read reply #2 and you can make it perfect again.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

cattledog

#5
Oct 28, 2015, 09:48 pm Last Edit: Oct 28, 2015, 09:49 pm by cattledog
Quote
I have a thermistor with 2 47ohm resistors taking the place of the 10k one (didn't have a 10k one).
Your code is written for a voltage divider of 10K along with the 10K thermistor. When I run you code on my setup it gives the correct temperature.

Code: [Select]
Temp = log(((10240000/RawADC) - 10000));
This can be written in a way which shows the resistance of the voltage divider.
Code: [Select]
Temp = log((10000*(1024/RawADC) - 1));

If you have change the 97 ohms to 9k ohms, use
Code: [Select]
Temp = log((9000*(1024/RawADC) - 1));


TomGeorge

Hi,
Have you got a potentiometer of about 5K or 1K?
Place it in series with the 9k1 and adjust it to give 10K, it will do until you get 10k.

Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

Go Up