strange results using the DS18B20 temperature sensor

I’m using the OneWire and DallasTemperature libraries for my code.
For some unknown reasons, the two sensors always return constant numbers.
The wiring has no problem, I double checked.
Here’s the code:

#include <DallasTemperature.h>

#include <OneWire.h>

#define ONE_WIRE_BUS 3
#define TEMPERATURE_PRECISION 12

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer={0x28,0x40,0x79,0x8F,0x05,0x00,0x00,0x83};
DeviceAddress outsideThermometer={0x28,0x2F,0x52,0x8F,0x05,0x00,0x00,0xEC};

void setup()
{
  Serial.begin(9600);
  sensors.begin();
  Serial.println("Initializing...");
  Serial.println();
  if(!sensors.getAddress(insideThermometer,0)) Serial.println("Unable to find address for Device 0");
  if(!sensors.getAddress(outsideThermometer,1)) Serial.println("Unable to find address for Device 1");
  sensors.setResolution(insideThermometer,TEMPERATURE_PRECISION);
  sensors.setResolution(outsideThermometer,TEMPERATURE_PRECISION);
}

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

void loop()
{
  Serial.print("Inside Temp: ");
  printTemperature(insideThermometer);
  Serial.print("Outside Temp: ");
  printTemperature(outsideThermometer);
  Serial.println();
  delay(3000);
}

and the Serial returns:

Initializing...

Inside Temp:  Temp C: 85.00 Temp F: 185.00
Outside Temp:  Temp C: 20.56 Temp F: 69.01

Inside Temp:  Temp C: 85.00 Temp F: 185.00
Outside Temp:  Temp C: 20.56 Temp F: 69.01

Inside Temp:  Temp C: 85.00 Temp F: 185.00
Outside Temp:  Temp C: 20.56 Temp F: 69.01

which is impossible, because i have the two sensors right next to each other.
When i touch one of the sensors, the numbers don’t change, either.
Pls help!
Thanks!

The value of 85 rings a bell as something you get back from the library if the sensor is not available. When everything is working correctly you may still get this value shortly after startup while everything is initialising. If you keep getting it, that suggests that something isn’t running correctly.

Although you say the wiring is correct, you can’t know that until everything is working correctly. How have you wired it, and especially how are you powering the sensors? Please include a circuit diagram if possible. Have you determined the address(es) of your sensor(s), and if so how? The Dallas temp library comes with an example sketch which scans the one-wire bus for devices which will enable you to confirm that the devices are working and connected OK and also tell you the addresses to use if you want to read the sensors by address as shown in your code.

PeterH:
The value of 85 rings a bell as something you get back from the library if the sensor is not available. When everything is working correctly you may still get this value shortly after startup while everything is initialising. If you keep getting it, that suggests that something isn’t running correctly.

Although you say the wiring is correct, you can’t know that until everything is working correctly. How have you wired it, and especially how are you powering the sensors? Please include a circuit diagram if possible. Have you determined the address(es) of your sensor(s), and if so how? The Dallas temp library comes with an example sketch which scans the one-wire bus for devices which will enable you to confirm that the devices are working and connected OK and also tell you the addresses to use if you want to read the sensors by address as shown in your code.

Yes, I have already tested it using the code below:

#include <DallasTemperature.h>

#include <OneWire.h>

#define ONE_WIRE_BUS 3

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer, outsideThermometer;

void setup()
{
  Serial.begin(9600);
  sensors.begin();
  Serial.println("Locating devices...");
  delay(1000);
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(),DEC);
  Serial.println(" devices.");
  if(!sensors.getAddress(insideThermometer,0)) Serial.println("Unable to find address for Device 0");
  if(!sensors.getAddress(outsideThermometer,1)) Serial.println("Unable to find address for Device 1");
  Serial.print("Device 0 Address: ");
  printAddress(insideThermometer);
  Serial.println();
  Serial.print("Device 1 Address: ");
  printAddress(outsideThermometer);
  Serial.println();
  Serial.println();
}

void printAddress(DeviceAddress deviceAddress)
{
  for(int i=0;i<8;i++)
  {
    if(deviceAddress[i]<16) Serial.print("0");
    Serial.print(deviceAddress[i],HEX);
  }
}

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

void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address:");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}

void loop()
{
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");
  printData(insideThermometer);
  printData(outsideThermometer);
  Serial.println();
  delay(1000);
}

And this works perfectly, returning:

Locating devices...
Found 2 devices.
Device 0 Address: 2840798F05000083
Device 1 Address: 282F528F050000EC

Requesting temperatures...DONE
Device Address:2840798F05000083 Temp C: 20.12Temp F:68.22
Device Address:282F528F050000EC Temp C: 20.06Temp F:68.11

Requesting temperatures...DONE
Device Address:2840798F05000083 Temp C: 20.12Temp F:68.22
Device Address:282F528F050000EC Temp C: 20.06Temp F:68.11

Requesting temperatures...DONE
Device Address:2840798F05000083 Temp C: 20.19Temp F:68.34
Device Address:282F528F050000EC Temp C: 20.06Temp F:68.11

Requesting temperatures...DONE
Device Address:2840798F05000083 Temp C: 23.31Temp F:73.96
Device Address:282F528F050000EC Temp C: 20.06Temp F:68.11

Requesting temperatures...DONE
Device Address:2840798F05000083 Temp C: 25.44Temp F:77.79
Device Address:282F528F050000EC Temp C: 20.12Temp F:68.22

As you can see, the temperature changes when I touched the sensor.
I can’t see any difference between this code and the first one, that’s what baffles me.
Thx!

use a tool like kdiff3 to see differences in sources.

The line you missed is probably: sensors.requestTemperatures();

robtillaart: use a tool like kdiff3 to see differences in sources.

The line you missed is probably: sensors.requestTemperatures();

That's IIIIIIIIIIT! I've been stupid. Now I see the differences. Thanks a looooooot!!!