Ds18b20 with ESP32 temp readings stuck on 24C, 25C and 26C

I'm trying to use an ESP32 and some ds18b20 temperature sensors to read temperatures around the house and visualize the data using Grafana and Influxdb. I am attempting to use some sensors parasitically powered on pin 18 and others powered normally on pin 4 . The rationale being that some locations already have 2 wire thermostats that I can easily remove and replace with a flush mount temp sensor. My problem is that now with three sensors connected (2 parasitically powered and 1 normal) I am getting temperature readings of 75.2F, 77F, and 78.8. or 24, 25 and 25 in celsius. Wondering if anyone else has ever had this problem. Any help would be appreciated! I have been struggling with these things for a while now.

#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <WiFiMulti.h>
WiFiMulti wifiMulti;
#include <InfluxDbClient.h>
#include <InfluxDbCloud.h>

#define DEVICE "ESP32"
// Data wire is plugged into digital pins 4 and 18 on the ESP32
#define ONE_WIRE_BUS 4
#define ONE_WIRE_BUS2 18
#define TEMPERATURE_PRECISION 9
#define WIFI_SSID "*********"                                                                                        //Network Name
#define WIFI_PASSWORD "*********"                                                                                //Network Password
#define INFLUXDB_URL "***********"                                                                                     
#define INFLUXDB_TOKEN "***********" 
#define INFLUXDB_ORG "***********"                                                                                     
#define INFLUXDB_BUCKET "***********"                                                                               
#define TZ_INFO "***********" 

// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS); 
OneWire oneWire2(ONE_WIRE_BUS2); 


// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
DallasTemperature sensorspara(&oneWire2);

DeviceAddress second_fl_temp_address = { 0x28, 0x5A, 0x32, 0xDB, 0x0A, 0x00, 0x00, 0x07 };
DeviceAddress basement_temp_address = { 0x28, 0x69, 0x9F, 0xDC, 0x0A, 0x00, 0x00, 0xEA};
DeviceAddress first_fl_temp_address = { 0x28, 0x35, 0xB0, 0xDC, 0x0A, 0x00, 0x00, 0x2E};
DeviceAddress boiler_outlet_address= { 0x28, 0x90, 0x40, 0x57, 0x04, 0xE1, 0x3C, 0x2A };

//int deviceCount = 0;
int16_t second_fl_temp_raw;
int16_t first_fl_temp_raw;
int16_t basement_temp_raw;
int16_t boiler_outlet_raw;
float second_fl_temp;
float first_fl_temp;
float basement_temp;
float boiler_outlet_temp;

InfluxDBClient client(INFLUXDB_URL, INFLUXDB_ORG, INFLUXDB_BUCKET, INFLUXDB_TOKEN, InfluxDbCloud2CACert);    
Point sensor("Temperature Readings");  //Data points


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

  WiFi.mode(WIFI_STA);                                              //Setup wifi connection
  wifiMulti.addAP(WIFI_SSID, WIFI_PASSWORD);

   Serial.print("Connecting to wifi");                               //Connect to WiFi
  while (wifiMulti.run() != WL_CONNECTED) 
    {
    Serial.print(".");
    delay(100);
  }
  Serial.println();
  
 
  sensor.addTag("device", DEVICE);                                   //Add tag(s) - repeat as required
  sensor.addTag("SSID", WIFI_SSID);

  timeSync(TZ_INFO, "pool.ntp.org", "time.nis.gov");                 //Accurate time is necessary for certificate validation and writing in batches

  if (client.validateConnection())                                   //Check server connection
  {
    Serial.print("Connected to InfluxDB: ");
    Serial.println(client.getServerUrl());
  } 
  else 
  {
    Serial.print("InfluxDB connection failed: ");
    Serial.println(client.getLastErrorMessage());
  } 
  sensors.begin();
  sensorspara.begin();
}

  // locate devices on the bus
  //deviceCount = sensors.getDeviceCount();
 
  //deviceCount = sensorspara.getDeviceCount();

//}

void loop(void)
{ 
  // Send command to all the sensors for temperature conversion
  sensors.requestTemperatures(); 
  sensorspara.requestTemperatures(); 
  
  // Display temperature from each sensor
 
  {
//Normally Powered Sensors
   
    Serial.print("Boiler Outlet ");
    Serial.print(" : ");
    boiler_outlet_raw = sensors.getTemp(boiler_outlet_address);
    //first_fl_temp = (DallasTemperature::toFahrenheit(first_fl_temp));
    boiler_outlet_temp = (boiler_outlet_raw / 128);
    boiler_outlet_temp = ((boiler_outlet_temp)*(1.8)+(32));
    Serial.print(boiler_outlet_temp);
    Serial.println("F");





//Parasitically Powered Sensors
    Serial.print("First floor ");
    Serial.print(" : ");
    //second_fl_temp = sensorspara.getTempCByIndex(0);
    first_fl_temp_raw = sensorspara.getTemp(first_fl_temp_address);
    //second_fl_temp = (DallasTemperature::toFahrenheit(second_fl_temp));
    first_fl_temp = (first_fl_temp_raw / 128);
    first_fl_temp = ((first_fl_temp)*(1.8)+(32)); 
    //Serial.print(second_fl_temp_raw);
    Serial.print(first_fl_temp);
    Serial.println("F");

    Serial.print("Second Floor ");
    Serial.print(" : ");
    //second_fl_temp = sensorspara.getTempCByIndex(0);
    second_fl_temp_raw = sensorspara.getTemp(second_fl_temp_address);
    //second_fl_temp = (DallasTemperature::toFahrenheit(second_fl_temp));
    second_fl_temp = (second_fl_temp_raw / 128);
    second_fl_temp = ((second_fl_temp)*(1.8)+(32)); 
    //Serial.print(second_fl_temp_raw);
    Serial.print(second_fl_temp);
    Serial.println("F");

    //Serial.print("Basement ");
    //Serial.print(" : ");
    //basement_temp = sensorspara.getTempCByIndex(1);
    //  second_fl_temp = (DallasTemperature::toFahrenheit(second_fl_temp));
    //basement_temp = ((basement_temp)*(1.8)+(32));
    //Serial.print(basement_temp);
    //Serial.println("F");
  }
   sensor.clearFields();                                              //Clear fields for reusing the point. Tags will remain untouched

  sensor.addField("Boiler outlet temp", boiler_outlet_temp);
  sensor.addField("First floor temp", first_fl_temp);                              // Store measured value into point
  sensor.addField("Second floor temp", second_fl_temp);                                // Store measured value into point
  //sensor.addField("Basement temp", basement_temp);                         



    
  if (wifiMulti.run() != WL_CONNECTED)                               //Check WiFi connection and reconnect if needed
    Serial.println("Wifi connection lost");

  if (!client.writePoint(sensor))                                    //Write data point
  {
    Serial.print("InfluxDB write failed: ");
    Serial.println(client.getLastErrorMessage());
  }
  Serial.println("");
  delay(1000);
}

There are many counterfeit 18B20 sensors on the market.

Where did you buy yours?
Try to buy from stores with good references.

Those numbers appear to be reasonable in a home in the summer. Sensors in different locations will give different values. If you want them to read the same place them in a temperature controlled circulating liquid bath. Also there can be some residual heat from handling. They need settle for a bit after moving them. More detail, at this point I am not sure if you have a problem.

are the ones with parasitic power reading the same and the powered one is the odd one. I friend had a similar thing a few years back, the library used had a delay missing. Adding the delay solved the problem. The parts in question were several years old.

They do appear reasonable which made me happy last night when I thought things were working. (had previously been getting 185F)
However, the numbers haven't changed in 12 hrs. Once I get back tonight I will power cycle the board and see if things change/improve.

The single sensor in normal power mode is likely a fake. The two parasitically powered sensors are from datanab which is a reputable reseller. I think...

How long is the wiring in your system?

There's been a couple of posts lately about driving multiple 1-Wire sensors from a simple microcontroller port pin and/or over long wires.
The simple port-pin driver isn't suitable in such cases - you really need a more advanced driver.

Longest run is about 12.5m.

How do you have the normal sensor wired? Is it part of the two wire wiring or is the Vdd pin connected to the microcontroller ground at the microcontroller.

A schematic diagram of your circuit would be nice.

What's the total length of wires (the network "weight" in the linked documents)?

Total weight is about 20m. Or i guess just "the weight"...

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