DS18b20 Order of sensors on a cable

I have a string of 10x DS18b20 sensors on a single two wire line (parasitic power). Below is a table of the sensors, Where they are located on the wire, and in what order where they discovered.

``````Serial              Order on wire*   Order discovered
286305560100002c    1                7
28a158610100006a    2                3
289b426101000089    5                8
28cd1161010000ce    6                5
2864026101000030    7                1
280c766101000026    8                2
``````

I read this document on how the OneWire discovers sensors on the bus. https://www.maximintegrated.com/en/app-notes/index.mvp/id/187

My question: Is there a way to detect the order of the sensors on a wire?

• I don't think so. There is nothing different between the different sensor, other than a minute difference in resistance in the wire, due to a longer length. – Gerben Feb 1 '17 at 14:55
• The discovery order is according to the search algorithm (which depends on the ROM/ID number). You can either put the sensors in order when you have their ID or use a mapping table in your sketch. The search algorithm does not determine the physical order of the sensors. – Mikael Patel Feb 1 '17 at 20:19

There is no way to detect position on the bus because all devices are connected in parallel. This is why a serial or "chain" wire, added to the newer devices, is required.

(To complicate matters, what is the "order of devices" - or even the meaning of "order" in a center-fed bus, or a circular, star, or other branched network? Order is just something we perceive when looking at an end-fed linear network. Electrons don't care. Think of a capacitor (unfortunately, the bus behaves like one but that's another story) with two plates, several centimeters square, and a dozen 1-wire devices connected from plate to plate. Now what is their order? Ow, my brain hurts! Let's go back to linear buses.)

The discovery order is a function of the set of binary device IDs on the bus. There are two ways I know of to come to know the physical ordering, both empirical (i.e., by observation):

1. Connect the set of devices one at a time, to a temporary bus such as a breadboard. With an Arduino, read the their IDs and tag them (human readable). With knowledge of the discovery alogrithm, or by running actual discovery on an Arduino with all devices connected, write down the IDs in the order they are discovered which is invariant for a given set of device IDs. Assemble your wired bus with the devices in this order.

2. (The reverse of 1 and quicker to build, and is what you've already shown in your question: Wire the bus. With a simple Arduino program, repeatedly sample all devices on the bus and report print their indices and temperatures (the indices will be in discovery order). One at a time, warm each device with your hand and notice which device index is affected. Write down the physical position (first, second, ...) and the index. This is the mapping table between position and index. Include it in your control algorithm.

• So I would say that the DS1820 for professional use is useless! There is no simple way to add or replace a sensor on existing temperature measuring appliance and to be sure about what are you measuring. Am I right? – Satman Feb 20 '18 at 20:16
• @Satman Sometimes the sensors don't respond anyway, so what you might think as sensor 3 would become sensor 2 if sensor 2 didn't respond. I wouldn't say they are useless, but you would need to know the sensor ID (something you might find out on the bench) before deploying it into the field. Using the ID would be much more accurate anyway, because then you are certain that you got a certain sensor, and not just because it happens to be 5th in a chain. – Nick Gammon Feb 21 '18 at 0:23

I found this application note.

APPLICATION NOTE 4037
Regain Location Information by Leveraging the 1-Wire® Chain Function—A Simple Signaling and Protocol Method Determines Device Physical Location

https://www.maximintegrated.com/en/app-notes/index.mvp/id/4037

• Note that 1) this technique is not applicable to DS18b20 and similar 1-wire devices; and the new devices - when using this capability - are not 1-wire any more, the chained signal requiring another conductor. – JRobert Feb 4 '17 at 1:11

what you can apparently do is use the User Data space set aside for the alarm and add an ID in there. I have not done this yet but am looking at this option as my sensor array has over 40 sensors in a line and ideally I would like the top one to be 0 and the last one in the chain to be 40.