Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use DS18B20 Temperature: Examples, Pinouts, and Specs

Image of DS18B20 TemperatureDesign with DS18B20 Temperature in Cirkit Designer

Introduction

The DS18B20 is a digital temperature sensor that provides accurate temperature readings in the range of -55°C to +125°C. It communicates using a 1-Wire interface, which allows multiple sensors to be connected to a single data line. This feature makes it highly versatile and suitable for a wide range of applications, including:

The DS18B20 is known for its simplicity, reliability, and ability to operate over long distances with minimal wiring.

Explore Projects Built with DS18B20 Temperature

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Arduino UNO with DS18B20 Temperature Sensor Monitoring: A project utilizing DS18B20 Temperature in a practical application
Arduino UNO with DS18B20 Temperature Sensor Monitoring

This circuit is designed to measure temperature using a DS18B20 temperature sensor interfaced with an Arduino UNO microcontroller. The sensor's data line is connected to digital pin 4 of the Arduino through a 4.7k Ohm pull-up resistor, and the Arduino runs a sketch that reads the temperature in Celsius and Fahrenheit, then outputs the readings to the serial monitor. The purpose of the circuit is to provide a digital temperature reading for monitoring or control applications.

Open Project in Cirkit Designer

Technical Specifications

The DS18B20 has the following key technical details:

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)
Resolution Programmable: 9-bit to 12-bit
Interface 1-Wire
Maximum Current (Active) 1.5 mA
Standby Current 750 nA
Conversion Time 93.75 ms (12-bit resolution)
Package Types TO-92, SOIC, or waterproof probe

Pin Configuration and Descriptions

The DS18B20 typically comes in a 3-pin TO-92 package. The pinout is as follows:

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 connection, drawing power from the data line.

Usage Instructions

Connecting the DS18B20 to a Circuit

To use the DS18B20, follow these steps:

  1. Connect the GND pin to the ground of your circuit.
  2. Connect the DQ pin to a digital I/O pin on your microcontroller (e.g., Arduino).
  3. Use a 4.7kΩ pull-up resistor between the DQ pin and the VDD pin to ensure proper communication.
  4. Optionally, connect the VDD pin to a 3.3V or 5V power supply. If using parasite power mode, leave the VDD pin unconnected.

Example Circuit with Arduino UNO

Below is an example of how to connect the DS18B20 to an Arduino UNO:

Arduino Code Example

The following code demonstrates how to read temperature data from the DS18B20 using the Arduino IDE. This example uses the OneWire and DallasTemperature libraries, which can be installed via the Arduino Library Manager.

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is connected to Arduino digital pin 2
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass the oneWire reference to 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
  
  // 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
}

Important Considerations

Troubleshooting and FAQs

Common Issues and Solutions

  1. No Temperature Reading:

    • Ensure the sensor is properly connected to the circuit.
    • Verify the pull-up resistor is correctly placed between the DQ pin and VDD.
    • Check the wiring for loose connections or shorts.
  2. Incorrect Temperature Values:

    • Ensure the sensor is not exposed to temperatures outside its operating range.
    • Verify the resolution settings in your code.
  3. Device Not Detected:

    • Confirm the correct digital pin is defined in the code.
    • Check for multiple sensors on the same data line and ensure unique addresses are used.
  4. Intermittent Readings:

    • Reduce cable length or use a lower pull-up resistor value (e.g., 2.2kΩ).
    • Ensure the power supply is stable and within the operating voltage range.

FAQs

Q: Can I connect multiple DS18B20 sensors to the same data line?
A: Yes, the DS18B20 supports multiple devices on the same 1-Wire bus. Each sensor has a unique 64-bit address for identification.

Q: What is parasite power mode?
A: In parasite power mode, the DS18B20 draws power from the data line instead of requiring a dedicated VDD connection. This reduces wiring but may limit performance in some cases.

Q: How do I increase the accuracy of temperature readings?
A: Use the 12-bit resolution setting for maximum accuracy. Ensure the sensor is properly calibrated and not exposed to rapid temperature fluctuations.

Q: Can the DS18B20 be used in waterproof applications?
A: Yes, the DS18B20 is available in a waterproof probe version, making it suitable for liquid temperature measurements.

By following this documentation, you can effectively integrate the DS18B20 into your projects for reliable temperature monitoring.