Issue connecting 20 DS18B20 sensors

Thread Starter

Alois Luong 1

Joined Aug 15, 2019
12
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?
 

Thread Starter

Alois Luong 1

Joined Aug 15, 2019
12
I unfortunately don't have access to a scope. A theory that I have is that 1-wire bus reliability is not good when there are a lot of sensors, or too much cable length, or improper wiring.
 

ericgibbs

Joined Jan 29, 2010
14,130
hi,
Why don't you allocate say 4 pins on the Arduino, 5 on each pin.
Select the pins and initialise for DS18B20.?

E

//Include libraries
#include <OneWire.h>
#include <DallasTemperature.h>

Redefine in a sequence with say a Function call.

// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2


// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);



void setup(void)
{
Serial.begin(9600); //Begin serial communication
Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
sensors.begin();
}
 

Thread Starter

Alois Luong 1

Joined Aug 15, 2019
12
Why don't you allocate say 4 pins on the Arduino, 5 on each pin.
Select the pins and initialise for DS18B20.?
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?
C++:
#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);
}
 

ericgibbs

Joined Jan 29, 2010
14,130
Last edited:

Thread Starter

Alois Luong 1

Joined Aug 15, 2019
12
Thank you all for your amazing ideas and suggestions. After toying around with all the ideas, two of them worked for me.

  • Splitting the sensors on more than one Arduino Pin: this works although it means that more cabling is required and the code becomes increasingly messy as more sensors are added.
  • Decreasing the pull-up resistor value: this worked like a charm! I don't have the knowledge to do exact calculations but found that a 1k ohm resistor worked for 20 sensors on a single serial bus line.
I'm sure that the first solution has many added benefits to it but for the sake of simplicity, I went with the second option.
 
Top