Multiple DS18B20 sensors on one digital pin?

Hello I'm just trying to understand how does the arduino and coding know there there are multiple ds18b20 using One pin? What i mean is how does it work using just a single digial wire pin? Just trying to understand this.

Joseph

It uses the one wire bus, for which the DS18B20 is specifically designed. They are a lot more than just a sensor, each has its own unique address enabling them to respond when Arduino addresses them.

Arduino has other common busses to ride.

One wire enables you to use a lot of the same thing, like DS18B20
I2C enables you to use different devices, like a clock and a display
SPI enables you both ways, as each device has a unique selector pin

Here is a short explanation: Reading and Writing 1-Wire® Devices Through Serial Interfaces | Analog Devices.
I can not find a better explanation at maxim integrated.

A 'reset' is put on the bus, and that enables the controller to find all the devices. Every sensor has a 64-bit unique identifier.
See the part where the communication protocol is explaned: 1-Wire - Wikipedia
If you understand it fully after reading that, then you understand it better than I do :confused:
If you want a simple explanation, well, there is no simple explanation. It is a ingenious protocol.

Keopel thank you for the information i try to read it and it kinda went past my head a little. But from what i can understand is that it looks like the way it can tell what sensor is what looks like a Unique id number like a mac address. That to me is just the basic how i can understand it. Hello Nick_Pyner thank you also. I 'm trying to read things but it will take me forever to read and longer to understand it. Thank you both for helping me. I'm starting to figure things out.

Joseph

It's not that hard, but it might help if you "do" while you "read". Note the Hacktronics tutorial has two Arduino programmes, one to read the sensors" addresses, and the other to use the sensors. Some sticky labels and a pencil helps here...

The Wikipedia article on 1-wire might be an easier introductory read. Under the "Communication Protocol" section there is an explanation of device addresses and the principle behind the enumeration protocol under which the address and type of all devices on the bus are discovered.

There's no need to understand how it works if you just want to use some of them. The library takes care of the details for you.

If you do want a better idea of what's happening, reading the library code will give you some hints.

With a single wire driven as an open collector bus its possible to enumerate a large
number of devices using the fact that a line actively driven low means no devices
are outputing HIGH - so when you ask all devices to identify themselves by the first bit
you can tell that:

a) no devices have that bit LOW (or there are no devices)
or
b) some devices have that bit LOW

Given that information you ask for the next bit having previously told the one's
with the first bit HIGH to shut up.
And then (optionally) you ask for the second bit again having told any with the first bit LOW
to shut up.

That tells you more. In particular you rule out whole swathes of address space
and narrow down to the actual set of identifiers.

Eventually after progressing through all the bits of the identifier, and under the
assumption that all attached devices have unique identifiers, you can enumerate
all the identifiers on the system efficiently, even if there are 2^64 possible
identifiers/addresses.

Thereafter you simply do targeted requests by identifier to talk to one device at a time.

The protocol allows you to specify an arbitrary subset of bits be wild-carded in a
request, which is what allows control of who answers by individual bit.

[ aside: a similar identification protocol is used in the MBUS smart-meter system ]

Hi, josephchrzempiec,

I have tried to explain 'layman style' how the DS18B20 communicates with an duinoi in a post on my Arduino blog:

There is also an example DS18B20 address finding sketch and a temperature sensing sketch. You can attach a lot of DS18B20 sensors to one pin. In one application I have 10 sensors reporting via one wire and one pin!

see: The DS18B20 temperature sensor – implementation with an Arduino – thesolaruniverse
success, photoncatcher

Its probably a good idea to add a decoupling cap on the supply at each sensor for extra stable
power if you can when mounted remotely on a cable.

An application note for this sensor (AN-148) also makes a strong distinction between different sensor connection topologies, in the context of reliable operation with longish cable runs. It specifically discourages "star" topology (all sensor lines branching off from a single node).
The link to the app note is a mile long, but easily found by Googling "AN-148 application note"
S.

This is the mile long link: https://pdfserv.maximintegrated.com/en/an/AN148.pdf
You can shorten it it to: AN148 Guidelines for Reliable Long Line 1-Wire Networks.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.