Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use DS18B20: Examples, Pinouts, and Specs

Image of DS18B20
Cirkit Designer LogoDesign with DS18B20 in Cirkit Designer

Introduction

The DS18B20 is a digital temperature sensor manufactured by DS18B20. It communicates over a 1-Wire interface, requiring only one data line (and ground) for communication. This sensor provides temperature readings with a resolution of 9 to 12 bits and operates within a temperature range of -55°C to +125°C. Its compact design and ease of use make it ideal for a wide range of applications, including HVAC systems, weather monitoring, industrial temperature control, and home automation.

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!
Arduino UNO Based Temperature Monitoring System with DS18B20 Sensor
Image of DS18b20 sim test: A project utilizing DS18B20 in a practical application
This circuit is designed to measure temperature using a DS18B20 sensor interfaced with an Arduino UNO. The Arduino reads temperature data from the sensor via a 1-Wire bus with a pull-up resistor and outputs the readings to the serial console.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO-Based Multi-Sensor Environmental Monitoring System
Image of diagrama tesis: A project utilizing DS18B20 in a practical application
This circuit involves an Arduino UNO microcontroller interfacing with a DS18B20 temperature sensor. The sensor is powered by the Arduino's 5V and GND pins, and its data pin is connected to a digital I/O pin on the Arduino, with a pull-up resistor in place. The setup is designed to read temperature data from the sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer
ESP8266 NodeMCU with DS18B20 Temperature Sensor Monitoring
Image of SUHU: A project utilizing DS18B20 in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Arduino UNO with Multiple DS18B20 Sensors for Temperature Monitoring
Image of Interfacing Multiple DS18B20 Digital Temperature Sensors With Arduino UNO: A project utilizing DS18B20 in a practical application
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.
Cirkit Designer LogoOpen Project in Cirkit Designer

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 DS18b20 sim test: A project utilizing DS18B20 in a practical application
Arduino UNO Based Temperature Monitoring System with DS18B20 Sensor
This circuit is designed to measure temperature using a DS18B20 sensor interfaced with an Arduino UNO. The Arduino reads temperature data from the sensor via a 1-Wire bus with a pull-up resistor and outputs the readings to the serial console.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of diagrama tesis: A project utilizing DS18B20 in a practical application
Arduino UNO-Based Multi-Sensor Environmental Monitoring System
This circuit involves an Arduino UNO microcontroller interfacing with a DS18B20 temperature sensor. The sensor is powered by the Arduino's 5V and GND pins, and its data pin is connected to a digital I/O pin on the Arduino, with a pull-up resistor in place. The setup is designed to read temperature data from the sensor.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of SUHU: 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.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Interfacing Multiple DS18B20 Digital Temperature Sensors With Arduino UNO: 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.
Cirkit Designer LogoOpen Project in Cirkit Designer

Technical Specifications

  • Manufacturer: DS18B20
  • Part ID: DS18B20
  • Temperature Range: -55°C to +125°C
  • Accuracy: ±0.5°C (from -10°C to +85°C)
  • Resolution: Programmable from 9 to 12 bits
  • Interface: 1-Wire
  • Operating Voltage: 3.0V to 5.5V
  • Current Consumption:
    • Active: 1 mA (typical)
    • Standby: 750 nA (typical)
  • Response Time: <750 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. Below is the pin configuration:

Pin Number Pin Name Description
1 GND Ground (0V reference)
2 DQ Data line for 1-Wire communication
3 VDD Power supply (3.0V to 5.5V)

Note: The DS18B20 can operate in "parasite power mode," where it draws power from the data line (DQ) instead of requiring a dedicated VDD connection.

Usage Instructions

How to Use the DS18B20 in a Circuit

  1. Wiring the Sensor:

    • Connect the GND pin to the ground of your circuit.
    • Connect the DQ pin to a digital I/O pin on your microcontroller.
    • Connect the VDD pin to a 3.3V or 5V power supply (or leave it unconnected for parasite power mode).
    • Place a 4.7 kΩ pull-up resistor between the DQ pin and the power supply (VDD). This is required for proper 1-Wire communication.
  2. Communication Protocol:
    The DS18B20 uses the 1-Wire protocol, which allows multiple devices to share the same data line. Each sensor has a unique 64-bit serial code, enabling individual addressing.

  3. Reading Temperature:

    • Send a "Convert T" command to initiate a temperature measurement.
    • Wait for the conversion to complete (up to 750 ms for 12-bit resolution).
    • Read the temperature data from the sensor's scratchpad memory.

Important Considerations and Best Practices

  • Use a decoupling capacitor (e.g., 0.1 µF) between VDD and GND to stabilize the power supply.
  • Avoid long wires for the data line to minimize signal degradation. If long wires are necessary, consider using shielded cables.
  • In parasite power mode, ensure the pull-up resistor is properly sized to provide sufficient current during temperature conversion.
  • When using multiple DS18B20 sensors on the same bus, ensure each sensor's unique address is correctly identified.

Example Code for Arduino UNO

Below is an example of how to interface the DS18B20 with an Arduino UNO using the popular OneWire and DallasTemperature libraries:

#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 reference to DallasTemperature library
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600); // Initialize serial communication
  sensors.begin();    // Start the DS18B20 sensor
  Serial.println("DS18B20 Temperature Sensor Example");
}

void loop() {
  sensors.requestTemperatures(); // Request temperature measurement
  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
}

Explanation of the Code:

  • The OneWire library handles communication with the DS18B20 over the 1-Wire protocol.
  • The DallasTemperature library simplifies temperature measurement and data retrieval.
  • The getTempCByIndex(0) function retrieves the temperature from the first sensor on the bus.

Troubleshooting and FAQs

Common Issues and Solutions

  1. Sensor Not Detected:

    • Ensure the wiring is correct and the pull-up resistor is properly connected.
    • Verify that the data pin is connected to the correct Arduino pin.
    • Check for loose connections or damaged components.
  2. Incorrect Temperature Readings:

    • Verify the power supply voltage is within the specified range (3.0V to 5.5V).
    • Ensure the pull-up resistor value is 4.7 kΩ.
    • Avoid placing the sensor near heat sources or in direct sunlight.
  3. Multiple Sensors on the Same Bus Not Working:

    • Ensure each sensor's unique address is correctly identified in the code.
    • Use a separate pull-up resistor for each sensor if necessary.

FAQs

Q1: Can the DS18B20 operate without a dedicated power supply?
Yes, the DS18B20 can operate in parasite power mode, drawing power from the data line. However, this mode may not work reliably in all setups, especially with long wires or multiple sensors.

Q2: What is the maximum cable length for the DS18B20?
The maximum cable length depends on factors such as wire quality, pull-up resistor value, and power supply. In general, lengths up to 30 meters are achievable with proper wiring and shielding.

Q3: How do I increase the resolution of the temperature readings?
The resolution (9 to 12 bits) can be configured by writing to the sensor's configuration register. Refer to the DS18B20 datasheet for detailed instructions.

Q4: Can the DS18B20 measure negative temperatures?
Yes, the DS18B20 can measure temperatures as low as -55°C. Negative temperatures are represented in two's complement format in the sensor's data output.