The DS18B20 is a digital temperature sensor that communicates over a 1-Wire interface, requiring only one data line (and ground) for communication. It provides accurate temperature readings in the range of -55°C to +125°C with a user-selectable resolution of 9 to 12 bits. The sensor is widely used in applications such as weather stations, home automation systems, industrial temperature monitoring, and HVAC systems due to its simplicity, reliability, and precision.
Key features of the DS18B20 include:
Parameter | Value |
---|---|
Temperature Range | -55°C to +125°C |
Accuracy | ±0.5°C (-10°C to +85°C) |
Resolution | 9 to 12 bits (programmable) |
Supply Voltage | 3.0V to 5.5V |
Communication Protocol | 1-Wire |
Max Current Consumption | 1.5 mA during conversion |
Standby Current | 750 nA (typical) |
Conversion Time | 93.75 ms (9-bit) to 750 ms (12-bit) |
Unique 64-bit ROM Code | Yes |
The DS18B20 is typically available in a 3-pin TO-92 package. The pinout is as follows:
Pin Number | Name | Description |
---|---|---|
1 | GND | Ground |
2 | DQ | Data line for 1-Wire communication (requires a pull-up resistor) |
3 | VDD | Power supply (optional for parasitic power mode) |
Note: The DS18B20 can operate in "parasitic power mode," where it draws power directly from the data line (DQ) and does not require a connection to the VDD pin.
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
// 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); // Start serial communication
sensors.begin(); // Initialize the DS18B20 sensor
Serial.println("DS18B20 Temperature Sensor Example");
}
void loop() {
sensors.requestTemperatures(); // Request temperature readings
float temperatureC = sensors.getTempCByIndex(0); // Get temperature in Celsius
if (temperatureC != DEVICE_DISCONNECTED_C) {
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
} else {
Serial.println("Error: Sensor not found!");
}
delay(1000); // Wait 1 second before the next reading
}
Sensor Not Detected:
Incorrect Temperature Readings:
Multiple Sensors on the Same Bus Not Working:
Parasitic Power Mode Issues:
Q: Can I use the DS18B20 with a 3.3V microcontroller?
A: Yes, the DS18B20 operates with a supply voltage range of 3.0V to 5.5V, making it compatible with 3.3V systems.
Q: How many DS18B20 sensors can I connect to a single data line?
A: Theoretically, you can connect up to 100 sensors on the same 1-Wire bus, but practical limitations such as wire length and capacitance may reduce this number.
Q: What is the default resolution of the DS18B20?
A: The default resolution is 12 bits, but it can be configured to 9, 10, or 11 bits for faster conversion times.
Q: Can the DS18B20 measure negative temperatures?
A: Yes, the DS18B20 can measure temperatures as low as -55°C. Negative temperatures are represented in two's complement format.
Q: Is the DS18B20 waterproof?
A: The standard DS18B20 is not waterproof, but waterproof versions are available in sealed stainless steel tubes for outdoor or liquid temperature measurements.