Stufin
Home Quick Cart Profile

DS18B20 Digital Temperature Sensor Module

Buy Now

VCC

Power supply pin (typically 3.3V or 5V)

GND

Ground pin

DQ

1-Wire data pin

Operating Conditions

Operating Temperature

-55C to 125C

Storage Temperature

-65C to 150C

Supply Voltage

3.0V to 5.5V

Supply Current

1.5mA (active), 1A (standby)

Applications

The DS18B20 Digital Temperature Sensor Module is suitable for a wide range of IoT applications, including

Environmental monitoring

Industrial automation

Medical devices

HVAC systems

Automotive systems

Consumer electronics

Conclusion

The DS18B20 Digital Temperature Sensor Module is a reliable and accurate temperature sensing component suitable for a variety of IoT applications. Its high accuracy, wide temperature range, and low power consumption make it an ideal choice for systems requiring precise temperature measurement.

Pin Configuration

  • DS18B20 Digital Temperature Sensor Module Pinout Guide
  • The DS18B20 Digital Temperature Sensor Module is a popular and widely used temperature sensing component in IoT projects. This module features a single-wire interface, making it easy to connect and integrate into various microcontroller-based systems. Here's a detailed explanation of each pin on the DS18B20 module:
  • Pinout Structure:
  • The DS18B20 module typically comes with a 3-pin or 4-pin connector, depending on the manufacturer and version. The 3-pin version is more common and will be the focus of this guide.
  • 3-Pin DS18B20 Module Pinout:
  • 1. GND (Ground) Pin:
  • Function: Provides a ground connection for the module.
  • Connection: Connect to the Ground (GND) pin on your microcontroller or power supply.
  • 2. VCC (Power) Pin:
  • Function: Supplies power to the module.
  • Connection: Connect to a 3.3V or 5V power supply, depending on the module's specified operating voltage.
  • 3. DQ (Data) Pin:
  • Function: Carries the digital temperature data from the sensor to the microcontroller.
  • Connection: Connect to a digital input pin on your microcontroller.
  • Note: Some DS18B20 modules may have a 4-pin connector, which includes an additional pin for parasite power. If your module has 4 pins, the additional pin is usually labeled "P" or "Vdd" and serves as an optional power input for parasite power mode.
  • Connection Diagram:
  • Here's a sample connection diagram to illustrate how to connect the DS18B20 module to a microcontroller (e.g., Arduino):
  • ```
  • +---------------+
  • | DS18B20 |
  • | Module |
  • +---------------+
  • |
  • |
  • v
  • +---------------+ +---------------+
  • | GND | | | GND |
  • +---------------+ --> +---------------+
  • |
  • |
  • v
  • +---------------+ +---------------+
  • | VCC | | | 3.3V/5V |
  • +---------------+ --> +---------------+
  • |
  • |
  • v
  • +---------------+ +---------------+
  • | DQ | | | Digital |
  • | | --> | | Input Pin |
  • +---------------+ +---------------+
  • ```
  • Important Considerations:
  • When connecting the DS18B20 module, ensure that the power supply voltage (VCC) matches the module's specified operating voltage.
  • Use a suitable pull-up resistor (e.g., 4.7k) between the VCC and DQ pins to enable the 1-Wire communication protocol.
  • Take care when handling the module to avoid damaging the sensor or its internal components.
  • By following this pinout guide, you can successfully connect and integrate the DS18B20 Digital Temperature Sensor Module into your IoT project.

Code Examples

DS18B20 Digital Temperature Sensor Module Documentation
Overview
The DS18B20 is a digital temperature sensor module that provides a high-accuracy and high-reliability temperature measurement solution. It is a popular choice for IoT projects that require temperature monitoring, such as weather stations, industrial automation, and smart home systems.
Technical Specifications
Operating temperature range: -55C to +125C
 Accuracy: 0.5C (between -10C to +85C)
 Resolution: 9-bit to 12-bit (configurable)
 Communication protocol: 1-Wire ( Dallas Semiconductor protocol)
 Power supply: 3.0V to 5.5V
Hardware Connection
The DS18B20 module typically has three pins:
VCC: Connect to a power supply (3.0V to 5.5V)
 GND: Connect to ground
 DQ (Data): Connect to a digital input pin on the microcontroller
Software Examples
Here are three code examples demonstrating how to use the DS18B20 digital temperature sensor module in various contexts:
### Example 1: Arduino Temperature Monitoring
This example uses an Arduino Uno board to read the temperature from the DS18B20 module and display it on the serial monitor.
```c++
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Pin 2 for data communication
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
  Serial.begin(9600);
  sensors.begin();
}
void loop() {
  sensors.requestTemperatures();
  float temperature = sensors.getTempCByIndex(0);
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" C");
  delay(1000);
}
```
### Example 2: Raspberry Pi Python Script for Temperature Logging
This example uses a Raspberry Pi to read the temperature from the DS18B20 module and log it to a CSV file using Python.
```python
import os
import glob
import time
import csv
# Define the DS18B20 device file
device_folder = '/sys/bus/w1/devices/'
device_file = glob.glob(device_folder + '28')[0] + '/w1_slave'
def read_temperature():
    with open(device_file, 'r') as f:
        lines = f.readlines()
        if lines[0].strip()[-3:] == 'YES':
            temperature = lines[1].find('t=')
            if temperature != -1:
                temp_string = lines[1][temperature + 2:]
                temp_c = float(temp_string) / 1000.0
                return temp_c
    return None
while True:
    temperature = read_temperature()
    if temperature is not None:
        with open('temperature_log.csv', 'a', newline='') as csvfile:
            writer = csv.writer(csvfile)
            writer.writerow([time.strftime('%Y-%m-%d %H:%M:%S'), temperature])
    time.sleep(60)  # Log temperature every minute
```
### Example 3: MicroPython on ESP32 for Wi-Fi Temperature Monitoring
This example uses an ESP32 board running MicroPython to read the temperature from the DS18B20 module and send it to a remote server using Wi-Fi.
```python
import machine
import onewire
import ujson
import urequests
# Define the DS18B20 pin and Wi-Fi details
ds_pin = machine.Pin(4)
wifi_ssid = 'your_wifi_ssid'
wifi_password = 'your_wifi_password'
server_url = 'http://your-server.com/temperature'
# Initialize the DS18B20 and Wi-Fi
ds = onewire.OneWire(ds_pin)
dsDevices = ds.scan()
while True:
    # Read temperature from DS18B20
    temp = ds Devices[0].temperature
    print(f'Temperature: {temp} C')
# Connect to Wi-Fi
    wlan = machine.WLAN(machine.WLAN.STA_IF)
    wlan.active(True)
    wlan.connect(wifi_ssid, wifi_password)
# Send temperature to remote server
    data = {'temperature': temp}
    headers = {'Content-Type': 'application/json'}
    response = urequests.post(server_url, json=data, headers=headers)
    response.close()
# Wait for 1 minute before taking the next reading
    machine.sleep(60)
```
These examples demonstrate the basic usage of the DS18B20 digital temperature sensor module with various microcontrollers and programming languages. The code can be modified and expanded to suit specific project requirements.