Hello,
In this tutorial-based article, we are going to learn about the waterproof temperature sensor DS18B20 and its interfacing with Arduino. 

Hardware Required

  • Arduino Uno

  • DS18B20 waterproof temperature Sensor module

  • Jumper Wires

Software Required

  • Arduino IDE

DS18B20 1-wire Temperature Sensor

The DS18B20 temperature sensor is a waterproof temperature sensor module that can be used to measure the temperature underwater. It uses a 1-wire interface for communication with the microcontroller. DS18B20 is very precise and it works in the range of -55 degrees to 125 degrees Celsius with an Accuracy of ±0.5°C. It can be powered with 3V to 5.5V power supply and it only consumes 1 mA of current during its working. Here is a list of the specifications for the DS18B20.

  • Power Supply: 3 to 5.5 V

  • Operating Current: 1 mA

  • Temperature detection range: -55 to 125°C

  • Accuracy: ±0.5°C

  • Conversion time <750 ms

One of the biggest advantages of the DS18B20 is that it uses a 1-wire protocol for interfacing. And each sensor has a 64-bit serial code embedded into them during the time of manufacturing. This makes it very easy to differentiate between two sensors. And so multiple temperature sensors can be used on a single bus with one microcontroller. This makes it perfect to use for projects which require multiple sensors on a single bus. 

DS18B20 Pinout

There are three pins on the DS18B20 sensor:

GND pin is the ground pin.

VDD pin is the power supply pin. It takes anywhere between 3 to 5.5V.

DQ pin is the data transfer pin and is connected to the digital pins on the Arduino. 

Interfacing with Arduino

The Red Pin is connected to the 5V pin on the Arduino board. 

The Black pin on the sensor is connected to the GND pin on the Arduino board. 

The Yellow pin is the data pin and is connected to the digital pin 2 on the Arduino board. 

 Arduino Code

First, we need to install the DallasTemperature library from the ‘Manage Libraries’ section inside the Arduino IDE. This library was published by Miles Burton. 

After the library is installed, Upload the following code onto the Arduino board. 

#include 
#include 

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);    


DallasTemperature sensors(&oneWire);

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

void loop(void)
{ 
  sensors.requestTemperatures(); 

  Serial.print("Temperature: ");
  Serial.print(sensors.getTempCByIndex(0));
  Serial.print((char)176);
  Serial.print("C  |  ");
  
  Serial.print((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0);
  Serial.print((char)176);
  Serial.println("F");
  
  delay(500);
}

I hope you learned something about the waterproof sensor DS18B20 in this article and I hope you liked it.