1Wire star connection with 3 DS18B20 stop working after a while

Hello,
I created a project where I have an Arduino Mini 05 that through 1Wire connection, read 3 temperatures from 3 DS18B20 sensors.
Just for your understanding, it works perfeclty for some hours or a couple of days, then I start to get for all of them temperature = 0°. It's really strange.. the connection is a star and cables are long more or less 7-10 meters. I have others Arduino, same project, same hardware but with one only sensor and in that case it is working for months without a problem.
I'm using the serial for the cross communication so I can't debug too much, of course it could be software or hardware. About the software, I checked many times and it seems ok, I implemented all errors in my inter-communication but I never received any error from sensors.
This is the code:

      switch (stepTemp) {
        case 0:
          if (TempDeviceNum > 0) {
              requestTemperature(idTemp);
              lastTempTime = millis();
              stepTemp++;
          }
        break;

        case 1:
          if (temperatureReady(lastTempTime)) {
            Temps[idTemp] = (int)(getTemperature(idTemp)*100.0);
            idTemp++;
            if (idTemp >= TempDeviceNum)
              idTemp = 0;
            stepTemp = 0;
          }
        break;
      }

these are functions:

void requestTemperature(int idx){
  //returns the temperature from one DS18B20 in DEG Celsius 
  ds.reset();
  ds.select(adrOneWire[idx]);
  ds.write(0x44); // start conversion, without parasite power on at the end 
}

bool temperatureReady(unsigned long timeReq) {
  unsigned long timeNow = millis();
  
  switch (TEMP_RESOLUTION) {
    case 12:  // 750 ms 
      return ((timeNow - timeReq) >= 800);
    case 11:  // 375 ms 
      return ((timeNow - timeReq) >= 400);
    case 10:  // 187.5 ms 
      return ((timeNow - timeReq) >= 200);
    case 9:   // 93.75 ms 
      return ((timeNow - timeReq) >= 100);
    default:
      return (false);
  }
  // return (ds.read());
}

float getTemperature(int idx){
  byte data[12]; 

  ds.reset();
  ds.select(adrOneWire[idx]);    
  ds.write(0xBE); // Read Scratchpad
  for (int i = 0; i < 9; i++) { // we need 9 bytes
    data[i] = ds.read();
  }
 
  byte MSB = data[1];
  byte LSB = data[0];
 
  float tempRead = ((MSB << 8) | LSB);
  float TemperatureSum = tempRead / 16.0;
 
  return TemperatureSum;
}

Maybe you can see something...

The most important thing for me is understanding about harware, because I'm using the pin 8 and I have just a pull-up resistor 4k7.
I tried to add a resistor 120 ohm in series of every branch, i found on the web that it could stop the reflection of signal back.. but the behavior is the same.
The connection is with 3 wires, +5Vdc, segnal and GND.

Can you tell me what I can do from the hardware point of view?
Can I check the resistence between signal and +5Vdc? ..or to GND?
Can I add a terminator resistance where the sensor is placed?

Once I'm sure about hardware, then I will investigate deeply into the code.

Makes sense that I read temperature zero? why?

Thanks
Bye
Andrea

At the moment, I can't see why you are getting zero but your code to convert the temperature is wrong. It doesn't handle negative temperatures correctly.
Change this code:

 byte MSB = data[1];
  byte LSB = data[0];
 
  float tempRead = ((MSB << 8) | LSB);
  float TemperatureSum = tempRead / 16.0;

to this:

// Convert the two bytes to a signed 16-bit integer
int16_t iT = ((data[1] << 8) | data[0]);
float TemperatureSum = iT/16.0;

Without seeing ALL your code, there's no way to know for sure what is wrong.
Why do you multiply the temperature by 100?

Temps[idTemp] = (int)(getTemperature(idTemp)*100.0);

Pete

Thanks a lot!
The reason is that I'm passing the value through a communication string to the master, you have to know that we are speaking of a slave. The temperature is divided by 100 by the master receiving the value.

Thanks for the negative value.. sure, I'm not expecting this.. inside home! :-)) but for sure it's an improvement.

What about hardware? any hints?
Next days I will try to simplify the code and just read temperatures, excluding issue in the software.. the whole code is big. For example I will try to configure one only temperature and check if the code works for long time or interrupt the read.. as I told, with one sensor I have many others Arduinos.

:frowning:
After two days where I enabled the read of temperature from one only sensor, it stop working this evening.. the temperature become zero.
In this configuration (same software, one sensor) is working in 10 others stations..

It should be an hardware problem.. the test was reading from one sensor but 3 sensors connected physically.

I did another test, I increased the time for getting temperature to 1s but nothing.

Ideas?

Which impedance I should have if I measure it on each sensor?
make sense to adjust with resistor?
120 ohm resistance in series to each star branch, it's enough and/or good?

hi there, i could use some solution here too, i have a similar problem, but in my case it gives -127 after a random time i.e. 2 hours... so i have tried everything and still the same

Sloppy wiring. The -127 means no connection.