

The DS18B20 is a digital temperature sensor that provides accurate temperature readings in both Celsius and Fahrenheit. It communicates using a 1-Wire interface, which allows multiple sensors to be connected to a single data line, simplifying wiring and reducing complexity. Known for its precision and reliability, the DS18B20 is widely used in applications such as weather stations, HVAC systems, industrial temperature monitoring, and home automation projects.
Key features of the DS18B20 include:








Below are the key technical details of the DS18B20 sensor:
| Parameter | Value |
|---|---|
| Operating Voltage | 3.0V to 5.5V |
| Temperature Range | -55°C to +125°C |
| Accuracy | ±0.5°C (from -10°C to +85°C) |
| Communication Protocol | 1-Wire |
| Resolution | Programmable (9 to 12 bits) |
| Conversion Time | 93.75ms (12-bit resolution) |
| Unique Serial Code | 64-bit |
| Maximum Current Consumption | 1.5mA during conversion |
The DS18B20 sensor typically comes in a 3-pin TO-92 package. Below is the pinout:
| Pin | Name | Description |
|---|---|---|
| 1 | GND | Ground connection |
| 2 | DQ | Data line for 1-Wire communication |
| 3 | VDD | Power supply (optional, can operate in parasite mode) |
Note: In parasite power mode, the sensor can operate without a dedicated VDD pin by drawing power from the data line.
To use the DS18B20 sensor, follow these steps:
Below is an example of how to use the DS18B20 sensor with an Arduino UNO. This code reads the temperature and displays it on the Serial Monitor.
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin connected to the DS18B20 data line
#define ONE_WIRE_BUS 2
// Create a OneWire instance to communicate with the sensor
OneWire oneWire(ONE_WIRE_BUS);
// Pass the OneWire instance to the DallasTemperature library
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600); // Initialize serial communication
sensors.begin(); // Start the DS18B20 sensor
}
void loop() {
sensors.requestTemperatures(); // Request temperature from the sensor
// Get temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Check if the reading is valid
if (temperatureC != DEVICE_DISCONNECTED_C) {
Serial.print("Temperature (C): ");
Serial.println(temperatureC);
} else {
Serial.println("Error: Sensor not found!");
}
delay(1000); // Wait 1 second before the next reading
}
Sensor Not Detected:
Incorrect Temperature Readings:
Intermittent Communication Failures:
Q: Can I connect multiple DS18B20 sensors to the same pin?
A: Yes, the DS18B20 supports multiple sensors on the same data line. Each sensor has a unique 64-bit serial code for identification.
Q: What is parasite power mode?
A: In parasite power mode, the sensor draws power from the data line instead of using the VDD pin. This reduces wiring but requires careful timing during temperature conversion.
Q: How do I increase the resolution of the temperature readings?
A: The DS18B20 supports programmable resolution (9 to 12 bits). Use the DallasTemperature library to configure the desired resolution.
Q: What is the maximum cable length for the DS18B20?
A: The maximum cable length depends on factors like pull-up resistor value and cable quality. Typically, lengths up to 30 meters are achievable with proper wiring and a strong pull-up resistor.
By following this documentation, you can effectively integrate the DS18B20 temperature sensor into your projects and troubleshoot common issues.