DS18B20 waterproof temp sensor, wrong output

HI there,
Just starting out with the Aduino. Have a basic understanding of C++, and have connected some of the basic senors and things to the pins, but still a noob. Anyways, I have one of these DS18B20 temp sensors, and I have downloaded and installed the One-wire library and the Dallas Instruments library required to get it up and running. I found some code online, which compiled and uploaded fine to the Arduino Uno R3 I am using. In the serial monitor, the feedback, however, is a repetitive:

20:39:03.690 -> Temperature is: -127.00 Requesting temperatures...DONE
20:39:05.453 -> Temperature is: -127.00 Requesting temperatures...DONE
20:39:07.217 -> Temperature is: -127.00 Requesting temperatures...DONE
20:39:08.948 -> Temperature is: -127.00 Requesting temperatures...DONE

It keeps sending the exact same data, weather I dunk the sensor in a hot cup of coffee or an ice-cold cup of kool-aid. I have the data line leading to pin 2, the ground to ground, and the vcc running to the 5v pin. I have about 20 of these sensors, maybe this one's faulty....?

Here i a pic, and the code I am using:

#include <OneWire.h>
#include <DallasTemperature.h>

// 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)
// start serial port
Serial.println("Dallas Temperature IC Control Library Demo");

// Start up the library

void loop(void)
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures

Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire

Where is the required pullup resistor. 4.7K is recommended value.

Code works fine with my Uno and 18B20 with 4.7K pullup.

1 Like

Thank you! I got frustrated and scrolled too far down, missing that entirely. It works just fine now. Thanks again


These water proof sensors are not water proof !!

The tip is , but if you submerge the whole sensor water will get in and it will fail

I'll second that - needs some proper hermetic sealing to work for more than a few days.

Yes, trickier than it seems.
A decent round cable and several layers of adhesive lined heat-shrink will work with the TO92 version.
For really critical applications, I would be looking at some properly engineered enclosure/container with cable glands rated to IP68.

Google thermowell .
You can make your own with a bit of copper pipe with the submerged end crimped and soldered .
I’ve used this in my fish pond for several years

Do you mean some copper tube sealed at one end and open at the other?
I have thermowells on my central heating pipes, but they have to be filled with thermally conductive paste.
Surely, with copper being a good thermal conductor, the tube will average the temperature over the whole depth?
I still think the best bet is to get a good seal between the cable and the "can" of the "waterproof" sensor.
Properly applied self-adhesive heatshrink should do the job and by that I mean using a heat gun, not a soldering iron or a lighter.
There's no guarantee that the supplier of these things isn't using bog-standard heatshrink.
Another consideration is just how far far water will penetrate a stranded cable by purely capillary action

But water has an awesomely large thermal capacity, so it may not be too worried about pumping some heat along the copper.

But water has an awesomely large thermal capacity, so it may not be too worried about pumping some heat along the copper.

Yes, but if the temperature sensor is in contact with the copper, is it measuring the temperature of the water at that point or the temperature of the copper that might not correspond with the temperature gradient of the water? Without looking it up, I reckon the thermal conductivity of water is less than that of copper.

I'm just nit-picking, but it doesn't matter what you do, the temperature sensor will reflect the way you use it, the can it's in, the cable it's attached to etc.

I still think the best solution is keep the waterproofing small and effective.

For the DS18B20 shown, the junction between the steel case and the cable is likely where the water could get in.

Another solution might be to use a plastic tube to protect the cable and heatshrink, poke the steel case through a cable gland and just have the tip exposed, assuming that's where the chip is.

I often use 20-mm plastic electrical conduit to house submerged cable assemblies. I just use a female M20 adaptor glued onto the end of the tube, screw an M20 cable gland in and seal onto the sensor.

At the other end where the cable emerges, use another cable gland or put an upside down "U" tube to stop the wet getting in

But the issue is the thermal conductance, not conductivity, there's way more water than copper, it totally dominates thermally. A 1mm wall 5mm diameter copper tube has a thermal conductance of 6mW/(K/m), and each cm^3 of water takes 4.2J to change one degree.... This is why phase-change heat-pipes are used to move heat efficiently, not just copper bars.

As said you will struggle to water proof it have a go .. then stick down the copper tube !

  • you can experiment and see how it performs by moving the sensor up and down the tube .
    You could always use a plastic tube with a copper tip- you can buy plastic and copper plumbing fittings that will fit together .
    Use some heat sink compound at the end if you wish

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