# Outside reference voltage for thermistor - How to change formula?

Hello,

i am measuring temperature using NTC10k thermistor, 1k pull-down resistor and Steinhart-Hart equation. When i am powering thermistor with 5V (the same source for powering Arduino) the result is perfect, really accurate.

Now the problem is that i must supply thermistor with bigger voltage (stable 12V) but with common ground as Arduino. Because of that result is incorrect.

I understand why but i don't know how to change formula (where to include this 12V) to get correct result, if that's even possible.

``````#define B 3950       // B = Thermistor B parameter (3950, datasheet)
#define T0 298.15  // T0 = 298,15
#define Ra 10000   // Ra = 10000 ohms of thermistor
#define Rb 1000     // Rb = Resistor (1k = 1000 ohms)

float R1,T1;
int temp1;

void setup()
{

}

void loop()
{

R1 = 1024.0 * Rb / float(analogRead(A0)) - Rb;
T1 = 1.0 / (1.0 / T0 + (1.0 / B) * log(R1 / Ra));

temp1 = T1 - 273.15;

}
``````

Be sure your input voltage never goes above 5.5V or you may damage the Arduino.

I think the corrected formula is:

``````  R1 = 1024.0 * Rb / float(analogRead(A0)) * 12.0 / 5.0 - Rb;
``````

Basically you are reading a voltage to calculate one resistance in a resistive divider.

You know the one resistor value, and you know the reading on the ADC. As long as the voltage on your ADC input remains between 0 and 5V then that voltage can calculated from the ADC reading.

You have a number of values to take into account:

1. The full scale voltage is 12V
2. The ADC full scale voltage is whatever you have scaled your 0-12V values to.

The unknown resistance basically forms part of a ratio:

Vout = Vin * R2 / (R1 + R2)

so the output voltage is the ratio of R1:R2 multiplied by the input voltage. That output voltage must then be scaled (typically with another resistive divider) to remain within the 0-5V range. Without the extra scaling Vout would be in the range 0 to 12V (infinity ohms to 0 ohms on the top resistor). Scaling that with a 3:1 resistive divider, say, would give a range of 0 to 4V, which is ideal. Other values can be used, too, as long as they fall within the 0-5V range. That top range value is important, as it forms the voltage in note 2 above.

So if the output is then scaled between 0 and 4V, then that is the value you should use in calculating the voltage, and hence the resistance.

The voltage on the ADC is:

ADC * 5 / 1023, or ADC / 1023.0 * 5.0, which ever way around you want to do it.

The 5 is the reference voltage for the ADC (the voltage your board runs at), not the voltage of the incoming reading. So it should return a value between 0 and 4V. You then put that into the resistance calculating formula, but with an upper voltage of 4V, not 5V - note, this is the SCALED voltage, not the SUPPLY voltage.

So your formula, for a 3:1 ratio divider on the input, would be:

((R2 * Vin) / Vout) - R2

Where R2 is your 1K?, Vin is 4V, and Vout is the result of the ADC to voltage calculation, so:
((1000.0 * 4.0) / (float(ADC) / 1023.0 * 5.0)) - 1000.0

Or, simplified:

(4000.0 / (float(ADC) / 5115.0)) - 1000.0

Hi, big question why must you use 12V?
If the arduino is measuring the thermistor why can’t it supply the 5V, or another 5V source?
If the sensor has to be some distance from the arduino, use 2 wires to thermistor and resistor at the arduino analogue input to gnd.
Check that you will not be heating the thermistor with the sense current.
Tom.

TomGeorge:
Hi, big question why must you use 12V?

The problem is that i am developing this solar regulator for already prepared conditions (not by me, ofcourse). On the roof there is a photovoltaic module (for supplying the whole circuit) and one thermistor. Basicly i would use 4 wires for that (2 for PV module and 2 for thermistor) but there are only 3 wires in cable (which is already installed and brought to the roof). Because of that i must use one wire as common for both. Systems on the roof are also already connected like this: one wire for PV module minus, second wire for thermistors minus and third wire as common plus. That means that thermistor's supply is the same as voltage on PV module.

johnwasser:
Be sure your input voltage never goes above 5.5V or you may damage the Arduino.

majenko:
That output voltage must then be scaled (typically with another resistive divider) to remain within the 0-5V range.

If i am supplying NTC 10k thermistor and 1k divider resistor with 12V, in some conditions output will be higher than 5V. That means that i must connect 2 resistors with thermistor and include both of them in my calculations (to be in safe voltage area for microcontroller), right?

Btw, voltage won't be exactly 12V (i put this value for easier explanation) but i am measuring it all the time through another voltage divider. I am planning to include that "voltage reading" in my equation for more precise calculation. Could this work like that?

Hi, fine I see your problem.

However this means that you are sharing the thermistor current in the wire with current generated by the PV, volt drop in the wire will mean that your thermistor readings, that are calculated on voltage drop, will be affected.

Also the PV does not put out constant 12V if you think it will be the 12V supply, a PV cell is a current generator not a voltage generator.

Tom.

luxy:
Btw, voltage won't be exactly 12V (i put this value for easier explanation) but i am measuring it all the time through another voltage divider. I am planning to include that "voltage reading" in my equation for more precise calculation. Could this work like that?

I know voltage won't be 12V. I said it for easier explanation..

Is there any other way to get correct readings from thermistor and supplying everything from PV module through 3 wires?

Maybe your best option is to calibrate it. Assuming the thermistor is pretty linear, you can use one map() command, once you have done a few sample readings.

luxy:
The problem is that i am developing this solar regulator for already prepared conditions (not by me, ofcourse). On the roof there is a photovoltaic module (for supplying the whole circuit) and one thermistor. Basicly i would use 4 wires for that (2 for PV module and 2 for thermistor) but there are only 3 wires in cable (which is already installed and brought to the roof). Because of that i must use one wire as common for both. Systems on the roof are also already connected like this: one wire for PV module minus, second wire for thermistors minus and third wire as common plus. That means that thermistor's supply is the same as voltage on PV module.

Could you hook the thermistor to PV module minus? Then that could be used as a common Ground. The 1K bias resistor would then connect to +5 instead of Ground and the voltage ratio would be inverted but you wouldn't have to worry about frying the input or using an unregulated voltage source.

johnwasser:
Could you hook the thermistor to PV module minus? Then that could be used as a common Ground. The 1K bias resistor would then connect to +5 instead of Ground and the voltage ratio would be inverted but you wouldn’t have to worry about frying the input or using an unregulated voltage source.

That was my first idea to. Problem is that everything on the roof is “sealed” in UV protected isolation and if that’s won’t be really necessary i don’t want to cut and open it. Ofcourse, if that’s the only solution i will have to.

Btw, about first idea with common plus… If i would use two divider resistors (to get max 4V on input) and measure voltage of PV module with another voltage divider all the time and put that result in equation… Could this work or deviations would be too high?

Hi, I gather you are building a regulator as well.

The problem is that i am developing this solar regulator

If so which side of the PV will you be disconnecting from the batteries when they are at max charge,high side or low side?
As I said before you are using one wire of your thermistor as the same wire that the PV array will be driving current. The potential difference from one end to the other of that wire will vary with charge current , thus causing changes in your potential at the thermistor / resitor junction. So your temperature calculations will be invalid.

The only way you can do it will be to momentarily stop PV charging and measure your potential difference for the thermistor with no charging current.
Then go back to charging.

Tom

luxy:
Btw, about first idea with common plus.. If i would use two divider resistors (to get max 4V on input) and measure voltage of PV module with another voltage divider all the time and put that result in equation.. Could this work or deviations would be too high?

Yes, that will work. See attached schematic. The capacitors (I suggest 1uF ceramic) help keep the voltage steady between reading the reference voltage on A0 and reading the thermistor voltage on A1. Take these two readings one immediately after the other. The thermistor resistance is:

Rt = (A0 * (R1 + R2))/A1 - (R1 + R2)

where A0 and A1 are the values returned by analogRead. Choose R2 to be about twice R1 so as to limit the voltage at the analog inputs to less than 5V, for example 2.2K and 1K.

TomGeorge:
If so which side of the PV will you be disconnecting from the batteries when they are at max charge,high side or low side?

I am not charging batteries. PV module is direct power source for this solar regulator and pump.

dc42:
Yes, that will work. See attached schematic.

Great! I will try that and report.. Thank you!

dc42:
The thermistor resistance is:

Rt = (A0 * (R1 + R2))/A1 - (R1 + R2)

where A0 and A1 are the values returned by analogRead. Choose R2 to be about twice R1 so as to limit the voltage at the analog inputs to less than 5V, for example 2.2K and 1K.

Hello,

i finaly found time to test this. I connected everything like you draw on scheme with 2,2k and 1k resistor and 12V for supply.

First i used upper equation "Rt = (A0 * 3200) / A1 - 3200" but i get resistance about -3200 ohms. Probably is something wrong with these equation. I don't know how to change your formula and where to put voltage reference.

``````#define B 3950     // B = Thermistor B parameter (3950, datasheet)
#define T0 298.15  // T0 = 298,15
#define Ra 10000   // Ra = 10000 ohms

float R1,T1;
int temp1;
float voltage;
float Rt;

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

void loop()
{

voltage = ((A0 / 1024.0) * 14.5);

Rt = (A0 * 3200) / A1 - 3200;

// Steinhart-Hart
T1 = 1.0 / (1.0 / T0 + (1.0 / B) * log(Rt / Ra));

temp1 = T1 - 273.15;

delay(500);

}
``````

I suggest you check your wiring. You might also like to print the values of A0 and A1. The only way you can get -3200 ohms is for A0 to be 0, however in the circuit I gave, A0 will always be greater than or equal to A1.

The voltage doesn't come into the equation.

dc42:
I suggest you check your wiring.

Hello,

i fixed it Wiring was ok.. The problem was in variable declaration. I changed it from int to unsigned long and now it's ok. I tested it with changing voltage from 5-12V and after first tests results was ok (about +/- 1 degree when changing).

Now i will test it with PV module (voltage from about 14-24V most of the time). I will change resistors values to 6,8k and 1k.

luxy:
The problem was in variable declaration. I changed it from int to unsigned long and now it's ok.

I should have spotted that! The expression: "(A0 * 3200)" is likely to overflow if A0 is an int. My suggestion would be to leave A0, A1 as int and change the line to "Rt = ((float)A0 * 3200.0) / (float)A1 - 3200.0;".

dc42:
My suggestion would be to leave A0, A1 as int and change the line to "Rt = ((float)A0 * 3200.0) / (float)A1 - 3200.0;".

Ok, i will change it and test it.

About resistors values.. I think 6,8k and 1k will be ok, since max voltage on the PV module is about 24V (if i calculated it correctly and consider safe are).

luxy:
About resistors values.. I think 6,8k and 1k will be ok, since max voltage on the PV module is about 24V (if i calculated it correctly and consider safe are).

At 24V, with 6.8K and 1k the maximum voltage on the analog inputs will be about 3.1V. So those values are OK.

If i understand it correctly, for better accuracy is the best that values at maximum voltage (24V in my case) are near to the 5V (about 4,5V max) on the microcontroller input, since measuring area is bigger. Is that correct?

So if i would use resistors with 3,9k and 1k, max value on analog input at 24V will be around 4,9V. Is smart to get so close to the limit?