Seven DS18B20's fine, eight DS18B20's no work

Hi all,
I've searched here and googled but not found anything similar to what I'm seeing. Apologies if I've missed it.
I'm trying to connect 15 DS18B20's (each with a 3m cable) to a UNO with WiFi R2.
It all works until I attach sensor number eight when I get no valid information.
I've tried different sensors, I've tried a power supply instead of USB, no improvement. I've tested sensor number eight alone and it's fine.
So I think I've ruled out lack of power and dodgy sensor haven't I?
I've seen comments saying you can have loads of DS18B20's on one wire, is that true?
Any help gratefully received.

Relevant part of the output is:

Sensor 1: 0.00 Sensor 2: 0.00 Sensor 3: 0.00 Sensor 4: 0.00 Sensor 5: 0.00 Sensor 6: 0.00 Sensor 7: 0.00 Sensor 8: 0.00

Code is work in progress so please forgive the sloppy programming :wink:

#include <SPI.h>
#include <WiFiNINA.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>

#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
float tempC;
String lcdText;
float prevTemp[9];
float lastTemp;
float difTemp;
DeviceAddress Thermometer;
uint8_t sensor1[8] = {0x28, 0x40, 0x18, 0x30, 0x27, 0x19, 0x01, 0x8F};
uint8_t sensor2[8] = {0x28, 0xD5, 0x62, 0x32, 0x27, 0x19, 0x01, 0x02};
uint8_t sensor3[8] = {0x28, 0xC5, 0x27, 0x24, 0x27, 0x19, 0x01, 0x53};
uint8_t sensor4[8] = {0x28, 0x38, 0xCD, 0x2A, 0x27, 0x19, 0x01, 0x19};
uint8_t sensor5[8] = {0x28, 0x25, 0x3E, 0x2C, 0x27, 0x19, 0x01, 0xE9};
uint8_t sensor6[8] = {0x28, 0x2A, 0x8B, 0x33, 0x27, 0x19, 0x01, 0xF2};
uint8_t sensor7[8] = {0x28, 0x0B, 0x78, 0x29, 0x27, 0x19, 0x01, 0xB8};
uint8_t sensor8[8] = {0x28, 0x9E, 0x9D, 0x25, 0x27, 0x19, 0x01, 0xF8};


uint8_t sensorx[8] = {0x28, 0x2D, 0xA6, 0x26, 0x27, 0x19, 0x01, 0xDA};


char ssid[] = "********";      // your network SSID (name)
char pass[] = "********";   // your network password

int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup() {
  sensors.begin();
  Serial.begin(9600);
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    delay(10000);
  }
  server.begin();
  printWifiStatus();
}


void loop() {

  // listen for incoming clients
  WiFiClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {

      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");


          sensors.requestTemperatures();
          //client.println(sensors.getTempCByIndex(0));
          //Serial.println(sensors.getTempCByIndex(0));
          sensors.getAddress(Thermometer, 0);
          printAddress(Thermometer);
          //  Serial.print("Sensor 1: ");
          //  printTemperature(sensor1);
 
          client.print("Sensor 1: ");
          client.println(sensors.getTempC(sensor1));
          client.print("Sensor 2: ");
          client.println(sensors.getTempC(sensor2));
          client.print("Sensor 3: ");
          client.println(sensors.getTempC(sensor3));
          client.print("Sensor 4: ");
          client.println(sensors.getTempC(sensor4));
          client.print("Sensor 5: ");
          client.println(sensors.getTempC(sensor5));
          client.print("Sensor 6: ");
          client.println(sensors.getTempC(sensor6));
          client.print("Sensor 7: ");
          client.println(sensors.getTempC(sensor7));
          client.print("Sensor 8: ");
          client
          .println(sensors.getTempC(sensor8));

          client.println("</html>");

          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);

    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
  sensors.requestTemperatures();
  Serial.println(sensors.getDeviceCount());
  for (int i = 0; i <= sensors.getDeviceCount() - 1; i++)
  {
    sensors.getAddress(Thermometer, i);
    //   Serial.println(i);
    printAddress(Thermometer);

  }

  delay(5000);
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    Serial.print("0x");
    if (deviceAddress[i] < 0x10) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
    if (i < 7) Serial.print(", ");
  }
  Serial.println("");
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  Serial.print(tempC);
  Serial.print((char)176);
  Serial.print("C  |  ");
  Serial.print(DallasTemperature::toFahrenheit(tempC));
  Serial.print((char)176);
  Serial.println("F");
}

You might need stronger pull-ups and perhaps more power rail decoupling.

You should ideally by daisy-chaining these sensors so the cabling doesn't present too low an impedance (many
wires in parallel will have a dynamic impedance of 10 ohms or less on very short timescales, a single cable is more like 100 ohms).

On one wire I've had 20 sensors running fine. 20 on separate wires all paralleled could be a very different matter.

Try 2k2 or even 1k pullup in the first instance. Each device ought to have a 100nF decoupling cap for its supply at the chip for best protection from noise and glitches.

If you can stop paralleling them so much that's likely to help.

Thanks Mark,
I’m running a 4.7k ohm resistor, I’m assuming that’s what you mean by pull up. Sorry, I’m very new to this.
I have plenty of IO spare on the board, but not enough to only have one per channel. I’ll try to figure out how to run multiple one wires.
Thanks again for the guidance. It’s much appreciated.

John,

I'm not sure you caught the part about 'daisy-chaining' the sensors.

This means that instead of running each 3m cable back to the Arduino you run them from one sensor to the next.

I'll try crude a ASCII drawing:

A = Arduino, S = Sensor

Home run:

   /----- S
  /------ S
A ------- S
  \------ S
   \----- S

Daisy-Chain:

A ---- S ---- S ---- S ---- S ---- S ---- S

Don

Thanks Don,
You’re absolutely right, I did miss that.
I’m not sure I can though as they’re sealed waterproof sensors. I’m not creating the connections and wiring myself. I might be able to significantly shorten the leads and not bring all the cables back to the UNO though.
Let me have a think and post what I’m thinking. Right now I’m thinking a kind of bus where the live, ground and signal wires run all the way round where the sensors will be then each sensor has its own wires connected to the bus. I’m sure bus is the wrong term but hopefully you get what I mean.
Do you think that would work?

You should be fine with eight sensors and a single 4k7. Your code might be suss as it seems to be having a two bob each way bet as to whether you use stated addresses or by index.

You can use more than instance of one wire, and spread the sensors over more pins, but I see no point in this.

Thanks Nick,
I want to get to 15 sensors.
I will be getting the temperatures by address, by index was just a test. I found I couldn’t rely on the same sensor always getting the same index.

johnkitching:
I found I couldn’t rely on the same sensor always getting the same index.

No surprise there. I think by index is for the birds, and suggest you delete all reference to that method.

johnkitching:
. . . Right now I’m thinking a kind of bus where the live, ground and signal wires run all the way round where the sensors will be then each sensor has its own wires connected to the bus. I’m sure bus is the wrong term but hopefully you get what I mean.
Do you think that would work?

That should work.

A -----|------|------|------|------|----- S
       |      |      |      |      |
       |      |      |      |      |
       |      |      |      |      |

       S      S      S      S      S

Don

Thanks Don.