Labs / Electronic modules

GraftSense - DS18B20-based Temperature Sensor Module (Open Version)

Author: Li Zisheng · Source: FreakStudio open documentation, v1.4 · License: CC BY 4.0 · Driver code (sensors/ds18b20_driver): MIT License

Contents
DS18B20 4.7k 55 125
DS18B20 U1 LED1 R1

I. Module Introduction

The temperature sensor module based on DS18B20 is a device that takes the DS18B20 chip as the core, equipped with a 4.7kΩ pull-up resistor, power filter capacitor and status indicator LED, adopts the 1-Wire (DIO) Communication Protocol, supports temperature measurement from -55℃ to + 125℃(default 12-bit resolution, accuracy of 0.0625℃), and can be quickly connected to the main control device through the GND, VCC, and DIO pins, which is suitable for scenarios such as environmental monitoring and home appliance temperature control.

II. Introduction to Major Chips

Here, in certain sections, we will take DS18B20 's domestic alternative chip MY18E20 as an example for introduction.

2.1 Chip Overview

DS18B20 is a high-precision programmable digital single-bus temperature measurement chip:

DS18B20 1 8 3 64 55 125 0.5

A microprocessor can, via a GPIO port, read and write the chip's control registers per software instructions of the 1-Wire protocol to configure parameters such as temperature measurement accuracy and alarm thresholds, and periodically collect digital temperature data.

2.2 Pin Definition

DS18B20 TO-92 MSOP8 SOP8 1 2 92 3 4 5

The DS18B20 is available in multiple packages including TO-92, MSOP8, and SOP8. The core functional pins and their definitions are as follows:

Pin No.NameFunction description
1GNDGround, provides the reference ground for the device.
2DQData Input/Output: uses an open-drain single-wire (1-Wire) interface; in parasitic power mode, this pin also supplies power to the device.
3VDDOptional VDD: connect a 3.0V~5.5V supply when externally powered; in parasitic power mode, VDD must be grounded.

2.3 Functional Block Diagram

DS18B20 1 2 3

MY18E20 The sensor mainly consists of the following components:

2.4 Performance Parameters

2.4.1 DC Electrical Parameters

DS18B20 55 125 2.5V 5.5V
DS18B20 10ms 55 1000
DS18B20 1.8V 5.5V 0.5 1.5 1.46V 1.56V

2.4.2 AC Electrical Parameters

DS18B20 10ms 1000 10 0 tLOW0 1 tLOW1
DS18B20 3s 0.5 0

DS18B20 has two core components in its AC electrical parameters:

11.3 55 125 1.8V 5.5V 40ms
DS18B20 15ms 100ms 500ms 2.4.1 2.4.3

2.4.3 Absolute Parameters

DS18B20 0.5V 6.0V 55 125 J-STD-020 2.4.3

2.5 Reference Circuit

DS18B20 1.8V 5.5V 10k MY18E20/MY18A20/MY18B20Z/MY18B20L 2.6
3.3V 1K 5V 100 500
MY18E20 100 480

2.6 Chip Configuration

None.

MY18E20/MY18S20/MY18Z20/MY18Z20L 12 14 0 bit0 bit1 MY18E20
DS18B20 12bit 14bit 125 0000 0111 1101 7D0h 2.7
MY18E20 bit7 bit0 bit6 2 0 5 7.2
MY18E20 64 8 48 9.1
MY18E20 2 3 10 1
9.3 4 R0 R1 MY18E20 9 14 15/500ms 1 12
9.4 MY18E20 64 1 0
DS18B20 2.7
MY18E20
10.4 MY18E20 5 8 3 F0h 33h 55h
MY18E20
MY18E20 3
MY18E20
44h MY18E20 E2
DS18B20 MY14820
DS18B20 1-wire 3
MY18E20 0 1 15us
DS18B20 480us 15-60us 60-240us
DS18B20 0 60us 120us 1 1us 15us 30us
1
DS18B20 0 2.7
1 MY18E20 64 44h
2 MY18E20 4eh 3 8

2.8 PCB Routing Precautions

None.

III. Circuit Engineering

3.1 Circuit Source Engineering

To obtain the source project of the circuit, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

The schematic diagram of this module is shown below:

SCH_Temperature Sensor Module Based on DS18B20_v1.0_2025-10-13.pdf 1.7 MB

DS18B20 U1 U2 LED1 R1 R2 C1 C2 v1.0

This module adopts a single-bus communication interface DIO: a simplified Maxim (formerly Dallas)-defined Communication Protocol:

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and the temperature sensor module based on DS18B20 uses the DIO interface to communicate with the main controller.

Here, we first use the HY2.0-4P connection cable to connect the module to the GraftPort-RP2040 development board's DIO0 interface:

DS18B20 GraftPort-RP2040 DIO0 HY2.0-4P

The module connections are shown in the following table:

Development Board Pins

Module Pins

Description

Pin 6

DOUT

1-Wire communication pin

Pin 7

NC

-

Here, we need to search for the relevant driver packages on uPyPI: https://upypi.net/zh/

106

Enter ds18b20_driver to search, and the following will be displayed:

ds18b20_driver 1.0.0

Click to copy the local installation command:

ds18b20_driver DS18B20

Here, we can use the mip tool to import module driver library code. Below are the usage commands for the mpremote tool:

mpremote mip install github:FreakStudioCN/GraftSense-Drivers-MicroPython/sensors/ds18b20_driver

After importing the DS18x20 temperature sensor driver - MicroPython driver code, copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-        
# @Time    : 2024/7/22 3:01 PM
# @Author  : Li Qingshui
# @File    : main.py       
# @Description : DS18B20 temperature experiment, using single-bus communication for data exchange

# ======================================== Import Modules ========================================

# Import hardware-related modules
from machine import Pin
# Import time-related modules
import time
# Import modules for single-bus communication
from onewire import OneWire
# Import the temperature sensor class
from ds18x20 import DS18X20

# ======================================== Global Variables ============================================

# ======================================== Functions ============================================

# ======================================== Custom Classes ============================================

# ======================================== Initialization ==========================================

# Delay to wait for the device to initialize
time.sleep(3)
# Print debug information
print('FreakStudio : Using OneWire to read DS18B20 temperature')

# Define the single-bus communication pin
ow_pin = OneWire(Pin(14))
# Define the temperature sensor
ds18x20 = DS18X20(ow_pin)

# ========================================  Main Program  ===========================================

# Scan for DS18B20 devices on the bus and get the list of device addresses
roms_list = ds18x20.scan()
# Print the list of device addresses
for rom in roms_list:
    print('ds18b20 sensor devices rom id:', rom)
# Have all DS18B20 devices on the bus convert the temperature
ds18x20.convert_temp()

# Read the temperature in a loop
while True:
    time.sleep_ms(500)
    for rom in roms_list:
        # Convert and print the temperature
        temp = ds18x20.read_temp(rom)
        # Print the temperature
        print('ds18b20 sensor {} devices temp {}'.format(rom, temp))
    # Start the temperature conversion
    ds18x20.convert_temp()

Burn the code, open a terminal, and use the mpremote tool to connect to the main controller; the output is as follows:

ds18b20 33.8125 38.25 DS18x20

We can ignite a lighter and hold it close to the module, or cover the chip with our finger; at this point, we will observe that the temperature displayed by the module rises.

IV. Drivers

ds18b20_driver.zip 15 KB

None.

VI. Revision History

Document Version

Date of Revision

Modifier

Modified Content

v1.0

2025-09-04

ben0i0d

Initialize the document

v1.1

2025-10-13

Li Zisheng

Added Section 2.8 PCB Routing Notes

Revised Section 3, Instructions for Circuit Source Engineering and Module Usage, and added a secondary heading:

3.1 Circuit Source Engineering, 3.2 Module Usage Instructions, 3.3 Application Experiments

The BOM sheet has not been finally checked, the driver has not been re-verified, and the 3.3 application experiment

Not yet specified.

v1.2

2025-12-29

Li Zisheng

Added application experiments and production files

v1.3

2025-12-31

Xin Ruili

Create an open version of the document based on the internal document version v1.2.

v1.4

2026-03-29

Xin Ruili

Modified the application experiment section

VII. Relevant Materials

7.1 Chip Datasheet

C2843534_Temperature Sensor_MY18E20_Datasheet_WJ1187342.PDF 1.8 MB

DS18B20 Datasheet English Version.pdf 3.3 MB

7.2 PCB Silkscreen Specific Icons

DS18B20 7.2