How to use a Waterproof DS18B20 temperature probe with Arduino

Posted on by
Waterproof DS18B20 temperature probe.

Waterproof DS18B20 temperature probe.

If you are automating a hydroponic system, aquaponic or just an aquarium, you know that have monitored the water temperature is critical to your system stays in top condition. Among the variety of submersibles temperature probes find a solution based on digital DS18B20 sensor. Here we explain how you can use with Arduino.


Such probes resistant to water are sold with different lengths and inside the digital temperature sensor is DS18B20. This sensor uses the communication interface 1-Wire, which allows you to connect several of these sensors to the same pin of Arduino. In its internal ROM has stored a unique 64-bit address identifying each sensor, the sensor letting us know what is giving us the temperature measurement or reading the temperature of a sensor. Measured in a temperature range between -55°C to 125°C (-67 ° F to 257 ° F) with an accuracy of ± 0.5°C (within the range of -10 ° C to 85 ° C).
We can also set alarms for using a search command from the master device (in our case will be Arduino) us to indicate the sensors, with their corresponding direction, being measured by temperatures above or below a selected range. This range is set by two TL and TH registers 1 byte each, where the most significant bit (MSB) is the sign and the remaining seven are worth. When the temperature measured by the sensor is greater than TH or lower than TL receive the Master (when performing the search for alarms) that has been activated the alarm on the sensor. The values of the TH and TL registers are stored in non-volatile memory so that even when disconnected from the power the sensor preserve values.
The digital measurement resolution is adjustable from 9 bits to 12 bits, allowing us to obtain more precise values decreasing the number of measures we can take per second, or else sacrifice some precision gaining more measurements per second, all It will depend on the use we want to give it.

Power Supply: 3,3V ~ 5V
Temperature range: -55 °C to +125 °C
Accuracy: ±0.5°C (within the range of -10°C to 85°C)
Resolution: 9 a 12 bits (adjustable resolution)
Wiring: Red: VCC
Yellow: DATA
Black: GND


First before you start writing your code it is advisable to seek if existing libraries that provide and simplify our work. In the case of DS18B20 there are several libraries, but not all use all the functionality that allows this sensor. The best we’ve found is at Github and is the library Arduino Library for Maxim Temperature Integrated Circuits  from which we can download the zip to install it in our Arduino IDE as explained in Install GitHub libraries on Arduino IDE.

Once installed the library we can test the sensor connected the VCC, GND and DATA pin to our Arduino, establishing the digital pin code Arduino that we will use for 1-wire protocol which connect the DATA pin of our sensor. Here you have a sample code:

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

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress AddThermometer;

void setup(void)
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices.");

  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");
  if (!sensors.getAddress(AddThermometer, 0))   Serial.println("Unable to find address for Device 0"); 

  Serial.print("Device 0 Address: ");

  sensors.setResolution(AddThermometer, 9);
  Serial.print("Device 0 Resolution: ");
  Serial.print(sensors.getResolution(AddThermometer), DEC); 

void printTemperature(DeviceAddress deviceAddress)

  float tempC = sensors.getTempC(deviceAddress);
  Serial.print("Temp C: ");
  Serial.print(" Temp F: ");

void loop(void)
  Serial.print("Requesting temperatures...");

void printAddress(DeviceAddress deviceAddress)
  for (uint8_t i = 0; i < 8; i++)
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
Comments are disabled