Connecting 20 DS18B20 in 1-wire

Hello,

I trying to connect 20 DS18B20 temperature sensors together (for a soil monitoring project). The sensors are the 3m cabled, waterproof versions of the DS18B20. I've connected all of them in parallel and am using an external source of power supply to power them (rather than powering them through the 5V pin on my Arduino Uno). The total cable weight/length is around 60.5m (20 x 3m + 0.5m for parallel wiring) and cable radius is 3.2m.

I've checked all of the sensors individually (and they all work fine) and hard-coded their addresses into the code to avoid having to search for their addresses every time I run the code.

Here's my issue. Let's say that sensor #1 is the one closest to the Arduino in the parallel circuit and sensor #20 is the farthest. When I only connect sensor #1 and read it, it works fine. But as soon as I connect the other 19 sensors, the reading immediately display -127C (ie. does not read).

So my question is, how do I make connect and read from 20 sensors?

It is probably about 1-wire bus reliability. Is it star config with 3m threads? Use the same length for each cable.

Read this:

My personal experience is that the 80-100ohm resistor on DS18B20 data pin can be usually helpful to reduce a reflection on branches.

Thanks for your quick reply.

More exactly, the sensors are connected in groups of 3 in star configuration. And each group of 3 is connected in parallel with each other. So I have 6 clusters with three sensors and 1 cluster with two sensors - all 7 clusters are connected in parallel with each other.

Just as long as the wire length to the closest sensor and the furthest sensot are about the same.

That means if the furthest sensor has 60 m of wite to it. Then the closest should too.

Sounds like you should create short med and long groups and use 3 pins and create groups of equal length. The 1wire is eady to duplicare on a second or third pin

Hi hashbrake
as said, a pullup resistor on the data pin is useful; if you have free pins on the UNO, separate the cables on 3, and even 7 pins, there should be no problem, as dave-in-nj said.
I would have put 3 probes (or 4) not in star, but in bus (3m and a probe, then 3m and another probe, then 3m and the last probe, with 4 or 5 pins of the arduino used for the probe cables), powered by the 5v of the arduino. But by separating the cables on different pins, you can keep your current topology

This seems like a great solution if it works. Although how would I modify my code (or duplicate as you said)?

Say that I'm using this code, how could I modify it to read sensors #1 and #2 on two different pins?

#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

// Addresses of 2 DS18B20s
uint8_t sensor1[8] = { 0x28, 0xEE, 0xD5, 0x64, 0x1A, 0x16, 0x02, 0xEC };
uint8_t sensor2[8] = { 0x28, 0x61, 0x64, 0x12, 0x3C, 0x7C, 0x2F, 0x27 };

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
}

void loop(void)
{
  sensors.requestTemperatures();
  
  Serial.print("Sensor 1: ");
  printTemperature(sensor1);
  
  Serial.print("Sensor 2: ");
  printTemperature(sensor2);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
}

What size pullup resistor are you using for the data line from the DS18B20's? The data input/output pin on the DS18B20 is open drain, so a pullup is required - not sure if the library uses the internal pullup on the arduino, but that would likely be too high resistance for reliable operation of multiple devices, 4.7K seems to be the common value used in examples.

I would not worry too much about powering the sensors from the arduino 5V supply, a DS18B20 draws a maximum of 1.5mA.

I'm using a 4.7k resistor as recommended. Although I read somewhere that when using cloned DS18B20s or long wires, using a lower resistor between 1k to 2.7k is better. So I will try that.

Hi,
Have you tried a delay between individual reads?
Give the one wire a chance along with the DS to read and write?

Just a thought.

Can you post a basic diagram showing the connections and distances of your sensor network, showing each star connection?

Tom.. :smiley: :+1: :coffee: :australia:

Start here

#define ONE_WIRE_BUS1 2
OneWire1 oneWire(ONE_WIRE_BUS1)

#define ONE_WIRE_BUS2 3
OneWire2 oneWire(ONE_WIRE_BUS2)

What is the maximum power out on one pin?

DallasTemperature sensors1(&oneWire1);

DallasTemperature sensors2(&oneWire2)

For the 5v pin, well in excess of the 30mA total needed if all 20 temperature sensors are active simultaneously. I was not contemplating providing power from an I/O pin, only eliminating a separate external supply, although an external 5v supply could be used to power both the arduino and temperature sensors.

which means to power the probes by the 5V taken from the arduino (Vcc pin); the probes consume up to 1.5 mA during the read/write time, which is very short, and if they are powered by a pin (and are not all on the same pin) and de-synchronized, they consume very little (a few uA in standby).
I sometimes powered the probes from a pin of the arduino configured as an output, but for another reason: to do a hard reset every 30 minutes (pin "5V" and data pin of the probe zeroed for 3 seconds), because on some applications, they were blocking (rarely) for a reason I still don't understand .

-the “water proof” ds18b20 aren’t* . If one fails it can stop the reading of all your sensors on the same bus , if all yours are buried there is a good chance one or more are now dead .

  • the steel tips are but not the cable connection

Why are you so worried? To make a Chinese probe waterproof, put a 30mm heat shrink tubing (adhesive is even better) on the metal-cable connection, and your probe is ip66 or more.
No, the even bare ds1820 can't be destroyed if they are accidently in water.

Hi @PatMax .

I use hot melt glue.

RV mineirin

Hi ruilviana ! very good, it's cheaper !

But they won’t be working whilst wet … which might be the OP’s problem

You gave me a good idea. I have a set of dallas probes (about 6) installed in my office, in the worst way (electric, electro-magnetic, mechanical,...) in order to test them, in bad conditions, on the long term. One probe is connected behind 300 m of extension cable (3 coils of 100m + drops of 20m...) and shares the bus with a probe placed at 3 m from the reading electronics. Another one is placed at only 20 m, but the extension cable is not a twisted pair, and passes near a neon light, and all the electrical devices generating parasites that I could find. Another one is powered by a very poorly regulated power source, with a lot of ripples; another one is installed in real life, in a customer's storage (you won't tell him, will you?), without any filtering capacitor and protective diodes. All this has been working pretty much correctly for years, I even forget about them. This allows me to see how they behave, by looking at the recording periods that occur over months. Here's the good idea you gave me: I'll put a bare dallas sensor in a container of liquid, and see what happens. The water in the house is not ionized enough to conduct and cause a short circuit; but the plastic encapsulation of the sensor is not waterproof over time, so that's where the problem will come from. I'll see how long it takes! Then I'll be able to say that I know from experience the reaction of sensors immersed in a liquid, and its influence on the measurement, thank you very much!