Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.
DS18B20 Arduino: Complete Waterproof Temperature Sensor Guide
When a project requires measuring temperature in wet environments, harsh conditions, or at distance from the main controller, the DS18B20 Arduino combination becomes my go-to solution. After designing temperature monitoring systems for everything from aquariums to industrial brewing equipment, I’ve come to appreciate why this sensor dominates the waterproof temperature sensing market.
The DS18B20 stands apart from other temperature sensors for several compelling reasons. It communicates digitally over a single data wire, maintains accuracy even with long cable runs, and each sensor carries a unique 64-bit address allowing multiple sensors on one bus. The waterproof probe version wraps all this capability in a stainless steel housing that handles submersion without complaint.
This tutorial covers everything you need to successfully implement DS18B20 Arduino projects, from understanding the underlying technology to wiring multiple sensors and troubleshooting common problems.
Understanding DS18B20 Sensor Technology
The DS18B20, manufactured by Maxim Integrated (formerly Dallas Semiconductor), uses the proprietary 1-Wire protocol for communication. This protocol deserves attention because it fundamentally shapes how you design DS18B20 Arduino circuits.
How 1-Wire Communication Works
Unlike I2C or SPI which require dedicated clock lines, the 1-Wire protocol transmits data and timing information over a single wire. The Arduino acts as the bus master, initiating all communication sequences with reset pulses and time-slot-based data transfer.
Each communication begins with the master pulling the data line low for at least 480 microseconds (the reset pulse), then releasing it. Connected DS18B20 sensors respond with presence pulses, signaling they’re ready for commands. Data bits are then exchanged through precisely timed voltage transitions.
The protocol’s elegance enables several practical advantages:
Advantage
Practical Benefit
Single data wire
Minimizes wiring complexity
Unique 64-bit addresses
Multiple sensors on one pin
No signal degradation
Works reliably over long distances
Parasite power mode
Operation with only two wires
Built-in CRC checking
Data integrity verification
Temperature Measurement Mechanism
Inside the DS18B20, a bandgap-based temperature sensor converts thermal energy to a digital value. The sensor counts clock cycles from a temperature-dependent oscillator and compares them to a stable reference oscillator. This differential counting technique provides consistent accuracy across the operating temperature range.
The measurement resolution is user-configurable from 9 to 12 bits, with corresponding conversion times from 93.75ms to 750ms. Higher resolution takes longer but provides finer temperature granularity.
Resolution
Increment
Conversion Time
9-bit
0.5°C
93.75 ms
10-bit
0.25°C
187.5 ms
11-bit
0.125°C
375 ms
12-bit
0.0625°C
750 ms
The default 12-bit resolution suits most applications, providing excellent accuracy with sub-second response times.
DS18B20 Technical Specifications
Understanding specifications helps determine if the DS18B20 fits your project requirements and operating environment.
Parameter
Specification
Operating Voltage
3.0V to 5.5V
Temperature Range
-55°C to +125°C
Accuracy
±0.5°C (from -10°C to +85°C)
Resolution
9 to 12 bits (programmable)
Conversion Time
93.75ms to 750ms
Standby Current
750nA typical
Active Current
1mA typical, 1.5mA max
Communication
1-Wire protocol
Data Line
Open-drain, requires pull-up
Unique Address
64-bit ROM code
The waterproof probe version adds a stainless steel housing with PVC-jacketed cable. While the DS18B20 chip handles temperatures up to 125°C, the PVC jacket typically limits practical use to around 100°C for continuous operation. For higher temperatures, look for probes with silicone or Teflon insulation.
DS18B20 Pinout and Form Factors
The DS18B20 comes in several packages, with the TO-92 transistor-style package and waterproof probe being most common for Arduino projects.
TO-92 Package Pinout
With the flat side of the TO-92 package facing you (text readable):
Pin
Name
Function
1 (Left)
GND
Ground
2 (Center)
DQ
Data In/Out
3 (Right)
VDD
Power Supply
Waterproof Probe Wire Colors
Waterproof probes use color-coded wires, though colors vary between manufacturers. The most common scheme:
Wire Color
Connection
Red
VDD (Power)
Yellow or White
DQ (Data)
Black
GND (Ground)
Always verify wire functions with your specific probe’s documentation or use a multimeter to identify ground (typically has continuity to the metal housing).
Wiring DS18B20 to Arduino
Proper wiring is critical for reliable DS18B20 Arduino operation. The most important element is the pull-up resistor on the data line.
Components Required
Component
Quantity
Notes
Arduino Uno/Nano/Mega
1
Any Arduino board works
DS18B20 Sensor or Probe
1+
Waterproof probe recommended
4.7kΩ Resistor
1
Pull-up for data line
Breadboard
1
For prototyping
Jumper Wires
3+
Appropriate lengths
Standard Wiring (Normal Power Mode)
Normal power mode provides the most reliable operation and is recommended for most applications:
DS18B20 Pin
Arduino Connection
VDD (Red)
5V
DQ (Yellow)
Digital Pin 2 + 4.7kΩ to 5V
GND (Black)
GND
The 4.7kΩ pull-up resistor connects between the data line and 5V, maintaining a stable high state when the bus is idle. This resistor is essential; the Arduino’s internal pull-ups are too weak (20-50kΩ) for reliable 1-Wire communication.
Parasite Power Mode Wiring
In parasite power mode, the sensor draws power through the data line, requiring only two wires:
DS18B20 Pin
Arduino Connection
VDD
GND (tie to ground)
DQ
Digital Pin 2 + 4.7kΩ to 5V
GND
GND
Parasite mode reduces wiring but can cause issues during temperature conversion when current demand spikes. For multi-sensor setups or long cable runs, normal power mode is more reliable.
Installing Required Arduino Libraries
The DS18B20 Arduino interface requires two libraries that handle the complex 1-Wire protocol timing.
OneWire Library Installation
Step 1: Open Arduino IDE and navigate to Sketch → Include Library → Manage Libraries
Step 2: Search for “OneWire” in the Library Manager
Step 3: Find “OneWire by Paul Stoffregen” and click Install
This library handles low-level 1-Wire communication, managing the precise timing requirements that would be tedious to implement manually.
DallasTemperature Library Installation
Step 1: With Library Manager still open, search for “DallasTemperature”
Step 2: Find “DallasTemperature by Miles Burton” and click Install
This library builds on OneWire, providing convenient functions specifically for DS18B20 and similar temperature sensors.
DS18B20 Arduino Code Examples
With hardware connected and libraries installed, you can start reading temperature values.
Basic Single Sensor Reading
This sketch reads temperature from one DS18B20 and displays it on the Serial Monitor:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Data wire connected to pin 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
Serial.println(“DS18B20 Temperature Sensor”);
sensors.begin();
}
void loop() {
sensors.requestTemperatures(); // Send command to get temperatures
float tempC = sensors.getTempCByIndex(0);
float tempF = tempC * 9.0 / 5.0 + 32.0;
if (tempC == DEVICE_DISCONNECTED_C) {
Serial.println(“Error: Could not read temperature”);
return;
}
Serial.print(“Temperature: “);
Serial.print(tempC);
Serial.print(“°C | “);
Serial.print(tempF);
Serial.println(“°F”);
delay(1000);
}
The getTempCByIndex(0) function retrieves temperature from the first (index 0) sensor found on the bus. The DEVICE_DISCONNECTED_C constant (-127°C) indicates communication failure.
Finding DS18B20 Sensor Addresses
When using multiple sensors, you need each sensor’s unique 64-bit address. This utility sketch discovers and prints all connected sensor addresses:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
Serial.print(“Found “);
Serial.print(sensors.getDeviceCount());
Serial.println(” sensors.”);
DeviceAddress tempAddress;
for (int i = 0; i < sensors.getDeviceCount(); i++) {
if (sensors.getAddress(tempAddress, i)) {
Serial.print(“Sensor “);
Serial.print(i);
Serial.print(” Address: “);
printAddress(tempAddress);
Serial.println();
}
}
}
void loop() {
// Nothing needed here
}
void printAddress(DeviceAddress deviceAddress) {
for (uint8_t i = 0; i < 8; i++) {
if (deviceAddress[i] < 16) Serial.print(“0”);
Serial.print(deviceAddress[i], HEX);
}
}
Record the printed addresses for use in multi-sensor projects where you need to identify specific sensors.
Reading Multiple DS18B20 Sensors
With multiple sensors on the same bus, you can read by index or by address. Reading by address ensures you always know which physical sensor provides each reading:
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
// Define sensor addresses (replace with your actual addresses)
After troubleshooting countless DS18B20 installations, I’ve compiled the most common issues and their solutions.
Problem: Reading Shows -127°C
This value indicates the sensor didn’t respond or communication failed.
Cause
Solution
Missing pull-up resistor
Add 4.7kΩ between data and 5V
Wrong pin number in code
Verify pin definition matches wiring
Loose connections
Check all wire connections
Defective sensor
Try a different DS18B20
Wrong wire identification
Verify probe wire colors with documentation
Problem: Reading Shows 85°C
The DS18B20 powers up with 85°C in its temperature register. Reading this value means the sensor hasn’t completed a conversion.
Cause
Solution
Reading too quickly after power-on
Add delay after sensors.begin()
Insufficient conversion time
Wait for conversion to complete
Parasite power issues
Switch to normal power mode
Problem: Intermittent Readings or Errors
Sporadic failures often indicate marginal signal integrity.
Cause
Solution
Long cable runs
Use lower pull-up value (3.3kΩ) or add capacitor
Multiple sensors overloading bus
Reduce pull-up to 2.7kΩ-3.3kΩ
Electrical noise
Add 100nF capacitor between VDD and GND
Poor connections
Use soldered connections instead of breadboard
Problem: Multiple Sensors Not All Detected
When some sensors on a shared bus aren’t recognized:
Cause
Solution
Pull-up resistor too high
Lower to 3.3kΩ or 2.7kΩ for many sensors
Bus capacitance too high
Limit cable length or use multiple buses
Address conflicts (rare)
Verify all sensors have unique addresses
For installations with more than 5-6 sensors, reducing the pull-up resistor value often resolves detection issues. Some users report success with 14+ sensors using a 2.7kΩ pull-up.
DS18B20 vs Other Temperature Sensors
Choosing the right sensor depends on your specific requirements.
Feature
DS18B20
DHT11
LM35
Thermocouple
Interface
1-Wire
Single-wire
Analog
Analog (amplified)
Temp Range
-55 to +125°C
0 to 50°C
-55 to +150°C
-200 to +1350°C
Accuracy
±0.5°C
±2°C
±0.5°C
±1-2°C
Waterproof
Yes (probe version)
No
No
Yes
Multi-sensor
One pin for many
One pin each
One analog pin each
One pin each
Humidity
No
Yes
No
No
Price
~$2-5
~$1-2
~$1
~$5-15
The DS18B20 excels for underwater measurements, multi-point temperature monitoring, and applications requiring accuracy over a wide range. For combined temperature and humidity, the DHT22 is better suited. For extreme temperatures, thermocouples remain necessary.
Practical DS18B20 Arduino Applications
The DS18B20 Arduino combination suits numerous real-world projects.
Aquarium Temperature Monitoring
The waterproof probe handles permanent submersion, monitoring tank temperature with enough accuracy to detect problematic fluctuations before they stress fish.
Brewing and Fermentation Control
Monitor mash temperatures, fermentation vessel conditions, and cooling water simultaneously with multiple sensors on a single data bus. The probe’s stainless steel construction handles wet brewing environments.
HVAC System Monitoring
Track supply and return air temperatures, duct conditions, and room temperatures across a building using long cable runs that maintain signal integrity.
Soil Temperature Measurement
Monitor ground temperature for agriculture, gardening, or geothermal studies. The waterproof housing survives burial in moist soil.
Industrial Process Control
Track temperatures at multiple points along a production line, triggering alarms or controls when values exceed thresholds.
Common sources for DS18B20 sensors include Amazon, AliExpress, Adafruit, SparkFun, and Mouser. When purchasing waterproof probes, check reviews for quality issues, as cheap clones sometimes have sealing problems.
Frequently Asked Questions About DS18B20 Arduino
How many DS18B20 sensors can I connect to one Arduino pin?
Theoretically unlimited, since each sensor has a unique address. Practically, 10-20 sensors work reliably with appropriate pull-up resistor adjustment. Beyond 5-6 sensors, reduce the pull-up from 4.7kΩ to 2.7kΩ-3.3kΩ. Very long cable runs or many sensors may require multiple buses on different Arduino pins.
Can I use DS18B20 with ESP8266 or ESP32?
Absolutely. The same OneWire and DallasTemperature libraries work with ESP8266 and ESP32 boards. Use 3.3V power and appropriate GPIO pins. Some users prefer adding a level shifter when using 5V sensors with 3.3V microcontrollers, though direct connection often works.
Why does my waterproof probe fail at high temperatures?
The DS18B20 chip handles 125°C, but the PVC cable jacket softens around 80-100°C. For sustained high-temperature use, purchase probes with silicone or Teflon insulation, or use the TO-92 package with appropriate heat-resistant wiring.
What’s the maximum cable length for DS18B20?
Reliable operation up to 100 meters is achievable with proper wiring: use twisted pair or shielded cable, ensure solid connections, and adjust the pull-up resistor for your specific cable capacitance. Shorter runs (under 10m) rarely cause issues.
How do I improve DS18B20 response time?
Reduce the resolution from 12-bit to 9-bit or 10-bit, which decreases conversion time from 750ms to under 200ms. Use sensors.setResolution(address, 9) to configure. For truly fast response, thermistors or RTDs provide quicker thermal response than the DS18B20’s internal sensor.
Final Thoughts on DS18B20 Arduino Projects
The DS18B20 Arduino combination delivers reliable digital temperature sensing that scales from single-sensor prototypes to multi-point monitoring installations. Its 1-Wire protocol eliminates wiring complexity while maintaining signal integrity over distances that would defeat analog sensors.
The waterproof probe version opens applications that other sensors simply cannot address: permanent underwater monitoring, outdoor weather stations, buried soil sensors, and industrial processes involving moisture or liquids. At a few dollars per sensor, there’s little reason to compromise with less capable alternatives.
Start with a single sensor to understand the wiring and library usage, then expand to multi-sensor configurations as your projects demand. The unique addressing system makes scaling straightforward, with each new sensor requiring only a connection to the shared bus. That simplicity, combined with proven reliability, explains why the DS18B20 remains the dominant choice for Arduino temperature sensing projects requiring waterproof capability or multi-point measurement.
Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Notes: For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.