Reading NTC and convert to temperature

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Reading NTC and convert to temperature

#1 Post by martinus » 14 Jan 2024, 11:37

Last year during spring, the controller unit for my Solar Water Heater(Zonneboiler) has given up after 30 years of operation. As the company went broke in 2015, no spares, no support.
Zonneboiler.png
Zonneboiler.png (294.63 KiB) Viewed 5388 times
So i decide to replace the controller with an ESP32 driven solution. Just added a relay board to control the pump and replaced the boiler vessel temperature sensor with a DS18B20 version sensor.
That part was easy. But the sun collector temperature sensor is just inreachable unless i go up to the roof from the outside. So i tried to read the the NTC sensor from the collector using an analog port on the ESP32. It has worked quite ok during the summer, but the temperature readings do not really match the actual temperature on the entire range.
I just used a simple formula that seems to work quite reasonable for ranges from 30-100 degrees. Actually sufficient for this system as temperatures below 30 degrees have no use to startup the system.

But it would be nice to get actual correct readings from the NTC.
I just hooked up the NTC between VCC and the analog input and tied a pull down resistor to ground.
And just devided the analog reading by 29 (experimental value) to get something that matched at 50 degrees.
But i likely need a more sophisticated formula.

Maybe someone has used an NTC before and has a proper solution/formula to convert the analog reading to the actual temperature?

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Reading NTC and convert to temperature

#2 Post by martinus » 14 Jan 2024, 13:46

Also getting irregular readings at low temperature (around 5 degrees). Analog values are approx 200 milliVolts now but fluctuating a lot. Hooked up a scope to see what is going on.
SensorNoise.png
SensorNoise.png (736.08 KiB) Viewed 5324 times
Seems quite some 50 Hz noise on the line (not on VCC feed), so the long wire to the NTC at the roof must pickup some powerline noise, maybe from the Solar Panel microinverters that are close to it.
Maybe need to check again when it's dark outside ;)

A capacitor will likely be able to filter out that noise.
Also noticed that ESP32 ADC values are not really matching actual voltage, especially at the low end range. When i hook up an Arduino Nano, those ADC readings really match to the ones obtained from a proper multimeter.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Reading NTC and convert to temperature

#3 Post by TD-er » 14 Jan 2024, 13:54

You could install a recent ESPEasy build to see how the P002 ADC can be addressed using built-in calibration and attenuation factors.
Then you will see the ESP32 doesn't go all the way to 0V.
With calibration enabled, you have the output in (m)Volt.

Anyway running an NTC over long wires is a bad idea as you either will pick up lots of noise, or you need to put more current through it which will heat up the NTC.
Why not use a DS18b20? Those can be used over quite long wire.

Or you need to setup a Wheatstone resistor bridge to calculate the unknown resistor and use twisted wire to cancel out any noise.

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Reading NTC and convert to temperature

#4 Post by martinus » 14 Jan 2024, 14:31

TD-er wrote: 14 Jan 2024, 13:54 Anyway running an NTC over long wires is a bad idea as you either will pick up lots of noise
I would have replaced it if i would be able to access it without climbing up on the roof and see where it is mounted. I have no access from the attic to it.

And back in 1992 they mounted it with three meters of plain wire.

I have added a "Mini Pro extender" to the solution using the PME plugin. Will see how both measurements compare over time. A small capacitor filters the noise quite well.

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Reading NTC and convert to temperature

#5 Post by TD-er » 14 Jan 2024, 14:43

Maybe you can also add some transistor to it, to make sure there isn't any current through the NTC while not measuring.
So it doesn't heat up on its own.
And while you're at it, it is best to measure the resistance using a constant current instead of a voltage.
Then the voltage you measure is directly proportional to the resistance.
Maybe add some resistor in series so you're not at the lower end of the ADC.
MEasuring voltage over a NTC is really hard to measure, but wiring up a LM317 as constant current is making things a lot easier.

martinus
Normal user
Posts: 129
Joined: 15 Feb 2020, 16:57

Re: Reading NTC and convert to temperature

#6 Post by martinus » 04 Feb 2024, 14:13

We have had some sunny days lately, so i was able to verify the new formula that i've found on the internet to calculate NTC resistance into actual temperatures:

Code: Select all

//********************************************************************************************
// Calculate Celsius from NTC analog reading
//********************************************************************************************
float ntc(int Ro, int Rseries, int B, int analog){
  float To = 298.15;                                // Nominal Temperature in kelvin
  float Vi = (4096-analog) * (3.3 / 4096);          // Calculate actual input voltage from analog value reading
  float R = (Vi * Rseries) / (3.3 - Vi);            //Convert voltage measured to resistance value, all Resistance are in kilo ohms.
  float T =  1 / ((1 / To) + ((log(R / Ro)) / B));  // Use R value in steinhart and hart equation, calculate temperature value in kelvin
  float Tc = T - 273.15;                            // Converting kelvin to celsius
  return Tc;
}
Using the Pro Mini Extender and the new formula, i get much more accurate results now for the collector temperature readings.

Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests