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

How to Use DS18B20: Examples, Pinouts, and Specs

Image of DS18B20Design with DS18B20 in Cirkit Designer

Introduction

The DS18B20 is a digital temperature sensor manufactured by DS18B20. It communicates over a 1-Wire bus, requiring only one data line (and ground) for communication. This sensor provides temperature readings in Celsius with a resolution ranging from 9 to 12 bits, making it highly versatile for applications requiring precise temperature monitoring. Its compact design and ease of integration make it a popular choice for hobbyists and professionals alike.

Explore Projects Built with DS18B20

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 ESP8266 NodeMCU with DS18B20 Temperature Sensor Monitoring: A project utilizing DS18B20 in a practical application
ESP8266 NodeMCU with DS18B20 Temperature Sensor Monitoring

This circuit features an ESP8266 NodeMCU microcontroller connected to a DS18B20 temperature sensor. The sensor's data line (DQ) is connected to the D2 pin of the NodeMCU through a 4.7k ohm pull-up resistor, which is a common configuration for one-wire temperature sensors. The sensor is powered by the 3.3V supply from the NodeMCU, and both the sensor and the NodeMCU share a common ground.

Open Project in Cirkit Designer
Image of Arduino UNO with Multiple DS18B20 Sensors for Temperature Monitoring: A project utilizing DS18B20 in a practical application
Arduino UNO with Multiple DS18B20 Sensors for Temperature Monitoring

This circuit is designed to monitor temperatures using multiple DS18B20 1-Wire temperature sensors connected to an Arduino UNO microcontroller. The sensors are powered by the Arduino's 5V output and share a common data line (DQ) connected to digital pin 2 through a 4.7kΩ pull-up resistor, allowing for simultaneous temperature readings. The Arduino runs a sketch that reads temperatures from each sensor and outputs the readings to the serial monitor in both Celsius and Fahrenheit.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

The DS18B20 is designed to operate efficiently in a wide range of environments. Below are its 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 to 12 bits)
Communication Protocol 1-Wire
Max Current Consumption 1.5mA during conversion
Standby Current 750nA (typical)
Conversion Time 93.75ms (12-bit resolution)
Package Types TO-92, SOIC-8, or waterproof probe

Pin Configuration and Descriptions

The DS18B20 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.

Usage Instructions

The DS18B20 is straightforward to use in a circuit, thanks to its 1-Wire communication protocol. Below are the steps and considerations for using the sensor:

Circuit Connection

  1. Basic Wiring:

    • Connect the GND pin to the ground of your circuit.
    • Connect the DQ pin to a digital I/O pin of your microcontroller (e.g., Arduino).
    • Connect a 4.7kΩ pull-up resistor between the DQ pin and the VDD pin (or the power supply line if using parasite power mode).
    • If not using parasite power mode, connect the VDD pin to a 3.3V or 5V power supply.
  2. Parasite Power Mode:

    • Leave the VDD pin unconnected.
    • Ensure the pull-up resistor is properly connected to the DQ pin.

Arduino UNO Example Code

Below is an example of how to use the DS18B20 with an Arduino UNO. This code reads the temperature and displays it on the Serial Monitor.

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

// Pin where the DS18B20 data line is connected
#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); // Initialize serial communication at 9600 baud
  sensors.begin();    // Start the DS18B20 sensor
}

void loop() {
  sensors.requestTemperatures(); // Request temperature from the sensor
  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 detected!");
  }
  
  delay(1000); // Wait 1 second before the next reading
}

Important Considerations and Best Practices

Troubleshooting and FAQs

Common Issues and Solutions

  1. Sensor Not Detected:

    • Check the wiring and ensure the pull-up resistor is correctly connected.
    • Verify that the DQ pin is connected to the correct microcontroller pin.
    • Ensure the sensor is powered correctly (VDD or parasite power mode).
  2. Incorrect Temperature Readings:

    • Verify the accuracy of the power supply voltage.
    • Check for noise or interference on the data line.
    • Ensure the sensor is not exposed to temperatures outside its operating range.
  3. Multiple Sensors on the Same Bus:

    • Use the getAddress() function in the DallasTemperature library to identify each sensor's unique address.
    • Ensure all sensors are properly connected with pull-up resistors.

FAQs

Q: Can I use multiple DS18B20 sensors on 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 sensor draws power directly from the data line, eliminating the need for a dedicated VDD connection.

Q: How do I increase the accuracy of temperature readings?
A: Use the highest resolution (12-bit) setting and ensure the sensor is properly calibrated and powered.

Q: Can the DS18B20 measure negative temperatures?
A: Yes, the DS18B20 can measure temperatures as low as -55°C.

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