The DS18B20 is a digital temperature sensor manufactured by DF Robot, with the part ID "Temperature Sensor." It is designed to provide accurate temperature readings in the range of -55°C to +125°C. The sensor communicates using a 1-Wire interface, which allows multiple sensors to be connected to a single data line. This makes it an excellent choice for applications requiring temperature monitoring in environments such as industrial systems, weather stations, and home automation.
The DS18B20 is a robust and versatile sensor with the following key specifications:
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) |
Maximum Current Draw | 1.5mA during conversion |
Standby Current | 750nA (typical) |
Response Time | < 750ms (12-bit resolution) |
Package Type | TO-92 or waterproof probe |
The DS18B20 has three pins, as described in the table below:
Pin Name | Pin Number | Description |
---|---|---|
GND | 1 | Ground pin, connects to the ground of the circuit. |
DQ | 2 | Data pin, used for 1-Wire communication. |
VDD | 3 | Power supply pin, connects to 3.0V to 5.5V. |
Note: A pull-up resistor (typically 4.7kΩ) is required on the DQ line for proper communication.
Wiring the Sensor:
Programming the Sensor:
Reading Temperature:
Below is an example of how to use the DS18B20 with an Arduino UNO:
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin connected to the DS18B20 data line
#define ONE_WIRE_BUS 2
// Initialize the OneWire and DallasTemperature libraries
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600); // Start serial communication
sensors.begin(); // Initialize the DS18B20 sensor
Serial.println("DS18B20 Temperature Sensor Initialized");
}
void loop() {
sensors.requestTemperatures(); // Request temperature readings
float temperatureC = sensors.getTempCByIndex(0); // Get temperature in Celsius
// Check if the reading is valid
if (temperatureC != DEVICE_DISCONNECTED_C) {
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
} else {
Serial.println("Error: Sensor not connected!");
}
delay(1000); // Wait 1 second before the next reading
}
No Temperature Reading:
Incorrect Temperature Values:
Sensor Not Detected:
Slow Response Time:
Q1: Can I connect multiple DS18B20 sensors to the same data line?
Yes, the DS18B20 supports multiple sensors on a single 1-Wire bus. Each sensor has a unique 64-bit ROM code for identification.
Q2: What is the maximum cable length for the DS18B20?
The maximum cable length depends on the environment and power supply. Typically, lengths up to 30 meters are achievable with proper pull-up resistance and shielding.
Q3: Can the DS18B20 measure negative temperatures?
Yes, the DS18B20 can measure temperatures as low as -55°C.
Q4: Is the DS18B20 waterproof?
The standard DS18B20 is not waterproof, but waterproof versions are available for outdoor or liquid temperature measurements.
Q5: What happens if the sensor is disconnected during operation?
The library will return a value of DEVICE_DISCONNECTED_C
to indicate the sensor is not connected.