Go Down

### Topic: Not able to sense temp using an NTC thermistor (Read 132 times)previous topic - next topic

#### electrophile

##### Oct 11, 2017, 06:23 pm
I had bought a couple of 10K NTC thermistors a while ago and finally found some use for them. I was trying out Adafruit's guide on using them but I'm getting some whacky outputs. At room temp (about 23 deg C) I see a nominal resistance of 9.9K on the multimeter. However, with the code on the guide, I see temps being calculated as 60 deg C. I tried using different NTC's such as the one for the E3D nozzle and switched out the series resistor to 100k but still no joy! What am I missing?

#### wvmarle

#1
##### Oct 11, 2017, 06:34 pm
What am I missing?
No idea what you are missing, I do know what I am missing: your code and your circuit diagram (so no Fritzing eye candy).
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

#### electrophile

#2
##### Oct 11, 2017, 06:45 pm
Ergo the link to the guide. I've now added the fritzing image here. Also listed is the code.

Code: [Select]
`// which analog pin to connect#define THERMISTORPIN A0         // resistance at 25 degrees C#define THERMISTORNOMINAL 10000      // temp. for nominal resistance (almost always 25 C)#define TEMPERATURENOMINAL 25   // how many samples to take and average, more takes longer// but is more 'smooth'#define NUMSAMPLES 5// The beta coefficient of the thermistor (usually 3000-4000)#define BCOEFFICIENT 3950// the value of the 'other' resistor#define SERIESRESISTOR 10000     uint16_t samples[NUMSAMPLES]; void setup(void) {  Serial.begin(9600);  analogReference(EXTERNAL);} void loop(void) {  uint8_t i;  float average;   // take N samples in a row, with a slight delay  for (i=0; i< NUMSAMPLES; i++) {   samples[i] = analogRead(THERMISTORPIN);   delay(10);  }   // average all the samples out  average = 0;  for (i=0; i< NUMSAMPLES; i++) {     average += samples[i];  }  average /= NUMSAMPLES;   Serial.print("Average analog reading ");   Serial.println(average);   // convert the value to resistance  average = 1023 / average - 1;  average = SERIESRESISTOR / average;  Serial.print("Thermistor resistance ");   Serial.println(average);   float steinhart;  steinhart = average / THERMISTORNOMINAL;     // (R/Ro)  steinhart = log(steinhart);                  // ln(R/Ro)  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)  steinhart = 1.0 / steinhart;                 // Invert  steinhart -= 273.15;                         // convert to C   Serial.print("Temperature ");   Serial.print(steinhart);  Serial.println(" *C");   delay(1000);}`

#### wvmarle

#3
##### Oct 11, 2017, 07:17 pm
Is that the exact schematic & code YOU use?

And isn't it impressive how horribly unreadable Fritzings are even for this kind of simple diagrams?

DId you connect the 10k pull-up to 5V or 3.3V? (assuming you're using a 5V Arduino and have both voltages available).
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

#### jremington

#4
##### Oct 11, 2017, 07:46 pmLast Edit: Oct 11, 2017, 07:47 pm by jremington
The code and the idiot diagram have to match.

There are two ways of wiring the thermistor voltage divider. One of them is wrong.

#### electrophile

#5
##### Oct 11, 2017, 08:48 pm
Is that the exact schematic & code YOU use?

And isn't it impressive how horribly unreadable Fritzings are even for this kind of simple diagrams?

DId you connect the 10k pull-up to 5V or 3.3V? (assuming you're using a 5V Arduino and have both voltages available).
Yeah I took that from the Adafruit's page and they did not have a higher resolution image. I just realized that the schematic I attached here is different from the final one and the way I've wired it (which is shown a little later in the page on the guide). The final schematic has AREF and the 10K pullup at 3.3V.

#### electrophile

#6
##### Oct 11, 2017, 09:13 pm
The code and the idiot diagram have to match.

There are two ways of wiring the thermistor voltage divider. One of them is wrong.
Yeah I just realized that the schematic I attached here is different from the final one and the way I've wired it (which is shown a little later in the page on the guide). The final schematic has AREF and the 10K pullup at 3.3V. I'm guessing the other way is to swap the positions of the pullup and the thermistor?

#### jremington

#7
##### Oct 11, 2017, 11:07 pmLast Edit: Oct 11, 2017, 11:10 pm by jremington
Quote
I'm guessing the other way is to swap the positions of the pullup and the thermistor?
Correct.

You can damage the Arduino by connecting a voltage source to AREF, unless you follow the rules carefully. See https://www.arduino.cc/en/Reference/AnalogReference

#### wvmarle

#8
##### Oct 12, 2017, 04:59 am
You're using the beta-coefficient formula (did you change that parameter to match your NTC's?), so you wire the NTC between GND and the analog pin, and the 10k between 5V and the analog pin if you have a 5V Arduino, or between the analog pin and 3.3V if you have a 3.3V Arduino.

You mentioned wiring to +3.3V which is wrong on a 5V Arduino. That's why I asked for YOUR schematic, so how YOU wired it, not something you pulled off from a web site and which may or may not be the same.

If you wire the divider to +3.3V and your Vcc is 5V, then no wonder you have too high temperature. The analog pin gets a lower voltage, making the NTC appear to have a lower resistance, thus higher temperature.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

#### MarkT

#9
##### Oct 12, 2017, 02:33 pm
Yeah I took that from the Adafruit's page and they did not have a higher resolution image. I just realized that the schematic I attached here is different from the final one and the way I've wired it (which is shown a little later in the page on the guide). The final schematic has AREF and the 10K pullup at 3.3V.
Hand-draw an accurate diagram of how you've actually wired it, no point posting something that's different,
it muddies the water.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up