Measure Temperature of Liquids and Gases with DS18B20 Sensor

Introduction

The ability to accurately Measure Temperature of Liquids and Gases with DS18B20 Sensor is crucial in various applications, ranging from scientific research to industrial processes. The integration of the DS18B20 Temperature Sensor with Arduino offers a versatile and precise solution for such temperature monitoring tasks. This project utilizes an Arduino UNO microcontroller, a widely-used development board known for its flexibility, along with the DS18B20 sensor, resistors, jumper wires, and a breadboard. By implementing this setup, one can create a reliable temperature sensing system capable of measuring the thermal conditions of liquids and gases with high accuracy. Whether applied in laboratories, industrial facilities, or even in home automation, this project showcases the practicality of the DS18B20 sensor in diverse temperature measurement scenarios.

Hardware Required

You will require the following Hardware Components for the How to Measure Temperature of Liquids and Gases with DS18B20 Sensor

Components#Buy From Amazon
Arduino UNO1Buy Link
DS18B20 Temperature Sensor1Buy Link
Resistors 4.7K1Buy Link
9v DC Adapter (Optional)1Buy Link
Jumper WiresFewBuy Link
Breadboard1Buy Link

What is a DS18B20 sensor?

The DS18B20, produced by Maxim Integrated (formerly Dallas Semiconductor), is a cost-effective yet advanced digital temperature sensor with a wide range (-55ºC to +125ºC) and precision exceeding ±0.5°C from -10°C to +85°C. Available in TO-92 and waterproof probe forms, it enables measurements in liquids and gases. Using the 1-Wire communication bus, proprietary to Maxim Integrated, it allows communication over a single conductor.

The 1-Wire bus supports multiple sensors on the same line and longer cables compared to other systems. With an alarm system for upper and lower limits, the DS18B20 is ideal for temperature control networks in domestic and industrial settings, such as managing HVAC systems in commercial buildings.

How does the DS18B20 work?

As mentioned, the DS18B20 sensor is more intricate internally than initially apparent. It comprises a processor with multiple modules, tasked with overseeing communication, temperature measurement, and alarm system management.

arduino-ds18b20-funcionamiento

A key advantage of DS18B20 is its 1-Wire communication bus, enabling transmission through a single data cable with intricate timing. The downside is the complex code required, imposing a high processor load, resulting in a total acquisition time of 750ms.

The 1-Wire system allows devices to be powered over the data line, either in parasitic mode or with a separate power source between 3.0V and 5.5V. A 4.7k pull-up resistor is essential for proper 1-Wire bus operation. Each sensor on the bus has a factory-recorded 64-bit ROM memory, with the first 8 bits representing the family (0x28 for DS18B20), the next 48 bits as the unique serial number, and the last 8 bits as a CRC

arduino-ds18b20-one-wire

The 1-Wire network can potentially support over 218 billion DS18B20 devices and about 268 million device families, practically allowing for infinite devices. DS18B20 resolution is configurable to 9, 10, 11, or 12 bits, with 12 bits as the default, offering temperature resolutions of 0.0625°C.

While the default resolution is 0.0625°C, the DS18B20 maintains considerable accuracy across the entire -10°C to +85°C range, as indicated in the graph showing average deviations at 3 sigma.

arduino-ds18b20-precision

Circuit Diagram

The following circuit shows you the connection of the How to Measure Temperature of Liquids and Gases with DS18B20 Sensor, Please make the connection carefully

As mentioned, the 1-Wire bus requires a 4.7k pull-up resistor. The sensor can be powere either directly through the Vdd pin or using the “parasite” mode, drawing power from the data line itself. The straightforward connection scheme is illustrated in the following image, allowing the sensor to be connected to any Arduino digital input.

Measure-temperature-of-liquids-and-gases-with-Arduino-and-DS18B20-Circuit

When illustrating the same setup and incorporating the layout for additional sensors (if required), we gain a clearer understanding of the 1-Wire bus structure.

Measure-temperature-of-liquids-and-gases-with-Arduino-and-DS18B20-Circuit-2

To utilize parasitic mode, connecting Vdd of all devices to GND is sufficient. This arrangement enables the sensors to draw power from the Vq data line. The assembly with parasite mode would resemble the following.

Measure-temperature-of-liquids-and-gases-with-Arduino-and-DS18B20-Circuit-3

Installing Arduino IDE Software

First, you will require to Download the updated version of Arduino IDE Software and Install it on your PC or laptop. if you Learn How to install the Arduino step-by-step guide then click on how to install Arduino Button given Blow

Code

To read DS18B20 temperatures, employ the 1-Wire library and the Dallas Temperature library, and in the first example, read a single sensor on digital pin 5.

//For more Projects: www.arduinocircuit.com

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

const int oneWirePin = 5;

OneWire oneWireBus(oneWirePin);
DallasTemperaturesensor(&oneWireBus);

void setup() {
  Serial.begin(9600);
  sensor.begin();
}

void loop() {
    Serial.println("Reading temperatures: ");
  sensor.requestTemperatures();

  Serial.print("Temperature at sensor 0: ");
  Serial.print(sensor.getTempCByIndex(0));
  Serial.println(" ºC");

  delay(1000);
}

When employing the getTempCByIndex function, the index represents the sensor number. While this function allows reading multiple sensors on a bus, identifying sensors by index can be problematic.

In the case of multiple sensors, it’s common to access them directly through their 64-bit addresses. To obtain these addresses, use the provided sketch, which scans the 1-Wire bus and displays the hexadecimal address (grouped into 8 two-digit numbers) on the screen.

//For more Projects: www.arduinocircuit.com

#include <OneWire.h>

const int oneWirePin = 5;
OneWire oneWireBus(oneWirePin);

void setup(void) {
  Serial.begin(9600);
  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  bytedata[12];
  byte addr[8];
  
  Serial.println("Searching for 1-Wire devices");
  while(oneWireBus.search(addr)) {
    Serial.println("1-Wire device found at address");
    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i], HEX);
      if (i < 7) {
        Serial.print(", ");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("Device error, invalid CRC!\n");
        return;
    }
  }
  Serial.println("Search completed");
  oneWireBus.reset_search();
  return;
}

void loop(void) {
  // nothing to do here
}

With the device addresses acquire, multiple sensors on the same 1-Wire bus can be read. In the subsequent example, we read two sensors—one located inside and the other outside a home—by accessing them through their respective addresses.

//For more Projects: www.arduinocircuit.com

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

const int oneWirePin = 5;

OneWire oneWireBus(oneWirePin);
DallasTemperature sensors(&oneWireBus);

DeviceAddress insideThermometer = { 0x28, 0x94, 0xE2, 0xDF, 0x02, 0x00, 0x00, 0xFE };
DeviceAddress outsideThermometer = { 0x28, 0x6B, 0xDF, 0xDF, 0x02, 0x00, 0x00, 0xC0 };

void setup(void)
{
  Serial.begin(9600);
  sensors.begin();
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print(tempC);
  Serial.println(" ºC");
  }
}

void loop(void)
{

  Serial.println("Reading temperatures");
  sensors.requestTemperatures();
  
  Serial.print("Indoor temperature: ");
  printTemperature(insideThermometer);
  Serial.print("Outdoor temperature: ");
  printTemperature(outsideThermometer);
  Serial.println("-------");
  
  delay(2000);
}

Applications

  1. Industrial Processes: Used to monitor and control temperature in industrial settings such as manufacturing and chemical processes.
  2. Scientific Research: Applied in laboratories for accurate temperature measurements in experiments and studies.
  3. Home Automation: Utilized in smart home systems for temperature monitoring and control.
  4. Weather Stations: Incorporated into weather stations to provide accurate temperature data for meteorological observations.

Leave a Comment


error: