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

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

Image of DS18B20 Digital Temperature Sensor
Cirkit Designer LogoDesign with DS18B20 Digital Temperature Sensor in Cirkit Designer

Introduction

The DS18B20 is a digital temperature sensor manufactured by DF Robot, with the part ID "Temperature Sensor." It is designed to provide accurate temperature readings in the range of -55°C to +125°C. The sensor communicates using a 1-Wire interface, 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.

Explore Projects Built with DS18B20 Digital Temperature Sensor

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 Multi-Sensor Environmental Monitoring System
Image of diagrama tesis: A project utilizing DS18B20 Digital Temperature Sensor 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
Arduino UNO Based Temperature Monitoring System with DS18B20 Sensor
Image of DS18b20 sim test: A project utilizing DS18B20 Digital Temperature Sensor 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 with Multiple DS18B20 Sensors for Temperature Monitoring
Image of Interfacing Multiple DS18B20 Digital Temperature Sensors With Arduino UNO: A project utilizing DS18B20 Digital Temperature Sensor 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
ESP8266 NodeMCU with DS18B20 Temperature Sensor Monitoring
Image of SUHU: A project utilizing DS18B20 Digital Temperature Sensor 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

Explore Projects Built with DS18B20 Digital Temperature Sensor

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 diagrama tesis: A project utilizing DS18B20 Digital Temperature Sensor 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 DS18b20 sim test: A project utilizing DS18B20 Digital Temperature Sensor 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 Interfacing Multiple DS18B20 Digital Temperature Sensors With Arduino UNO: A project utilizing DS18B20 Digital Temperature Sensor 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
Image of SUHU: A project utilizing DS18B20 Digital Temperature Sensor 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

Common Applications and Use Cases

  • HVAC (Heating, Ventilation, and Air Conditioning) systems
  • Industrial temperature monitoring
  • Weather stations
  • Home automation and IoT projects
  • Data logging systems
  • Agricultural monitoring systems

Technical Specifications

The DS18B20 is a robust and versatile 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)
Response Time < 750ms (12-bit resolution)
Package Type TO-92 or waterproof probe

Pin Configuration and Descriptions

The DS18B20 has three pins, as described in the table below:

Pin Name Pin Number Description
GND 1 Ground pin, connects to the ground of the circuit.
DQ 2 Data pin, used for 1-Wire communication.
VDD 3 Power supply pin, connects to 3.0V to 5.5V.

Note: A pull-up resistor (typically 4.7kΩ) is required on the DQ line for proper communication.

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 VDD pin to a 3.3V or 5V power supply.
    • Connect the DQ pin to a digital I/O pin of your microcontroller (e.g., Arduino UNO) and add a 4.7kΩ pull-up resistor between the DQ pin and the VDD pin.
  2. Programming the Sensor:

    • The DS18B20 communicates using the 1-Wire protocol. Libraries such as the "OneWire" and "DallasTemperature" libraries for Arduino simplify communication.
  3. Reading Temperature:

    • Use the provided libraries to initialize the sensor, request temperature readings, and retrieve the data.

Arduino UNO Example Code

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

// Initialize the OneWire and DallasTemperature libraries
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

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

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 and Best Practices

  • Ensure the pull-up resistor (4.7kΩ) is properly connected to the DQ line.
  • Avoid long wires for the 1-Wire bus to minimize signal degradation.
  • Use waterproof versions of the sensor for outdoor or liquid temperature measurements.
  • If multiple sensors are connected to the same data line, each sensor must have a unique 64-bit ROM code for identification.

Troubleshooting and FAQs

Common Issues and Solutions

  1. No Temperature Reading:

    • Cause: The pull-up resistor is missing or incorrectly connected.
    • Solution: Verify the 4.7kΩ pull-up resistor is connected between the DQ pin and VDD.
  2. Incorrect Temperature Values:

    • Cause: Noise or interference on the 1-Wire bus.
    • Solution: Use shorter wires and ensure proper grounding.
  3. Sensor Not Detected:

    • Cause: Faulty wiring or incorrect pin connections.
    • Solution: Double-check all connections and ensure the sensor is powered.
  4. Slow Response Time:

    • Cause: High resolution (12-bit) is selected.
    • Solution: Reduce the resolution to 9 or 10 bits if faster response is needed.

FAQs

Q1: Can I connect multiple DS18B20 sensors to the same data line?
Yes, the DS18B20 supports multiple sensors on a single 1-Wire bus. Each sensor has a unique 64-bit ROM code for identification.

Q2: What is the maximum cable length for the DS18B20?
The maximum cable length depends on the environment and power supply. Typically, lengths up to 30 meters are achievable with proper pull-up resistance and shielding.

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

Q4: Is the DS18B20 waterproof?
The standard DS18B20 is not waterproof, but waterproof versions are available for outdoor or liquid temperature measurements.

Q5: What happens if the sensor is disconnected during operation?
The library will return a value of DEVICE_DISCONNECTED_C to indicate the sensor is not connected.