0

Suddenly, after testing my NTC thermistor (100k), the thermistor's curve started to turn into a PTC curve. To measure the resistance I am using an Arduino. I think its a hardware issue as I did not change my program at all. Is there a way to check it the resistance's that the Arduino outputs are correct? Could this be the problem, would it be the thermistors? The precision, I think, is also affected, some are too 5C others are to 1C.

#include <Wire.h>
#include <Arduino.h>
int ThermistorPin = 0, reffPin = 1;
int resistance = 10000;


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

void loop() {
  float avg = 0;

      for(int x = 0; x < 10; x++)
      {
        avg += volateToResistance();
        delay(50);

      }
      Serial.println(avg/10.0);
    delay(5);
}
float volateToResistance()
{
  float voltage = analogRead(reffPin) * 5.0/1023;  // takes in ausmmed 5 volts and calulates actutal voltage Ex if analogRead(reffPin) = 1023, then voltage will be equal to exactly 5 volts 
  float Vout= (analogRead(ThermistorPin) * voltage)/1023.0;
  return resistance * (voltage/Vout) -1;
}

enter image description here

Aditya Kendre
  • 97
  • 1
  • 7
  • 2
    A multimeter would be the classical way of measuring resistance. – Marcus Müller Nov 02 '19 at 15:26
  • 1
    To measure the resistance you are using an ardunio and what circuit? – τεκ Nov 02 '19 at 15:26
  • 1
    The Arduino is not an ohmmeter so you need to show us the circuit you are using and insert a listing of your code. Have you measured the thermistors with an actual ohmmeter? – Elliot Alderson Nov 02 '19 at 15:27
  • @Elliot Alderson I am not really too experienced with drawing circuits, but I attached an image, does this help? – Aditya Kendre Nov 02 '19 at 15:37
  • 2
    @AdityaKendre an actual schematic would've been better (drawing them is not hard) than a wiring cartoon, but well, it helps, if you tell us which cables go where. – Marcus Müller Nov 02 '19 at 15:43
  • 5V got to the left side of the thermistor, GND has a 100k resistor that is connected to the right side of the thermistor. That same side has a wire that carries the analog signal to the Arduino. – Aditya Kendre Nov 02 '19 at 16:01
  • Are you familiar with a voltage divider? Consider what happens when the NTC is on the high side of the divider. – sstobbe Nov 02 '19 at 16:08
  • 1
    Your code doesn't make sense to me. You calculate `voltage`, then multiply `Vout` by it, then factor it out in the `return` statement. You might want to add some comments. – Elliot Alderson Nov 02 '19 at 16:13
  • @sstobbe yes I am, I am using that in the program, in the function volateToResistance(). – Aditya Kendre Nov 02 '19 at 16:24
  • @ElliotAlderson it is not factored out because it is being divided by 1023.0 first – Aditya Kendre Nov 02 '19 at 16:31
  • if your for() loop, you should put debug print for both `analogRead(reffPin)` and `analogRead(ThermistorPin)` and provide output of those (so, 20 numbers - one for each value for each loop) to be able to debug it further. It might be that you need to setup pins 0 & 1 as analog inputs or something -- proposed debug will provide us with more info to answer. – Matija Nalis Nov 02 '19 at 16:31
  • Please explain what you are trying to do with your calculations, preferably by adding comments to your code. – Elliot Alderson Nov 02 '19 at 16:51
  • Assuming nothing else is wrong, you still need brackets here `*((voltage/Vout) -1)` – sstobbe Nov 02 '19 at 16:58
  • 1
    Side note: your calculation should be \$voltage/1024\$ not 1023 (see [here](https://electronics.stackexchange.com/a/258497/53368)). This is a very common mistake perpetuated by an Arduino code example. – Tom Carpenter Nov 02 '19 at 21:51
  • Your reference resistor is 100K but the number 10,000 is used in the program. The formula for resistance is wrong, it should be 100000*(Voltage/Vout-1). – Spehro Pefhany Nov 03 '19 at 04:29
  • Please undelete you question https://electronics.stackexchange.com/q/465548/3288. People have put substantial effort into assisting you with the question - deleting it destroys the value others may get from the question plus other people's input. The question and answers are worthwhile and deleting it removes the worthwhileness. – Russell McMahon Nov 03 '19 at 22:53
  • @RussellMcMahon I understand, but after clarifying, no one seemed to be interested in helping, despite their initial effort and interest. – Aditya Kendre Nov 04 '19 at 02:29
  • Regardless of what it may seem (1) The time span was far far far too short to tell. People answering or commenting are all over the world - I'm in New Zealand. (Are you in India). Others are in USA & UK and elsewhere. It takes days for a proper to and fro discussion. Under a day is far too short to decide to pack up and leave. (2) If you delete it you ensure that nobody can help or add to the thread. (3) It's 'impolite' to waste people's efforts by deleting them (they vanish for most users along with the question). – Russell McMahon Nov 04 '19 at 11:39
  • @RussellMcMahon so how do I get answers to my question? – Aditya Kendre Nov 08 '19 at 03:01
  • @AdityaKendre You could try - Reading the answer you have and advising whether what is suggested explains what you are seeing. eg if you swap the red and black wires the voltage will DECREASE with increasing temperature. As you have it wired the voltage will increase. Did you check whether this is your 'problem'? If so,m did you provide feedback. || You could explain what you mean by "started to turn into a PTC curve" -> We can guess what that may mean but it doesn't tell us what you are seeing. Providing some measurement results with temperature would be a good idea. – Russell McMahon Nov 08 '19 at 05:25
  • || BUT, FIRSt - what happens when you swap the red and black wires? – Russell McMahon Nov 08 '19 at 05:25
  • @RussellMcMahon, that was the problem. I need help on my other question. – Aditya Kendre Nov 11 '19 at 03:42
  • @AdityaKendre The lead swapping was suggested 9 days ago. On November 2nd Anders said "As your thermistor is on the high side of the voltage divider and you measure across the lower resistor, you will measure higher voltage when a NTC thermistor heats up" -> If you'd read through the suggestions then and implemented them AND, importantly understood why it works, you'd have wasted less of your time and other people's. || This site is an IMMENSE resource. Learn to use it well. – Russell McMahon Nov 11 '19 at 05:40

1 Answers1

2

As general troubleshooting guide, if you question the thermistor, test it in isolation. Disconnect the thermistor from the circuit, and use a multimeter in resistance mode to measure its resistance... should show about 100 kohm. Grab the thermistor with your fingers to heat it, and verify that the resistance decreases. Then it's a NTC.

If the problem is not with the thermistor, it's the calculations. Your calculations don't look right to me but I can't say exactly what's wrong. You can't measure Vref as that's already the reference the ADC measures again -- it's like using a ruler to measure the length of the ruler.

As your thermistor is on the high side of the voltage divider and you measure across the lower resistor, you will measure higher voltage when a NTC thermistor heats up. Maybe this is what confuses you.

A warning about your setup; your voltage divider using a 100 kohm thermistor and 100 kohm resistor will together give 50 kohm impedance. Signal impedance is the resistance 'experienced' by the microcontroller ADC, or loosely how sensitive the signal is to disturbances. Arduino Uno uses the ATMega328 microcontroller, which needs lower impedance for ADC to avoid skewed measurements. The datasheet can tell you in detail but I vaguely remember it should be lower than 10 kohm at least. The easiest solution is to add a capacitor between A0 and GND. Any capacitor value 10 nF or higher is ok -- 100 nF and 1 uF are common values.

The precision, I think, is also affected, some are too 5C others are to 1C.

This may be due to the impedance mentioned above, some error in the calculation or natural variations between thermistors. (All thermistors only promise to follow the specifications within some percentage.)

Anders Petersson
  • 1,111
  • 6
  • 10
  • some of those capture-a-sample-of-the-analog-input ADCs end up with negative voltages on the cap (from what I've seen), and that causes huge confusion on the next high-impedance sample. – analogsystemsrf Nov 02 '19 at 17:31
  • That's odd, do you have some link for that phenomenon? A big cap or slow sampling frequency should avoid such a problem, right? – Anders Petersson Nov 02 '19 at 17:35
  • 1
    the behavior is what I recall explained the -90 millivolt input residual on a Teensy board. The engineer-in-charge added a unity-gain buffer, and RC output filter, and that behavior went away. There is no link. Without the ADC schematic and timing diagram, who know what really was happening. I was just helping debug. – analogsystemsrf Nov 03 '19 at 03:54