Learning more about DS18B20 temperature sensor; some possibilities.

In using the DS18B20 for a couple of projects I have mostly used software snippets from others, accepting the compromises that entails; but now it's about time I took control and wrote my own code to get the best out of them.

I have read the datasheet from Maxim, though I confess I didn't understand much of it. It did prompt a few questions, and I hope you learned folk will help me with them.

  1. The CONVERT command. Does issuing this command make every DS18B20 on the network do a temperature conversion?

  2. During conversion would the network be 'tied-up' until the last sensor had finished?
    //Background: I want to use 6 sensors, five at 10 bit resolution, one at 12 bit.

  3. Once conversion had finished would each hold its value in its scratchpad area? If no further commands were issued by the master would that value be held (almost) permanently?

  4. Is it practical to issue a more frequent CONVERT command to an individual sensor? In doing this would all the remaining sensors retain their last readings in their scratchpads?
    //Background. One sensor is used in a control loop, and needs 0.1 C resolution (so 12 bits) and to be reliably read and acted upon every 2 seconds. The other 5 sensors are room air temperature only, 0.5C resolution, and may be read much less frequently (9 bits).

  5. The datasheet makes claims of suitability for 'industrial applications'. Does this imply they will tolerate noisy electrical environments, and operate reliably over tens of metres of cable?

TIA
GM

  1. You can sent CONVERT command either to one particular sensor or to all of them at once.
  2. No. COnversion is an internal operation and you can issue any other command during it. even to the same sensor.\
  3. Yes.
  4. It depend on your case. Have not enough details to suggest anything. . BTW frequent conversion can cause sensor self heating in some cases. And while it has around 0.1 resolution accuracy is much lower.
  5. Define "noisy environment". Yes it can work on tenth or even hundred meters but you should take care about bus topology. Guidelines for Reliable Long Line 1-Wire Networks | Analog Devices

Please be aware that virtually all DS18B20 sold on Amazon, eBay, Aliexpress etc are counterfeit. Only official distributors has an original DS18B20 (DigiKey, Mouser, Arrows etc)

Glorymill:
In using the DS18B20 for a couple of projects I have mostly used software snippets from others, accepting the compromises that entails; but now it's about time I took control and wrote my own code to get the best out of them.

I have read the datasheet from Maxim, though I confess I didn't understand much of it. It did prompt a few questions, and I hope you learned folk will help me with them.

  1. The CONVERT command. Does issuing this command make every DS18B20 on the network do a temperature conversion?

Depends if you use MATCH ROM or SKIP ROM - the former is needed when multiple devices are on the bus.
So that only one is enabled to respond.

  1. During conversion would the network be 'tied-up' until the last sensor had finished?

No, you can talk to any sensors during that time, its a non-blocking protocol, but note that the
delay till the result is ready is something the bus master has to keep track of.

//Background: I want to use 6 sensors, five at 10 bit resolution, one at 12 bit.

Then use them that way, you've got to give addresses (ie use MATCH ROM) for all
the comms - the DallasTemperature library has functions to do this IIRC.

  1. Once conversion had finished would each hold its value in its scratchpad area? If no further commands were issued by the master would that value be held (almost) permanently?

The sensors store the last conversion result until a new conversion or the power goes away.

  1. Is it practical to issue a more frequent CONVERT command to an individual sensor? In doing this would all the remaining sensors retain their last readings in their scratchpads?

They are separate devices on a bus - so long as you remember to address devices they are independent
other than that they compete for time on the bus

//Background. One sensor is used in a control loop, and needs 0.1 C resolution (so 12 bits) and to be reliably read and acted upon every 2 seconds. The other 5 sensors are room air temperature only, 0.5C resolution, and may be read much less frequently (9 bits).

If they are read infrequently you might as well use 12 bits throughout as the 0.75s delay isn't of concern.

  1. The datasheet makes claims of suitability for 'industrial applications'. Does this imply they will tolerate noisy electrical environments, and operate reliably over tens of metres of cable?

TIA
GM

Use decoupling capacitors on each sensor, do not use parasite power, and use twisted pairs for:
1 power+ground
2 data+ground

Then yes, it should be pretty robust. Add shielding if heavy EMI is present, grounded only at the Arduino
end. Never ground sensors at the mounting point if you can avoid it, that's a recipe for ground loops.

Use 4k7 pull-up resistor on the bus, perhaps one at each end on long wires (ie 2k35 net value).

DS18B20's on eBay etc are generally fakes - buy them from reputable electronics stockists only.

alesam:
And while it has around 0.1 resolution accuracy is much lower.

The resolution is 0.0625C, I measured the standard deviation for a set of a dozen or so
devices I measured at < 0.1C (at room temperature), so the repeatability is very good.

For absolute accuracy I don't know, but its likely to be similar in magnitude to the repeatability at
room temperature and deviate more at more extreme temperatures. The datasheet has
a typical performance curve with +/- 3 s.d. lines given showing the trends.

Remember these devices are laser trimmed in the factory, presumably at 25.0C so the
room-temperature performance is likely to be well characterized.

People often don't understand how to use temperature sensors precisely - air currents in typical
rooms fluctuate in temperature much more then 0.1C, and heat radiation from your body falling
on a black epoxy device will also heat it > 0.1C easily - I've seen on several occasions people
saying they read a degree or two high sitting on a breadboard as they sit in front of it... Yes,
that's probably heat radiation, or perhaps some self-heating as well.

For best accuracy you'll need to use forced airflow, or put the sensor in a metal tube to prevent
it absorbing heat radiation. The device itself is not usually the main source of error.

I've got 5 DS18B20 directly from Maxim and put them between two aluminum bars close to each other. Then left them for a night wile logging temperature every 5 sec. Maximum temp difference between sensors was around 0.5C

  1. Not typically. There is a rather opaque and highly technical treatise on DS18B20 on long cables somewhere around. Good luck with that. A fair proportion of the discussion on DS18B20 around here is about grief with long cable runs, but there is plenty of it.... The general view is that you cannot afford to be cheapskate. I believe that those sensors that come on a cable have 5m at most. Adding 2m of cheap cable to mine with 3m was fatal. CAT5 is commonly used for cable. The longer the cable run you consider, the greater the motivation to not use cable.

Hi,

Lots of good info here @MarkT and others... Thanks! Couple of comments:

Please be aware that virtually all DS18B20 sold on Amazon, eBay, Aliexpress etc are counterfeit. Only official distributors has an original DS18B20 (DigiKey, Mouser, Arrows etc)

This can be a problem. I have DS18B20 sensors with stainless steel ends on cables up to 10M, made by a reputable factory in Shenzhen we have a personal relationship with. They guarantee the chips are genuine. I have sold over 5000 of these to industrial and hobbyist customers over 5 years now with no problems. For a while I insisted on unencapsulated samples from each batch of 500 or so. They passed the Fake Test. There are two clone chips I have seen; one is actually pretty good.

I have personally used a few of the 10M cabled sensors here to my swimming pool, solar heater , indoor and cellar and outdoor air temperatures. (I just got back from a 6-week camper road trip, and it was reassuring to remotely check the temperatures in our log cabin in Vermont each day!) I have logged months of data with zero failed values. Over a year I did have one instance of the (-large value) fail. That is a pain when you have automatically-scaled graphs! I was going to code a protection to reject that (still on to-do list)..

I have a lot of DS18B20 stuff on ArduinoInfo.Info HERE I will abstract some of the details here to update that... THANKS!

MarkT:
For absolute accuracy I don't know.....

....People often don't understand how to use temperature sensors precisely...

...The device itself is not usually the main source of error.

Thanks for your reply, though I am not so much interested in accuracy as I am in repeatability. To put this into context, the 12 bit precision sensor is the one that will report back to the PID control block, so to achieve +- 1oC control regulation of wet central heating water at around 70oC I will need a resolution of 0.1 to allow the proportional control to do its stuff in good time (no pun intended). With the DS18B20 spec showing 0.5oC accuracy there is no way any control system could improve on that. Of most importance is that, whatever arbitrary temperature I set the boiler to, it'll produce a stable output temperature, and I don't really mind if the National Physical Laboratory tells me it's 2 degrees out, as long as it's 2 degrees out every time.
PS it's an electric flow boiler with burst fire power control.
The 10 bit precision sensors will be used to measure outside temperature, three room temperatures, and stored hot water temperatures, so a precision of half a degree is quite adequate as they will not be used within the control strategy (at this stage!)

To conclude, I thank you all for your clear answers on the technical stuff. With that info I can better plan my next software writing mission and build on what I have learned. You are, as a 'community', a great asset and I appreciate that.

alesam:
I've got 5 DS18B20 directly from Maxim and put them between two aluminum bars close to each other. Then left them for a night wile logging temperature every 5 sec. Maximum temp difference between sensors was around 0.5C

That's air currents and heat radiation I suspect - they are big effects, several C difference is easily attainable
if one sensor is screened from a heat source optically and another isn't. Tungsten lighting
and human bodies and radiators are typical sources of heat radiation.

Aluminium (unless anodized or painted) reflects heat radiation very efficiently.

A good NTC would offer more accurate, repeatable, and less hysteresis then the device suggesed here. By their own data sheet the DS18B20 reads with an accuracy of ±0.5°C from -10°C to +85°C, so reading it with high resolution only implies an accuracy that isn't there. A good NTC can get to +0.1°C accuracy, and if a common value like a 10KΩ interchangeable is used, wire length isn't really an issue as its resistance is significantly less than the thermistor if you use something like 1mm² conductor. Oddly enough that is what the building trade uses for their control systems and they run up to 100m of wire (usually something like Belden 8760 screen earthed at controller end).

Calculation is then a Steinhart Hart equation with a balance resistor at the controller end into an anlogue input.

Digital temperature sensors were only ever designed to be used where terminal space, or multiple local temperatures need be inegrated into a space, or no A/D converter is unavailable, none of which appear to apply to the examples in the thread. They have their place in the market, but that place doesn't appear to be here!