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 capable of providing accurate temperature measurements in Celsius with a resolution of 9 to 12 bits. It features a unique 1-Wire interface, allowing multiple sensors to be connected to a single data line, simplifying wiring and reducing the number of required microcontroller pins. The sensor is widely used in applications such as environmental monitoring, HVAC systems, and industrial temperature control due to its ease of use and reliability.

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

Common Applications and Use Cases

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

Technical Specifications

  • 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 from 9 to 12 bits
  • Interface: 1-Wire protocol
  • Unique 64-bit Serial Code: Allows multiple sensors on the same bus
  • Power Modes: Parasitic power or external power
  • Package Options: TO-92, SOIC, and waterproof versions available

Pin Configuration and Descriptions

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

Pin Number Name Description
1 GND Ground pin
2 DQ Data pin (1-Wire communication line, requires a pull-up resistor)
3 VDD Power supply pin (can be omitted in parasitic power mode)

Usage Instructions

How to Use the DS18B20 in a Circuit

  1. Wiring the Sensor:

    • Connect the GND pin to the ground of the power supply.
    • Connect the VDD pin to a 3.3V or 5V power source (or leave it unconnected for parasitic power mode).
    • Connect the DQ pin to a digital I/O pin of the microcontroller. Use a 4.7kΩ pull-up resistor between the DQ pin and the power supply (VDD).
  2. Connecting Multiple Sensors:

    • Each DS18B20 has a unique 64-bit serial code, allowing multiple sensors to share the same data line.
    • Ensure that all sensors are connected in parallel, with a single pull-up resistor on the shared data line.
  3. Programming:

    • Use libraries such as the DallasTemperature library for Arduino to simplify communication with the sensor.

Important Considerations and Best Practices

  • Pull-Up Resistor: Always use a 4.7kΩ pull-up resistor on the data line to ensure proper communication.
  • Cable Length: For long cables, use twisted-pair or shielded cables to reduce noise and improve reliability.
  • Parasitic Power Mode: If using parasitic power mode, ensure the microcontroller can provide sufficient current during temperature conversions.
  • Temperature Resolution: Higher resolutions (e.g., 12-bit) require longer conversion times, so adjust your code timing accordingly.

Example Code for Arduino UNO

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

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

// Data wire is connected to pin 2 on the Arduino
#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 at 9600 baud
  sensors.begin();    // Initialize the DS18B20 sensor
}

void loop() {
  sensors.requestTemperatures(); // Send command to get temperature readings
  float temperatureC = sensors.getTempCByIndex(0); // Get temperature in Celsius
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");
  delay(1000); // Wait 1 second before reading again
}

Code Notes:

  • Replace ONE_WIRE_BUS with the pin number where the DS18B20's DQ pin is connected.
  • The getTempCByIndex(0) function retrieves the temperature of the first sensor on the bus. For multiple sensors, use their unique addresses.

Troubleshooting and FAQs

Common Issues and Solutions

  1. No Temperature Reading:

    • Ensure the pull-up resistor (4.7kΩ) is correctly connected between the DQ pin and VDD.
    • Verify that the sensor is properly powered (check voltage on the VDD pin).
  2. Incorrect or Fluctuating Readings:

    • Check for loose or poor connections in the circuit.
    • Use shielded cables for long-distance connections to reduce noise.
  3. Multiple Sensors Not Detected:

    • Ensure all sensors are connected in parallel with a single pull-up resistor.
    • Use the getAddress() function in the DallasTemperature library to retrieve each sensor's unique address.
  4. Parasitic Power Issues:

    • If using parasitic power mode, ensure the microcontroller can provide sufficient current during temperature conversions.
    • Consider using external power (connect VDD to 3.3V or 5V) for more reliable operation.

FAQs

Q: Can I use the DS18B20 with a 3.3V microcontroller?
A: Yes, the DS18B20 operates within a voltage range of 3.0V to 5.5V, making it compatible with 3.3V systems.

Q: How many DS18B20 sensors can I connect to a single data line?
A: Theoretically, you can connect up to 100 sensors on a single data line, but practical limits depend on cable length, power supply, and noise.

Q: What is the maximum cable length for the DS18B20?
A: The maximum cable length depends on the environment and wiring quality. Typically, lengths up to 30 meters are achievable with proper shielding and pull-up resistor values.

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

Q: How do I increase the resolution of the temperature readings?
A: Use the setResolution() function in the DallasTemperature library to configure the resolution (9 to 12 bits).

By following this documentation, you can effectively integrate the DS18B20 into your projects and troubleshoot common issues.