Author Topic: How to Interface 108 Thermistors with Arduino  (Read 3568 times)

0 Members and 1 Guest are viewing this topic.

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 4837
  • Country: nl
Re: How to Interface 108 Thermistors with Arduino
« Reply #25 on: February 13, 2025, 08:17:52 pm »
For 1 wire I can advice to make use of the DS2482 to make the 8 busses Siwastaja mentioned.

It uses I2C for communication with the MCU.

I have used it in my central heating system with 88 DS18B20 sensors. The software I used was owfs on a Linux bases Raspberry PI 2B. No idea if this is also available to run on an Arduino based device.

This, but divide them into a few buses. 1-Wire bus depends on high speed (microsecond timing), and capacitance of long wires / many tens of devices is simply too much. (For some reason I never understood, it is marketed as if it was fine with hundreds of devices and tens of meters of wire, but at least I can't make it work reliably in such extreme setups :-//)

I have managed to make it work without problems with up to 20 devices on a single bus and line lengths of more than 10 meters. I made optocoupler and DC-DC converter based galvanic separations between the Raspberry PI connected DS2482 and the actual sensors. Took a lot of tweaking on the circuit to make it work, but was able to have it still work reliable with at least 90 meters of cat 5 utp cable, where I used three wires. 5V, ground and signal. The ground and signal using a twisted pair.

I recommend providing the third wire for external power for 1-Wire sensors.

This also speeds up the scanning process when multiple sensors are on the bus and makes it work more reliable.

Online PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 2220
  • Country: au
Re: How to Interface 108 Thermistors with Arduino
« Reply #26 on: February 13, 2025, 10:16:46 pm »
Max would be 1.5 m; its in a battery pack, and we would just want this to be a temporary solution. The actual plan is to use CAN communication, but for now we would need to use an arduino.

The LIN bus may be easier than CAN?

Was thinking about the same; just wanted to know if there is a better solution Looks like I'll end up going for analog multiplexers.
I found this on TI's website: [CD74HCx4067][https://www.ti.com/lit/ds/symlink/cd74hc4067.pdf], will this do the job?
Yes, sure, a couple of those will do a 16x16 matrix, using 8 MCU pins to select and an ADC to read. Fine for a temporary solution.

 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 13364
  • Country: ch
Re: How to Interface 108 Thermistors with Arduino
« Reply #27 on: February 14, 2025, 01:07:14 pm »
Do they have to be thermistors? Or could you just use a bunch of DS18B20-style temperature sensors on a single 1-Wire bus?

This, but divide them into a few buses. 1-Wire bus depends on high speed (microsecond timing), and capacitance of long wires / many tens of devices is simply too much. (For some reason I never understood, it is marketed as if it was fine with hundreds of devices and tens of meters of wire, but at least I can't make it work reliably in such extreme setups :-//)

But e.g. 14 sensors per bus * 8 buses should work, and you can just use any 1-Wire library on Arduino and re-init it to use different IO pins (and you easily can have 8 IO pins for this).

I recommend providing the third wire for external power for 1-Wire sensors.
OP said maximum 1.5m, so splitting into multiple buses might not even be necessary.
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3432
  • Country: us
Re: How to Interface 108 Thermistors with Arduino
« Reply #28 on: February 14, 2025, 04:18:05 pm »
Based on the datasheet:

https://www.analog.com/media/en/technical-documentation/data-sheets/DS18B20.pdf

it seems it takes about 20 bytes of communication just to read the temperature from one sensor.

The transmission speed of 1-wire is 16.6K bits/second (each bit takes 60us) so if all 108 sensors were on a single bus it would take about 1 second to get all the readings:

108*20*8 = 17280 bits

In any case, the conversion time is 90ms on the lowest resolution (see Table 2 in the datasheet) which limits the sample rate to about 10 samples per second at most.
 

Offline pcprogrammer

  • Super Contributor
  • ***
  • Posts: 4837
  • Country: nl
Re: How to Interface 108 Thermistors with Arduino
« Reply #29 on: February 14, 2025, 05:04:25 pm »
Temperatures normally do not vary that fast. Not sure about what it is like within a battery pack, but I suspect that within normal use it will not matter that much if a reading is only once a second.

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 9531
  • Country: fi
Re: How to Interface 108 Thermistors with Arduino
« Reply #30 on: February 14, 2025, 07:42:04 pm »
OP said maximum 1.5m, so splitting into multiple buses might not even be necessary.

In this case not because of wire length, but because of the number of sensors.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 9531
  • Country: fi
Re: How to Interface 108 Thermistors with Arduino
« Reply #31 on: February 14, 2025, 07:43:14 pm »
Temperatures normally do not vary that fast. Not sure about what it is like within a battery pack, but I suspect that within normal use it will not matter that much if a reading is only once a second.

One reading every 30 seconds is definitely more than enough for a battery pack. Even the sensors themselves have enough thermal mass that nothing happens at <15 second level.
 

Offline mino-fm

  • Regular Contributor
  • *
  • Posts: 157
  • Country: de
Re: How to Interface 108 Thermistors with Arduino
« Reply #32 on: February 15, 2025, 10:39:25 am »
Ten years ago I used Arduino UNO R3 to sample up to 6 x KTY81 as shown below.
PB.0 is activated with 0.1 s period for <= 1 ms until all channels are read. A duty ratio of 1:100 will avoid internal heating of sensors. Ratiometric measurements don't care about absolute value of Vref.

Today I would use a STM32G0xy for >= 8 input channels with 12 bits of resolution and about 11 ENOB. Because of stable HSI clock no external resonator or crystal is required.
 

Offline pqass

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: ca
Re: How to Interface 108 Thermistors with Arduino
« Reply #33 on: February 15, 2025, 03:13:52 pm »
I don't think anyone has mentioned it so far but input conditioning should be used to position the signal such that the entire ADC range is used.

For example, between -10°C to +50°C, the KTY81/110 returns 747R to 1209R and 1000R at 25°C if the sensor is provided with 1mA.  Assuming a 1000R bias resistor and 2Vref, then the mid-point of the divider only moves between 860mV and 1090mV or between 438 and 560 in (10 bit) ADC values without any range maximization.  Unfortunately, the ATmega328 only provides a 1.1Vref which is 0.55mA to the sensor thus the resistances in Table 7 of the PDF will be different.

Whether a diode (-2.2mV/°C) or diode-connected-transistor (-???mV/°C) is used instead, ADC range maximization should still be needed.
See "Using a 2n2222 as Temp. Sensor" here.  A summing amplifier is used to sum the raw signal with a counter voltage (via offset pot) to position the 0°C point and gain (via feed-back pot) to maximize the output range.  Although, you probably can remove the need for a negative offset adjustment voltage if you position 0°C to be up at a 1/6th of the Vref.

Also, the sensor may not be linear so you'll have to compensate via lookup table or more complex formula.
« Last Edit: February 15, 2025, 03:16:27 pm by pqass »
 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15335
  • Country: de
Re: How to Interface 108 Thermistors with Arduino
« Reply #34 on: February 15, 2025, 04:14:29 pm »
There quite different thermistors. The KTY81 and similar are relatively linear. AFAIR they get about linear in in the voltage when combined with some 2.7 K.
So one could use 2.7 K to 5 V supply and than a divider to some 2 to 2.5 V for V ref. This way one gets a little more resolution, though still quite a bit of the ADC range not used.
The PTC with more exponential response give much more change in the resistance (e.g. 4.5% per K compared to some 0.6 % for the KTY81). This can be enough to get reasonable resolution (though a limited range) with only a resistor. The response is however nonlinear.

For a Diode as sensor one could use the 1.1 V reference and this way get some 0.5 K resolution from the usuaul 2.2 -mV/K and a 10 bit ADC. This is not great, but could still be good enough.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3311
  • Country: ca
Re: How to Interface 108 Thermistors with Arduino
« Reply #35 on: February 15, 2025, 04:33:52 pm »
I don't think anyone has mentioned it so far but input conditioning should be used to position the signal such that the entire ADC range is used.

Not really. A few years back I used NCU18XH103F60RB. I had no problems getting 0.5 degree resolution with simple voltage divider between the thermistor and a 10k resistor. My chip had a 12-bit ADC, so there wouldn't be a problem to get 0.1 degree resolution. For batteries, 1 degree is probably enough, which you can get even with an 8-bit ADC.

For batteries it is more important to ensure good thermistor placement, so that it measures the temperature of the battery, not the surroundings. Otherwise, you can easily get several degree error.
 

Offline mino-fm

  • Regular Contributor
  • *
  • Posts: 157
  • Country: de
Re: How to Interface 108 Thermistors with Arduino
« Reply #36 on: February 15, 2025, 05:12:42 pm »
Unfortunately, the ATmega328 only provides a 1.1Vref which is 0.55mA to the sensor

PB.0 is used as output to supply the sensor dividers. Vref is input and supplied by PB.0 output too, maybe 4.5 V.
As told before, today I would use a controller with 12 bit ADC still not knowing what is really needed.
 

Offline Siwastaja

  • Super Contributor
  • ***
  • Posts: 9531
  • Country: fi
Re: How to Interface 108 Thermistors with Arduino
« Reply #37 on: February 15, 2025, 06:11:20 pm »
I don't think anyone has mentioned it so far but input conditioning should be used to position the signal such that the entire ADC range is used.

Not really.

I agree. Nowadays 12-, even 14-bit ADCs integrated into MCUs are cheap and very linear. By careful analog design you could extract maybe 1-2 more bits of dynamic range. But because it is rarely a limiting factor anyway, this effort is wasted. Scaling values in software is trivial, and you need to do it anyway.

If you try to do as qpass says and use the "entire range" of ADC, that would imply amplification, i.e., an opamp, which can then add new sources of inaccuracy, and unnecessary clipping if you later understand that you wanted 10degC more range.

Of course, one should pay some attention to how they e.g. choose a reference (pull-up or pull-down) resistor for an NTC. For example, for a 10kOhm NTC a 5kOhm fixed resistor works better than e.g. a 20 kOhm resistor when temperatures to be measured most accurately are in range of, say,  30 - 100 degC. Choosing a 100kOhm resistor would be then a bad idea. But all this does not take too many minutes to figure out in Excel; NTC manufacturers helpfully publish spreadsheets of resistances at different temperatures.
 

Offline pqass

  • Frequent Contributor
  • **
  • Posts: 981
  • Country: ca
Re: How to Interface 108 Thermistors with Arduino
« Reply #38 on: February 15, 2025, 06:16:05 pm »
Unfortunately, the ATmega328 only provides a 1.1Vref which is 0.55mA to the sensor

PB.0 is used as output to supply the sensor dividers. Vref is input and supplied by PB.0 output too, maybe 4.5 V.
As told before, today I would use a controller with 12 bit ADC still not knowing what is really needed.

I think using PB0 as an output and AREF (the Vref in/out) pin as input (ie. "analogReference(EXTERNAL)") to track its voltage is not much better than just connecting AREF to Vcc.   Using the AREF pin as an output (ie. "analogReference(INTERNAL)") would be quieter and independent of Vcc level without using the extra PB0 pin.  Although, it would be better to drive the thermistors via 2x opamp buffer that way the 1090mV to 860mV (+50°C to -10°C) divider mid-point fits nicely in the top quarter of the ADC range.  This still gives 0.26°C resolution without the offset+gain, per channel, that I proposed previously.

 

Offline Kleinstein

  • Super Contributor
  • ***
  • Posts: 15335
  • Country: de
Re: How to Interface 108 Thermistors with Arduino
« Reply #39 on: February 15, 2025, 07:31:27 pm »
...
Of course, one should pay some attention to how they e.g. choose a reference (pull-up or pull-down) resistor for an NTC. For example, for a 10kOhm NTC a 5kOhm fixed resistor works better than e.g. a 20 kOhm resistor when temperatures to be measured most accurately are in range of, say,  30 - 100 degC. Choosing a 100kOhm resistor would be then a bad idea. But all this does not take too many minutes to figure out in Excel; NTC manufacturers helpfully publish spreadsheets of resistances at different temperatures.
To get good signal swing from a resistive sensor it is usually better to have the series resistor larger than the sensor, not smaller. So 10 K sensor and 20 K of fixed resistor absolutely makes sense. This is especially the case when the ADC can use a reference that is smaller than the voltage driving the half bridge. Things can be different with highly nonlonear NTCs, that can change a lot from nominal resistance.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3311
  • Country: ca
Re: How to Interface 108 Thermistors with Arduino
« Reply #40 on: February 15, 2025, 10:10:06 pm »
To get good signal swing from a resistive sensor it is usually better to have the series resistor larger than the sensor, not smaller. So 10 K sensor and 20 K of fixed resistor absolutely makes sense. This is especially the case when the ADC can use a reference that is smaller than the voltage driving the half bridge. Things can be different with highly nonlonear NTCs, that can change a lot from nominal resistance.

The voltage on the ADC is

Vt = V*Rt/(Rt+Rh)

where

V is VDD
Rt is the resistance of the thermistor
Rh is the resistance of the high side resistor

We want to make Vt as much sensitive to Rt as we can. Thus, we calculate the sensitivity

S = dVt/dRt = VRh/(Rt + Rh)^2

We need to select Rh which maximizes S. The S function has one maximum which is obtained when the differential dS/dRh is zero.

dS/dRh = (V(Rt+Rh)^2 - VRh*2(Rt+Rh))/(Rt+Rh)^4 = V(Rt-Rh)/(Rt+Rh)^3

This is equal to zero when Rt = Rh. Hence, the best Rh is equal to the expected resistance of the thermistor Rt at prevalent temperatures.
 
The following users thanked this post: Siwastaja

Offline mikerj

  • Super Contributor
  • ***
  • Posts: 3424
  • Country: gb
Re: How to Interface 108 Thermistors with Arduino
« Reply #41 on: February 17, 2025, 10:51:20 am »
...
Of course, one should pay some attention to how they e.g. choose a reference (pull-up or pull-down) resistor for an NTC. For example, for a 10kOhm NTC a 5kOhm fixed resistor works better than e.g. a 20 kOhm resistor when temperatures to be measured most accurately are in range of, say,  30 - 100 degC. Choosing a 100kOhm resistor would be then a bad idea. But all this does not take too many minutes to figure out in Excel; NTC manufacturers helpfully publish spreadsheets of resistances at different temperatures.
To get good signal swing from a resistive sensor it is usually better to have the series resistor larger than the sensor, not smaller. So 10 K sensor and 20 K of fixed resistor absolutely makes sense. This is especially the case when the ADC can use a reference that is smaller than the voltage driving the half bridge. Things can be different with highly nonlonear NTCs, that can change a lot from nominal resistance.

All NTC thermistors are highly non-linear AFAIK, thus the challenge with getting a good curve fit over the full temperature range without a ridiculous number of terms, though linear PTC thermistors are available.  If the fixed resistor is reasonably close to the NTC resistance in the middle of the required temperature range this provides both a useful amount of linearisation and improves resolution (assuming it will be quantised by an ADC). 
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf