The DS18B20 is a digital temperature sensor that provides accurate temperature readings over a wide range (-55°C to +125°C). It communicates using the 1-Wire protocol, 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 versatile and robust 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) |
The DS18B20 is available 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) |
Wiring the Sensor:
Pull-Up Resistor:
Multiple Sensors:
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
// Setup a oneWire instance to communicate with any 1-Wire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to 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 sensor
// Get temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Print temperature to Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
delay(1000); // Wait 1 second before next reading
}
No Temperature Reading:
Incorrect Temperature Values:
Multiple Sensors Not Detected:
getAddress()
function in the DallasTemperature library to retrieve each sensor's unique address.Q: Can I use the DS18B20 with a Raspberry Pi?
A: Yes, the DS18B20 is compatible with Raspberry Pi. You can use libraries such as w1thermsensor
to interface with the sensor.
Q: What is parasite power mode?
A: Parasite power mode allows the sensor to operate without a dedicated power supply by drawing power from the data line. This requires a pull-up resistor and is suitable for low-power applications.
Q: How many sensors can I connect to a single data line?
A: Theoretically, you can connect up to 100 sensors on a single data line, but this depends on factors like cable length and power supply.
Q: Can the DS18B20 measure negative temperatures?
A: Yes, the DS18B20 can measure temperatures as low as -55°C. Negative values are returned as signed integers in the library.
By following this documentation, you can effectively integrate the DS18B20 temperature sensor into your projects for accurate and reliable temperature monitoring.