Electronics

Temperature Sensor Module - DS18B20

AED 12.50

1

Description

The DS18B20 digital temperature sensor module features the renowned DS18B20 sensor, a widely recognized temperature sensing solution developed by Maxim Integrated (formerly Dallas Semiconductor). Renowned for its versatility, this sensor offers a remarkable level of accuracy, boasting a precision of 0.5°C across a broad temperature spectrum, ranging from a frigid -55°C to a scorching +125°C. Designed to be exceptionally adaptable, the Sensor Module is compatible with various platforms, including the Arduino, operating at 5 V, as well as electronics such as the ESP32 and Raspberry Pi, which utilize 3.3 V GPIO pins, thanks to its wide operating voltage range spanning from 3.0 to 5.5 V.

 

Package Includes:

  • 1x DS18B20 Temperature Sensor Module

Features:

  • DS18B20 Sensor: Utilizes the highly reliable DS18B20 digital temperature sensor produced by Maxim Integrated (formerly Dallas Semiconductor).
  • Temperature Range: Offers a wide temperature measurement range from -55°C to +125°C, making it suitable for various applications.
  • High Accuracy: Provides precise temperature measurements with an accuracy of ±0.5°C, ensuring reliable data.
  • Digital Interface: Communicates temperature data digitally, simplifying integration with microcontrollers like Arduino, ESP32, and Raspberry Pi.
  • One-Wire Interface: Operates on a single wire for data communication, reducing the complexity of wiring connections.
  • Wide Voltage Compatibility: Compatible with both 5 V systems (such as Arduino) and 3.3 V systems (like ESP32 and Raspberry Pi) due to its voltage tolerance range of 3.0 to 5.5 V.
  • Versatile Applications: Suitable for a wide range of applications, including environmental monitoring, temperature control, and more.
  • Compact Design: Compact and easy-to-mount module for convenient integration into projects.
  • Durable Construction: Built to withstand various environmental conditions, ensuring long-lasting performance.
  • Low Power Consumption: Operates with low power consumption, ideal for battery-powered applications.

 

Description:

 

The DS18B20 digital temperature sensor module is a highly regarded temperature sensing solution designed by Maxim Integrated (formerly Dallas Semiconductor). It stands out for its reliable performance, offering an accuracy level of 0.5°C across a broad temperature range spanning from -55°C to +125°C. This versatile Sensor Module is compatible with various microcontroller platforms, including the Arduino (operating at 5 V) and popular electronics like the ESP32 and Raspberry Pi, which use 3.3 V GPIO pins. Its adaptability stems from its operating voltage range, which extends from 3.0 to 5.5 V. One of the standout features of this sensor is its ability to communicate with the Arduino using just a single digital pin. This is made possible through the use of the Dallas Semiconductor 1-Wire® protocol, a communication method similar to I2C but with a wider operating range and slightly slower data rates. Another advantage is the capacity to connect multiple DS18B20 sensors on a single 1-Wire bus, each uniquely identified by a 64-bit serial code. For added flexibility, users can programmatically adjust the sensor's resolution to meet specific requirements. Options range from 9 to 12 bits, providing temperature precision of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C, respectively. The default setting is 12 bits, ensuring exceptional temperature accuracy.

 

Principle of Work:

the DS18B20 sensor module employs its internal components and the 1-Wire® communication protocol to measure temperature accurately and interface seamlessly with microcontrollers. This integration allows for temperature data retrieval and further processing, enabling a wide range of temperature-sensitive applications.

Internal Working of DS18B20 Sensor Module: The DS18B20 sensor module is built around the DS18B20 digital temperature sensor, which operates based on the principles of analog-to-digital conversion and digital communication.

  • the DS18B20 sensor contains a temperature-sensing element, typically a semiconductor material with a known temperature-resistance characteristic.
  • It utilizes this temperature-resistance relationship to measure the ambient temperature. As the temperature changes, the resistance of the sensing element changes accordingly.
  • The DS18B20 converts this resistance into a digital signal using an analog-to-digital converter (ADC) integrated within the sensor.
  • This digital temperature value is stored in the DS18B20's memory and made available for retrieval through its unique 64-bit serial code.

Interaction with Microcontroller (MCU):

  • To interface the DS18B20 sensor module with an MCU, such as an Arduino, ESP32, or Raspberry Pi, the 1-Wire® communication protocol is employed. The MCU sends specific commands to the DS18B20 using a single digital pin (typically the Data pin), and the sensor responds accordingly.
    1. The MCU initiates communication by sending a "Start Conversion" command to the DS18B20 sensor module.
    2. The DS18B20, upon receiving the command, begins the temperature conversion process.
    3. After a specific conversion time (which depends on the sensor's resolution settings), the MCU sends a request for temperature data.
    4. The DS18B20 sensor responds by transmitting the digital temperature data to the MCU.
    5. The MCU then processes and interprets this data to obtain the actual temperature reading.
    6. This temperature reading can be used for various applications, such as displaying the temperature on an LCD screen, logging data to a microSD card, or triggering specific actions based on temperature thresholds.

 

Pinout of the Board:

DS18B20 Description
GND GND
Out Connected to any digital pin
VCC 5V


Applications:

. Temperature Monitoring and Control:

  • HVAC systems: Used for controlling heating, ventilation, and air conditioning systems.
  • Home automation: Monitors and adjusts indoor temperatures for energy efficiency and comfort.

2. Weather Stations: Measures ambient temperature for weather monitoring and forecasting.

3. Industrial Automation:

  • Process control: Ensures temperature accuracy in industrial processes.
  • Equipment monitoring: Detects overheating in machinery to prevent damage.

4. Agriculture: Greenhouses: Maintains optimal growing conditions by monitoring and controlling temperature.

  • Livestock farming: Ensures the comfort and health of animals by regulating temperature in barns and enclosures.

5. Medical Devices: Blood storage units: Ensures proper temperature conditions for preserving medical samples.

 6. Scientific Research: Laboratories: Precisely measures and records temperatures for experiments and research.

7. Green Energy: Solar water heaters: Control the circulation of fluid to optimize solar heating systems.

8. Energy Efficiency: Energy management systems: Helps optimize energy consumption by regulating temperature in buildings.

9. Automotive Applications: Engine temperature monitoring: Ensures proper engine operation and prevents overheating.

  • Climate control: Maintains cabin temperature and comfort in vehicles.

10. Aquatic Systems: Aquariums and fish tanks: Regulate water temperature for aquatic life.

  • Swimming pool and spa temperature control.

11. Cold Storage: Warehouses and refrigerated storage units: Maintain a consistent temperature for preserving goods.

12. IoT Projects: Integrates with Internet of Things (IoT) projects for remote temperature monitoring and data logging.

 

 

Circuit:

 

  1. Connect the middle pin (Out) of the DS18B20 module to digital pin 2 on the Arduino.
  2. Connect the GND (Ground) of the DS18B20 module to the GND (Ground) on the Arduino.
  3. Connect the Vcc (Voltage supply) of the DS18B20 module to the 5V (5 Volts) on the Arduino.

 

Library: 

 

  1. Download the library ZIP file from the provided link: Arduino-Temperature-Control-Library.
  2. Open the Arduino IDE on your computer.
  3. Go to the "Sketch" menu, hover over "Include Library," and select "Add .ZIP Library..."
  4. A file dialog will open. Navigate to the location where you downloaded the library ZIP file (typically in your "Downloads" folder) and select it.
  5. Click the "Open" button to begin the library installation process.
  6. The Arduino IDE will automatically extract and install the library from the ZIP file. Once the installation is complete, you should see a confirmation message in the IDE's status bar.

 

Code:

the code continuously reads the temperature from the first DS18B20 temperature sensor connected to the Arduino and displays the temperature in both Celsius and Fahrenheit on the Serial Monitor, with a 1-second delay between readings. This allows you to monitor the temperature from the sensor in real-time through the Arduino IDE's Serial Monitor:

#include "OneWire.h"
#include "DallasTemperature.h"

// Define the pin to which the 1-Wire bus is connected:
#define ONE_WIRE_BUS 2

// Create an instance of the OneWire class to communicate with the OneWire devices:
OneWire oneWire(ONE_WIRE_BUS);

// Pass the oneWire reference to the DallasTemperature library:
DallasTemperature sensors(&oneWire);

void setup() {
  // Begin serial communication at a baud rate of 9600:
  Serial.begin(9600);

  // Initialize the DallasTemperature library:
  sensors.begin();
}

void loop() {
  // Request temperature readings from all devices on the bus:
  sensors.requestTemperatures();

  // Fetch the temperature in degrees Celsius for the first device on the bus:
  float tempC = sensors.getTempCByIndex(0);

  // Fetch the temperature in degrees Fahrenheit for the first device on the bus:
  float tempF = sensors.getTempFByIndex(0);

  // Print the temperature readings in both Celsius and Fahrenheit:
  Serial.print("Temperature: ");
  Serial.print(tempC);
  Serial.print(" \xC2\xB0C | "); // Display the degree symbol for Celsius
  Serial.print(tempF);
  Serial.println(" \xC2\xB0F"); // Display the degree symbol for Fahrenheit

  // Wait for a short interval before taking the next reading:
  delay(1000);
}

 

  1. Library Inclusions: It includes two libraries: OneWire and DallasTemperature. These libraries are necessary for communicating with the DS18B20 temperature sensor via the 1-Wire protocol.

  2. Pin Definition: It defines the Arduino pin to which the DS18B20 sensor's 1-Wire bus is connected. In this code, it's set to digital pin 2 (#define ONE_WIRE_BUS 2).

  3. Library Initialization: It initializes the OneWire and DallasTemperature libraries with the 1-Wire bus reference.

  4. Setup Function:

    • It initializes serial communication with the Arduino IDE's Serial Monitor at a baud rate of 9600.
    • It starts up the DallasTemperature library.
  5. Loop Function:

    • Inside the loop function, it performs the following tasks in a continuous loop:

    • sensors.requestTemperatures();: This command sends a request to all DS18B20 devices on the bus to perform a temperature conversion.

    • sensors.getTempCByIndex(0);: This retrieves the temperature in degrees Celsius from the first DS18B20 device on the bus (index 0).

    • sensors.getTempFByIndex(0);: This retrieves the temperature in degrees Fahrenheit from the same device.

    • It then prints the temperature readings in both Celsius and Fahrenheit with appropriate units to the Serial Monitor. For example, "Temperature: 25.00 °C | 77.00 °F."

    • It adds a delay of 1 second using delay(1000); before taking the next temperature reading. This delay prevents the code from continuously requesting temperature readings too quickly.

 

Technical Details:

  • Programmable Digital Temperature Sensor
  • Communicates using 1-Wire method
  • Operating voltage: 3V to 5V
  • Temperature Range: -55°C to +125°C
  • Accuracy: ±0.5°C
  • Output Resolution: 9-bit to 12-bit (programmable)
  • Unique 64-bit address enables multiplexing
  • Conversion time: 750ms at 12-bit

 

Resources:

Comparisons:

The DS18B20 and DHT11 are two different types of temperature and humidity sensors, each with its own characteristics and use cases.

Choosing Between DS18B20 and DHT11:

  • Temperature-Only vs. Temperature and Humidity: If you only need temperature data, the DS18B20 is a better choice due to its higher accuracy and wider temperature range. If you require both temperature and humidity measurements, the DHT11 is suitable.
  • Accuracy: If precise temperature readings are critical, the DS18B20 is more accurate.
  • Application: Consider your specific application requirements when choosing between these sensors. For applications like weather stations or environmental monitoring that require both temperature and humidity data, the DHT11 may be preferable. If you need accurate temperature measurements in a broader range of applications, the DS18B20 is a better fit.
DHT11 Specifications DS18B20
Humidity and temperature Measurement Temperature
0 – 50° C / ± 2° C Temperature Range -55 – 125° C / ± 0.5° C
20 – 80 / ± 5 % Humidity Range Nil
1 wire Communication Protocol  1 wire
1 Hz one reading every second Sampling Rate
3 – 5 V Operating Voltage 3 – 5 V
2.5 mA Minimum current 10 mA